openapi_parser icon indicating copy to clipboard operation
openapi_parser copied to clipboard

[Bug? or Feature?] oneOf with shared properties fails validation

Open tomo-kn opened this issue 2 years ago • 0 comments

Failure that occurred

Validation fails when using oneOf and properties in parallel.

one_of_alongside_properties:
  additionalProperties: false
  required:
    - shared_property
  properties:
    shared_property:
      type: string
  oneOf:
    - $ref: '#/components/schemas/one_of_object1'
    - $ref: '#/components/schemas/one_of_object2'

one_of_object1:
  type: object
  required:
    - name
    - integer_1
  properties:
    name:
      type: string
    integer_1:
      type: integer
  additionalProperties: false
one_of_object2:
  type: object
  required:
    - name
    - string_1
  properties:
    name:
      type: string
    string_1:
      type: string
  additionalProperties: false

Solution.

If you change the schema to use oneOf within properties instead of using oneOf and properties in parallel, the validation will work correctly.

one_of_within_properties:
  additionalProperties: false
  required:
    - shared_property
    - sample_one_of
  properties:
    shared_property:
      type: string
    sample_one_of:
      oneOf:
        - $ref: '#/components/schemas/one_of_object1'
        - $ref: '#/components/schemas/one_of_object2'

Expected results

Using oneOf and properties in parallel does not cause any particular problem with orval type generation, for example. Thus, ideally, the openapi-parser validation should also pass.

tomo-kn avatar Oct 09 '23 10:10 tomo-kn