簡體   English   中英

Nestjs + Swagger:如何向@ApiProperty 添加自定義選項

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM