Skip to content

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

@tomo-kn

Description

@tomo-kn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions