Skip to content

ValidateOneOfDiscriminator errors #383

@michivogler

Description

@michivogler

I'm currently trying to generate an OpenAPI documentation using this library. When I try to add a discriminator in combination with oneOf I get a ton of errors after validation for the ValidateOneOfDiscriminator rule and I can't figure out what exactly is wrong.

Error message examples:

Composite Schema EmailAddress must contain property specified in the discriminator Type. [#/paths/~1Addresses/get/responses/200/content/application~1json/schema/items/oneOf]

Composite schema EmailAddress must contain property specified in the discriminator Type in the required field list. [#/paths/~1Addresses/get/responses/200/content/application~1json/schema/items/oneOf]

When I serialize the OpenApiDocument and copy it to https://editor.swagger.io/ everything seems to be valid. Even if I use the OpenApiStreamReader and validate it again there are no errors and after serializing it again there's no diff between the two documents.

Any idea what the problem might be?

Here's a short version of my openapi.yaml

openapi: 3.0.1
info:
  title: My API
  version: v1
paths:
  /Addresses:
    get:
      tags:
        - Addresses
      operationId: AddressesGetAll
      parameters:
        - name: pageIndex
          in: query
          schema:
            type: string
        - name: pageSize
          in: query
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  oneOf:
                    - $ref: '#/components/schemas/EmailAddress'
                    - $ref: '#/components/schemas/PostalAddress'
                    - $ref: '#/components/schemas/WebAddress'
                  discriminator:
                    propertyName: Type
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
components:
  schemas:
    WebAddress:
      required:
        - Type
        - Uri
      type: object
      properties:
        VerifiedDate:
          type: string
          format: date-time
          readOnly: true
        Version:
          type: number
          format: int32
          readOnly: true
        CreatedTime:
          type: string
          format: date-time
          readOnly: true
        UpdatedTime:
          type: string
          format: date-time
          readOnly: true
        IsVerified:
          type: boolean
          readOnly: true
        Type:
          type: string
          readOnly: true
        VerificationCode:
          type: string
        Guid:
          type: string
          format: uuid
          readOnly: true
        IsAdvertisingAllowed:
          type: boolean
        Uri:
          type: string
        DisplayName:
          type: string
          readOnly: true
    EmailAddress:
      required:
        - Address
        - Type
      type: object
      properties:
        Address:
          type: string
        VerifiedDate:
          type: string
          format: date-time
          readOnly: true
        Version:
          type: number
          format: int32
          readOnly: true
        CreatedTime:
          type: string
          format: date-time
          readOnly: true
        UpdatedTime:
          type: string
          format: date-time
          readOnly: true
        IsVerified:
          type: boolean
          readOnly: true
        Domain:
          type: string
          readOnly: true
        Type:
          type: string
          readOnly: true
        VerificationCode:
          type: string
        Guid:
          type: string
          format: uuid
          readOnly: true
        IsAdvertisingAllowed:
          type: boolean
        DisplayName:
          type: string
          readOnly: true
    PostalAddress:
      required:
        - Country
        - City
        - Type
      type: object
      properties:
        Longitude:
          type: string
        Region:
          type: string
        Zipcode:
          type: string
        City:
          type: string
        VerifiedDate:
          type: string
          format: date-time
          readOnly: true
        Version:
          type: number
          format: int32
          readOnly: true
        CreatedTime:
          type: string
          format: date-time
          readOnly: true
        State:
          type: string
        UpdatedTime:
          type: string
          format: date-time
          readOnly: true
        StreetName:
          type: string
        IsVerified:
          type: boolean
          readOnly: true
        Type:
          type: string
          readOnly: true
        VerificationCode:
          type: string
        Guid:
          type: string
          format: uuid
          readOnly: true
        Latitude:
          type: string
        IsAdvertisingAllowed:
          type: boolean
        DisplayName:
          type: string
          readOnly: true
        StreetNumber:
          type: string
        PoBox:
          type: string

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugA broken experience

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions