swagger
                                
                                 swagger copied to clipboard
                                
                                    swagger copied to clipboard
                            
                            
                            
                        [Feature request] Array of oneOf (or isArray for oneOf)
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe it
Our API accepts an array and the elements of said array can be of two types (described by the oneOf schema combinator).
Describe the solution you'd like
The ideal solution would be to allow specifying isArray for the oneOf combinator.
Teachability, documentation, adoption, migration strategy
Adding one example in the docs is probably sufficient, and it compiles with the teachability requirements. No migration needed.
What is the motivation / use case for changing the behavior?
No change to existing behavior, the proposed feature does not interfere with the existing ones.
Hi, any progress with this?
For the time being, there is a hack that we can temporarily use to enable array of oneOf until the feature is actually implemented.
@ApiProperty({
  type: 'array',
  allOf: [
     {
        type: 'array',
        items: {
          oneOf: [ ...$refs ]
        }
     }
  ],
})
someProperty: (DtoClass1 | DtoClass2 | DtoClass3)[];
By reading the source code I think that it's supported with a slightly different syntax:
@ApiProperty({
    type: 'array',
    items: {
        oneOf: [ ...$refs ]
    }
})
someProperty: Dto[];
Will this be implemented?
https://github.com/nestjs/swagger/issues/1729#issuecomment-1202387103