Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support allOf in schema definitions #17

Open
Szer opened this issue Apr 3, 2020 · 0 comments
Open

Support allOf in schema definitions #17

Szer opened this issue Apr 3, 2020 · 0 comments

Comments

@Szer
Copy link
Owner

Szer commented Apr 3, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant