Skip to content

Behavior of the allOf and discriminator #3025

Closed Answered by rafalkrupinski
mtovt asked this question in Q&A
Discussion options

You must be logged in to vote

allOf makes it an inheritance. Superclass should neither know of nor include its subclasses.

The specification you've attached says your endpoint returns only a list of User. Since additionalProperties is true by default, it may return objects that happen to validate against UserA and/or UserB but that's not declared explicitly.

responses:
  default:
    content:
      application/json:
        schema:
          type: array
          items:
            oneOf:
            - $ref: '#/components/schemas/UserA'
            - $ref: '#/components/schemas/UserB'
            - $ref: '#/components/schemas/User'

Not sure about discriminator, but you can try adding additionalProperties: false to Use…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@rafalkrupinski
Comment options

@flaksp
Comment options

@rafalkrupinski
Comment options

@rafalkrupinski
Comment options

@mtovt
Comment options

Answer selected by mtovt
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants