- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将我的 DTO 类(Typescript)转换为 JSON 架构:
import { IsNumber, IsString } from 'class-validator';
import { classToPlain } from 'class-transformer';
export class TodoDTO {
@IsNumber()
id?: number;
@IsString()
name?: string;
@IsString()
description?: string;
}
let todo = classToPlain(TodoDTO);
console.log('todo=>', todo);
我尝试使用两个包 class-transformer 和 class-validator 来转换和验证 TodoDTO 类。
在控制台中,输出为 todo=> [Function: TodoDTO]
预期输出:
"TodoDTO": {
"type": "object",
"properties": {
"id": { "type": "number" },
"name": { "type": "string" },
"description": { "type": "string" }
},
"required": [ "id", "name", "description" ]
}
我正在尝试使用 TodoDTO 类作为 fastify-typescript 中的 json-schema。
欢迎任何建议。
最佳答案
我使用了一个名为 class-validator-jsonschema 的库这帮助我根据需要将类转换为 json-schema。
这是代码:
import { IsNumber, IsString } from 'class-validator';
export class TodoDTO {
@IsNumber()
id?: number;
@IsString()
name?: string;
@IsString()
description?: string;
}
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
import * as todoDtos from './todo.dto';
export { todoDtos };
export const schemas = validationMetadatasToSchemas();
console.log('schemas=>', schemas);
关于typescript - 将 Typescript 类 DTO 转换为 Fastify Swagger 的 JSON 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69872389/
在 fastify 中,有没有办法为路由/路径添加别名?基本上,以相同的方式处理两条路径。这对于迁移 API 很有用。 我知道我可以将处理程序函数抽象为一个命名函数,并将该函数传递给两个路由。我只是想
在 fastify 中,有没有办法为路由/路径添加别名?基本上,以相同的方式处理两条路径。这对于迁移 API 很有用。 我知道我可以将处理程序函数抽象为一个命名函数,并将该函数传递给两个路由。我只是想
如您所知,Fastify 中的默认错误界面如下所示 { "statusCode": 400, "error": "Bad Request", "message": "Missi
我已经使用命令 fastify-cligenerate 设置了带有 fastify-cli 库的 fastify 框架。它具有开箱即用的 fastify-autoload 插件。 但是,当我添加自己的
如何从请求中访问属于非文件 字段的文本? (我正在使用 Insomia ) 我们使用 Insomia 的请求 我们可以通过遍历部分来访问文件字段。使用 const parts = await req.
如何从请求中访问属于非文件 字段的文本? (我正在使用 Insomia ) 我们使用 Insomia 的请求 我们可以通过遍历部分来访问文件字段。使用 const parts = await req.
我能够创建 jwt token : fastify.post('/signup', (req, reply) => { const token = fastify.jwt.sign({ p
我能够创建 jwt token : fastify.post('/signup', (req, reply) => { const token = fastify.jwt.sign({ p
对于每条路线,我都必须键入相同的标题,如下所示。有没有办法全局设置这些 header ,以便默认情况下将它们用于每个路由,并且可以在每个路由的基础上进行覆盖? fastify.post("/api/u
对于每条路线,我都必须键入相同的标题,如下所示。有没有办法全局设置这些 header ,以便默认情况下将它们用于每个路由,并且可以在每个路由的基础上进行覆盖? fastify.post("/api/u
我对何时在 Fastify.js 中使用插件有点困惑。例如,如果我只有一个包含一些实用函数的 lib/utils.js 文件,我通常会在我的应用程序中需要的地方只require() 它们。改为制作我的
我长期以来一直是 ExpressJs 的粉丝,但在 Youtube 视频中我偶然发现了 Fastify 并想尝试一下 我正在努力制作 fastify-swagger插件工作,我认为它应该工作 - 动态
我正在寻找如何使用 fastify-nextjs 启动 fastify-cli 的建议 我曾尝试将代码简单地添加到建议的位置,但它不起作用。 'use strict' const path = req
我的代码中有这个路由器 fastify.get('/:link', (req, reply) => { req.params.url = req.host+req.url; reply
我正在尝试在我的拦截器中设置响应 header ,并且我发现的任何方法都没有运气。我试过了: const request = context.switchToHttp().getRequest();
我是 node.js 的 fastify 框架的新手,我想知道 fastify-plugin 的确切用途是什么 因为我无法理解它背后的想法。我尝试了一些带有或不带有插件的代码,但我没有注意到其中的区别
试图让中间件在 Fastify 中工作 - 我似乎无法访问查询或参数。文档说: Fastify supports out of the box Express/Restify/Connect midd
上下文:我对请求和响应时间感兴趣。 知道请求何时由 Fastify 管理的第一种方法是添加一个钩子(Hook),如下所示: fastify.addHook('onRequest', (request,
上下文:我对请求和响应时间感兴趣。 知道请求何时由 Fastify 管理的第一种方法是添加一个钩子(Hook),如下所示: fastify.addHook('onRequest', (request,
正如你想象的那样,我对 Express 很熟悉,但这是我第一次使用 Fastify。 我想访问 Fastify 请求的未修改正文,以进行 Webhook 的签名验证 - 即,我希望看到请求传入时未被任
我是一名优秀的程序员,十分优秀!