openapi: 3.0.1
info:
  title: oneOf test
  version: '1.0'
servers:
  - url: 'http://localhost:8000/'
paths:
  /state:
    get:
      operationId: getState
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ObjA'
                  - $ref: '#/components/schemas/ObjB'
                  - $ref: '#/components/schemas/ObjD'
                discriminator:
                  propertyName: realtype
                  mapping:
                    a-type: '#/components/schemas/ObjA'
                    b-type: '#/components/schemas/ObjB'
                    b-type: '#/components/schemas/ObjD'
    post:
      operationId: createState
      requestBody:
        content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ObjA'
                  - $ref: '#/components/schemas/ObjB'
                discriminator:
                  propertyName: realtype
                  mapping:
                    a-type: '#/components/schemas/ObjA'
                    b-type: '#/components/schemas/ObjB'
        required: true
      responses:
        '201':
          description: OK
components:
  schemas:
    CustomOneOfSchema:
      oneOf:
        - $ref: '#/components/schemas/ObjA'
        - $ref: '#/components/schemas/ObjB'
      discriminator:
        propertyName: realtype
        mapping:
          a-type: '#/components/schemas/ObjA'
          b-type: '#/components/schemas/ObjB'
    CustomOneOfArraySchema:
      type: array
      items:
        oneOf:
          - $ref: '#/components/schemas/ObjA'
          - $ref: '#/components/schemas/ObjB'
          - $ref: '#/components/schemas/ObjC'
        discriminator:
          propertyName: realtype
          mapping:
            a-type: '#/components/schemas/ObjA'
            b-type: '#/components/schemas/ObjB'
            c-type: '#/components/schemas/ObjC'
    ObjA:
      type: object
      properties:
        realtype:
          type: string
        message:
          type: string
    ObjB:
      type: object
      properties:
        realtype:
          type: string
        description:
          type: string
        code:
          type: integer
          format: int32
    ObjC:
      type: object
      properties:
        realtype:
          type: string
        state:
          type: string
    ObjD:
      type: object
      properties:
        realtype:
          type: string
        color:
          type: string