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

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

Open
tomo-kn opened this issue Oct 9, 2023 · 0 comments
Open

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

tomo-kn opened this issue Oct 9, 2023 · 0 comments

Comments

@tomo-kn
Copy link

tomo-kn commented Oct 9, 2023

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 tomo-kn changed the title Bug: oneOf with shared properties fails validation [Bug] oneOf with shared properties fails validation Oct 9, 2023
@tomo-kn tomo-kn changed the title [Bug] oneOf with shared properties fails validation [Bug? or Feature?] oneOf with shared properties fails validation Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant