OpenAPI.NET.OData icon indicating copy to clipboard operation
OpenAPI.NET.OData copied to clipboard

Consider replacing anyOf with allOf for enum types at least

Open sherlock1982 opened this issue 2 years ago • 4 comments

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 avatar Sep 28 '22 09:09 sherlock1982

@sherlock1982 thanks for the suggestion.

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

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

baywet avatar Mar 31 '23 16:03 baywet

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.

irvinesunday avatar Apr 26 '23 10:04 irvinesunday

One of would probably make the most sense here

baywet avatar Apr 26 '23 15:04 baywet

@sherlock1982 would oneOf work for your case?

irvinesunday avatar Apr 26 '23 15:04 irvinesunday