Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider replacing anyOf with allOf for enum types at least #286

Open
sherlock1982 opened this issue Sep 28, 2022 · 4 comments
Open

Consider replacing anyOf with allOf for enum types at least #286

sherlock1982 opened this issue Sep 28, 2022 · 4 comments
Assignees
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:enhancement Enhancement request targeting an existing experience.

Comments

@sherlock1982
Copy link

sherlock1982 commented Sep 28, 2022

In converted schema there are many places like this:

      schema:
        anyOf:
          - $ref: '#/components/schemas/Pbx.NumberFilterType'

This I believe is done to express extra props. Specifically to make this type nullable for example.
While this works with OpenAPI Generator 5.4.0 it doesn't work with many other versions including 6.X branches.

6.X branches generate complete gibberish if referenced type is enum and it is referenced via anyOf
I'm not a great specialist in OpenAPI specs but I want to raise this discussion because replacing anyOf to allOf works perfectly.
So what do you think?

Steps to reproduce

Make a schema with enum.

Expected result

      schema:
        allOf:
          - $ref: '#/components/schemas/Pbx.NumberFilterType'

Actual result

      schema:
        anyOf:
          - $ref: '#/components/schemas/Pbx.NumberFilterType'
@sherlock1982 sherlock1982 changed the title Consider replacing anyOf with allOf for enum types at least Consider replacing anyOf with oneOf for enum types at least Sep 28, 2022
@sherlock1982 sherlock1982 changed the title Consider replacing anyOf with oneOf for enum types at least Consider replacing anyOf with allOf for enum types at least Sep 28, 2022
@irvinesunday irvinesunday self-assigned this Nov 14, 2022
@adhiambovivian adhiambovivian added the type:enhancement Enhancement request targeting an existing experience. label Mar 24, 2023
@irvinesunday irvinesunday added this to the OData:1.4 milestone Mar 29, 2023
@baywet
Copy link
Member

baywet commented Mar 31, 2023

@sherlock1982 thanks for the suggestion.

Can you expand on why you didn't request this instead?

schema:
  $ref: '#/components/schemas/Pbx.NumberFilterType'

@baywet baywet added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Mar 31, 2023
@irvinesunday
Copy link
Collaborator

irvinesunday commented Apr 26, 2023

Currently, we use anyOf when referencing an enum reference if it is nullable in OpenAPI 3.0 spec. and above. An example would be:

requestedModalities:
  type: array
  items:
    anyOf:
      - $ref: '#/components/schemas/microsoft.graph.modality'
      - type: object
        nullable: true

else (if it is not nullable)

role:
  $ref: '#/components/schemas/microsoft.graph.screenSharingRole'

Using allOf would mean that all of the given schemas must be valid for the given property, which would not be factual.

@baywet
Copy link
Member

baywet commented Apr 26, 2023

One of would probably make the most sense here

@irvinesunday
Copy link
Collaborator

@sherlock1982 would oneOf work for your case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:enhancement Enhancement request targeting an existing experience.
Projects
None yet
Development

No branches or pull requests

4 participants