gpt4 book ai didi

typescript - NestJs Swagger 混合类型

转载 作者:行者123 更新时间:2023-12-04 13:11:16 25 4
gpt4 key购买 nike

我有一个类,其中一个属性可以是字符串或字符串数​​组,不知道我应该如何在 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,
})
但结果如下图,这是不正确的
enter image description here

最佳答案

请尝试

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com