Nestjs+ Swagger:如何将自定义选项添加到@apiproperty

发布于 2025-01-30 19:50:53 字数 302 浏览 3 评论 0 原文

是否可以将自定义选项添加到@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;
}

Is it possible to add a custom option to @ApiProperty decorator?

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离不开的别离 2025-02-06 19:50:53

我不确定我是否完全了解,但是如果您在谈论 Openapi的扩展 。看看这一点: https://github.com/nestjs/nestjs/swagger/swagger/swagger/ssues/195 < /a>

I'm not sure i fully understand, but If you are talking about openapi's extensions. Take a look at this: https://github.com/nestjs/swagger/issues/195

揽清风入怀 2025-02-06 19:50:53

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);
};

Solution from 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);
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文