我有一个类,其中一个属性可以是字符串或字符串数组,不知道我应该如何在 swagger 中定义它
@ApiProperty({
description: `to email address`,
type: ???, <- what should be here?
required: true,
})
to: string | Array<string>;
更新正如@Youba 建议的答案,我试过了
@ApiProperty({
description: `to email address(es)`,
additionalProperties: {
oneOf: [
{ type: 'string' },
{ type: 'Array<string>' },
],
},
required: true,
})
和 @ApiProperty({
description: `to email address(es)`,
additionalProperties: {
oneOf: [
{ type: 'string' },
{ type: 'string[]' },
],
},
required: true,
})
和 @ApiProperty({
description: `to email address(es)`,
additionalProperties: {
oneOf: [
{ type: 'string' },
{ type: '[string]' },
],
},
required: true,
})
但结果如下图,这是不正确的最佳答案
请尝试
@ApiProperty({
oneOf: [
{ type: 'string' },
{
type: 'array',
items: {
type: 'string'
}
}
]
})
Array<TItem>
可以在 OpenAPI 中用 {type: 'array', items: { type: TItem } }
表示
关于typescript - NestJs Swagger 混合类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64939247/