Skip to content

Conversation

@MaggieKimani1
Copy link
Contributor

@MaggieKimani1 MaggieKimani1 commented Jul 21, 2022

Fixes #402

@darrelmiller
Copy link
Member

The validation process needs to be recursive. The current check only validates direct children of the schema. The following example still fails.

openapi: 3.0.0
info:
  description: Service to test discriminator
  version: 1.0.0
  title: Test Service
servers:
  - url: 'https://localhost'
paths:
  /test:
    post:
      description: Sample post
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Parent'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Parent'
components:
  schemas:
    Parent:
      type: object
      oneOf:
         - $ref: '#/components/schemas/ChildA'
         - $ref: '#/components/schemas/ChildB'
      discriminator:
         propertyName: type
    ChildA:
      allOf:
      - $ref: "#/components/schemas/BaseChild"
      - properties:
          AName:
            type: string
        type: object
    ChildB:
      allOf:
      - $ref: "#/components/schemas/BaseChild"
      - properties:
          BName:
           type: string
        type: object
    BaseChild:
      properties:
        type:
         type: string
      type: object

Copy link
Member

@darrelmiller darrelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checking needs to be made recursive. See the example I included in the overview comments.

@MaggieKimani1
Copy link
Contributor Author

The checking needs to be made recursive. See the example I included in the overview comments.

Thanks for the correction. Resolving..

@darrelmiller darrelmiller merged commit a9e91fe into vnext Aug 17, 2022
@darrelmiller darrelmiller deleted the mk/fix-parent-schema-discriminator-issue branch August 17, 2022 01:00
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

Successfully merging this pull request may close these issues.

Schema array type with anyOf and discriminator fails validation

5 participants