0

I have two definitions as a part of .yaml file as shown below:

definitions:
  EmployeeModel:
    type: object
    properties:
      id:
        type: integer
      name:
        type: string

  AddressModel:
    type: object
    properties:
      id:
        type: integer
      city:
        type: string
      employee:
        $ref: '#/definitions/EmployeeModel'

I want to change the address model such that the property 'employee' can either be an integer or a reference to EmployeeModel.

Is this possible? I have tried using oneOf and the result looked something like:

employee:
  oneOf:
    - type: integer
    - $ref: '#/defintions/EmployeeMap'

Is this the right way?

Anvith
  • 477
  • 9
  • 22
  • `oneOf` and `anyOf` are not supported in OpenAPI/Swagger 2.0 - they were introduced in OpenAPI 3.0. See the ^^ linked question. Btw your usage of `oneOf` is correct, and your example would be valid in OpenAPI 3.0 if you replace `definitions` with `components/schemas`. – Helen Jul 10 '18 at 11:09
  • Thanks for info @Helen – Anvith Jul 12 '18 at 07:13

0 Answers0