Skip to content

Support allOf in schema definitions #17

@Szer

Description

@Szer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions