NestJs Swagger 混合类型

Rez*_*eza 11 swagger typescript openapi nestjs

我有一个类,其中一个属性可以是字符串或字符串数​​组,不知道如何在 swagger 中定义它

    @ApiProperty({
        description: `to email address`,
        type: ???, <- what should be here?
        required: true,
    })
    to: string | Array<string>;
Run Code Online (Sandbox Code Playgroud)

我试过

    @ApiProperty({
        description: `to email address(es)`,
        additionalProperties: {
            oneOf: [
                { type: 'string' },
                { type: 'Array<string>' },
            ],
        },
        required: true,
    })
Run Code Online (Sandbox Code Playgroud)

    @ApiProperty({
        description: `to email address(es)`,
        additionalProperties: {
            oneOf: [
                { type: 'string' },
                { type: 'string[]' },
            ],
        },
        required: true,
    })
Run Code Online (Sandbox Code Playgroud)

    @ApiProperty({
        description: `to email address(es)`,
        additionalProperties: {
            oneOf: [
                { type: 'string' },
                { type: '[string]' },
            ],
        },
        required: true,
    })
Run Code Online (Sandbox Code Playgroud)

但结果如下图所示,这是不正确的

在此输入图像描述

Cha*_*ran 19

请尝试

@ApiProperty({
   oneOf: [
      { type: 'string' },
      { 
         type: 'array',
         items: {
            type: 'string'
         }
      }
   ]
})
Run Code Online (Sandbox Code Playgroud)

Array<TItem>可以在 OpenAPI 中表示为{type: 'array', items: { type: TItem } }