allOf enums
See original GitHub issueHi, I’m trying to switch to a new dart code generator (because of dart’s new null safety fratures). That code generator has problems with the way enum fields are modeled with allOf by this scheme generator, e.g.
components:
schemas:
CategoryEnum:
enum:
- Gloves
- Clothes
- Shoes
- mask
type: string
SomeModel:
type: object
properties:
category:
allOf:
- $ref: '#/components/schemas/CategoryEnum'
nullable: true
The reason why the problems come up is that the new generator generates enums differently, as actual enums instead of regular classes with a bunch of static members of itself. The enum methods for conversion etc. have to be referenced differently than other types though, but when the model’s enum field is included via an allOf construct, it’s not recognized as an enum but as another model. So the generated code is wrong.
Now my question is what’s the prupose of this modelling/ why does spectacular do it this way? And can it be turned off? 😄
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
yes indeed. OpenAPI 3.1 is fully based on JSON Schema in contrast to OpenAPI 3.0.3. once support is ramping up, we will look at this again. right now tooling support is just not fully there yet and thus this fix would probably create more issues than it solves.
the way we do it right now is the one and only “correct” way to do in 3.0.3. i’ll be happy to change this in the future.
I hacked something into the code generator to treat schemas of this kind as enums. The maintainer pointed out that nullable is apparently removed and replaced by type arrays in OAS 3.1: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0