question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi, 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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tfranzelcommented, Jul 1, 2021

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.

0reactions
NANASHI0X74commented, Jun 28, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

allOf + enum is resulting in a enum array merge when ... - GitHub
allOf + enum is resulting in a enum array merge when it should actually be an intersection as any instance must validate against...
Read more >
Enums - Swagger
Enums. You can use the enum keyword to specify possible values of a request parameter or a model property. For example, the sort...
Read more >
Enum.values() vs EnumSet.allOf( ). Which one is more ...
allOf and it looks very efficient, especially for enums with less than 64 values. Basically all sets share the single array of all...
Read more >
Guide to EnumSet | Baeldung
An EnumSet is a specialized Set collection to work with enum classes. ... The most simple methods to create an EnumSet are allOf()...
Read more >
EnumSet (Java Platform SE 8 ) - Oracle Help Center
allOf. Creates an enum set containing all of the elements in the specified element type. Returns: An enum set containing all the elements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found