Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Support polymorphic response from the nested list level #196

Open
dralpus opened this issue Jan 19, 2019 · 2 comments
Open

Support polymorphic response from the nested list level #196

dralpus opened this issue Jan 19, 2019 · 2 comments

Comments

@dralpus
Copy link
Contributor

dralpus commented Jan 19, 2019

We need to support the polymorphic response at the nested list (2nd layer response - from the data model). Clients should handle the different type of objects inside the lists as long as they have discriminator parameters.

We have a DataModel such as:

class PetResponse
{
 public string message {get; set;}
 // <-- We need an annotation support here for overridding the base type (Pet) and instead support discriminator parameter, with oneOf functionality.
 public List<Pet>{get; set;}
}

End result of the swagger document should be look like this:
Sample result: https://app.swaggerhub.com/apis/dralpus/test/1.0.0-oas3

openapi: 3.0.1
info:
  title: Polymorphic List Sample
  version: "1.0.0-oas3"
servers:
  - url: 'https://localhost'
paths:
  /feeds:
    get:
      tags:
        - News
      summary: Result array contains any of the specified types
      operationId: getMsnFeeds
      parameters:
        - name: query
          in: query
          description: 'Get '
          schema:
            type: string
      responses:
        '200':
          description: List of compositeCards
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PetResponse'
components:
  schemas:
    PetResponse:
      type: object
      properties:
        result:
          type: array
          items:
            # Actually PetResponse has an Pet type array to support Polymorphism, but it is overridden by the extended class types
            oneOf:
              - $ref: '#/components/schemas/Cat'
              - $ref: '#/components/schemas/Dog'
              - $ref: '#/components/schemas/Lizard'
          discriminator:
            propertyName: pet_type
        message:
          type: string
    Lizard:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            lovesRocks:
              type: boolean
    Pet:
      type: object
      properties:
        name:
          type: string
        petType:
          type: string
      required:
        - name
        - petType
    Cat:
      description: A representation of a cat
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            huntingSkill:
              type: string
              description: The measured skill for hunting
              enum:
                - clueless
                - lazy
                - adventurous
                - aggressive
          required:
            - huntingSkill
    Dog:
      description: A representation of a dog
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            packSize:
              type: integer
              format: int32
              description: the size of the pack the dog is from
              default: 0
              minimum: 0
          required:
            - packSize
@Shwetap05
Copy link
Member

Shwetap05 commented Feb 3, 2019

@dralpus to support this feature we will need to start supporting custom annotations for request/response contracts properties as currently we use only the default <summary> tag to fetch the property description. I will need to think about the design as the work is not going to be trivial to support this.

@MikesGlitch
Copy link

Any news on this? Would be really helpful for a project I'm working on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants