Skip to content

Schema array type with anyOf and discriminator fails validation #402

@rwrife

Description

@rwrife

I'm trying to validate an OpenAPI document that contains a schema object that is of type 'array' that can be an 'anyOf' that uses a discriminator to know which object goes into the array and it's failing validation. The document appears to be a valid OAS3 document and the Swagger UI has no issues rendering it, so I'm guessing it's an issue with OpenAPI.NET.

I'm getting validation errors similar to:

Composite Schema ChildTypeA must contain property specified in the discriminator type. [#/components/schemas/SampleResponse/properties/suggestedActions/items/anyOf]
Composite schema ChildTypeA must contain property specified in the discriminator type in the required field list. [#/components/schemas/SampleResponse/properties/suggestedActions/items/anyOf]

...for this document

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 of SampleRequest
      requestBody:
        description: Returns the SampleResponse with multiple types
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SampleRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SampleResponse'
components:
  schemas:
    SampleRequest:
      type: object
      required:
        - id
      properties:
        id:
          type: string
          description: Random ID
          example: '1513776099991'
    BaseType:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          description: Suggested object type
    ChildTypeA:
      allOf:
        - $ref: '#/components/schemas/BaseType'
          properties:
            type:
              type: string
              enum:
                - typeA
      type: object
    ChildTypeB:
      allOf:
        - $ref: '#/components/schemas/BaseType'
          properties:
            type:
              type: string
              enum:
                - typeB
      type: object
    SampleResponse:
      type: object
      properties:
        suggestedActions:
          type: array
          items:
            anyOf:
              - $ref: '#/components/schemas/ChildTypeA'
              - $ref: '#/components/schemas/ChildTypeB'
            discriminator:
              propertyName: type

Metadata

Metadata

Assignees

Labels

priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7daystype:bugA broken experience

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions