[英]Nestjs + Swagger: How to add a custom option to @ApiProperty
是否可以向 @ApiProperty 装饰器添加自定义选项?
import { ApiProperty } from '@nestjs/swagger';
class Animal {
@ApiProperty({
type: String,
description: 'animal name',
'x-description': 'some information' // how to add a cutom option 'x-description' ?
})
name: string;
}
我不确定我是否完全理解,但如果你在谈论openapi 的扩展。 看看这个: https ://github.com/nestjs/swagger/issues/195
来自https://github.com/nestjs/swagger/issues/195#issuecomment-526215840的解决方案
import { ApiProperty } from '@nestjs/swagger';
type SwaggerDecoratorParams = Parameters<typeof ApiProperty>;
type SwaggerDecoratorMetadata = SwaggerDecoratorParams[0];
type Options = SwaggerDecoratorMetadata & DictionarySwaggerParameters;
type DictionarySwaggerParameters = { 'x-property'?: string };
export const ApiPropertyX = (params: Options) => {
return ApiProperty(params);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.