Skip to content

Handle discriminator for transformers #2807

@amarant

Description

@amarant

Description

Hi,
here is a pretty common openapi.yaml using a simple discriminator, and it would be great if the transformer could handle the getPets that can output cats and dogs with each one their own date fields.

for now it output a transformer for the endpoint getCats of cats only, but not the pets one for cats or dogs

openapi.yaml
openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths:
  /cats:
    get:
      operationId: getCats
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Cat'
  /pets:
    get:
      operationId: getPets
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
components:
  schemas:
    Cat:
      type: object
      required:
        - type
        - napDate
      properties:
        type:
          type: string
          enum:
            - cat
        napDate:
          type: string
          format: date-time
      allOf:
        - type: object
          required:
            - type
            - name
            - birthDate
          properties:
            type:
              type: string
              enum:
                - cat
            name:
              type: string
            birthDate:
              type: string
              format: date-time
    Dog:
      type: object
      required:
        - type
        - walkDate
      properties:
        type:
          type: string
          enum:
            - dog
        walkDate:
          type: string
          format: date-time
      allOf:
        - type: object
          required:
            - type
            - name
            - birthDate
          properties:
            type:
              type: string
              enum:
                - dog
            name:
              type: string
            birthDate:
              type: string
              format: date-time
    Pet:
      type: object
      oneOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'
      discriminator:
        propertyName: type
        mapping:
          cat: '#/components/schemas/Cat'
          dog: '#/components/schemas/Dog'
    PetType:
      type: string
      enum:
        - cat
        - dog

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions