GiraffeGenerator icon indicating copy to clipboard operation
GiraffeGenerator copied to clipboard

Support allOf in schema definitions

Open Szer opened this issue 6 years ago • 0 comments

allOf could be encoded in general case via "tupling" type with each other in new type:

components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
    Dog:     # "Dog" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Dog`-specific properties 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
            breed:
              type: string
    Cat:     # "Cat" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Cat`-specific properties 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer

could be encoded like


interface IPet = 
  abstract pet_type: string
type Pet = 
  { pet_type: string }
  interface IPet with
    member x.pet_type = x.pet_type

type Cat = 
  { hunts: bool
    age: int
    pet_type: string }
  interface IPet with
    member x.pet_type = x.pet_type

type Dog = 
  { bark: bool
    breed: string
    pet_type: string }
  interface IPet with
    member x.pet_type = x.pet_type

Szer avatar Apr 03 '20 15:04 Szer