nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.69k stars 474 forks source link

Nullable array item support for typescript plugin #759

Closed maximelkin closed 4 years ago

maximelkin commented 4 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When array item declared as nullable, plugin is unable to generate appropriate schema for property

Expected behavior

openapi schema should be generated with nullable items

Minimal reproduction of the problem with instructions

class Model1 {}

class Model2 {
    items: Array<Model1 | null>
}

What is the motivation / use case for changing the behavior?

Reduce boilerplate in that cases

Environment


Nest version: 7.0.13


Others:

@nestjs/swagger: 4.5.7

kamilmysliwiec commented 4 years ago

Unfortunately, union types are not supported and very likely won't be supported in the future. The reason is that TypeScript in certain scenarios implicitly defines such unions, for example, when your property is marked as optional and "strict" configuration property is set to true. Likewise, sometimes enums (it depends on some factors) are implicitly transformed into union types instead. Thus, it would be impossible for us to distinguish whether a union was generated by the compiler, or specified explicitly by the developer.