1

I am trying to re-use component schemas as reference which vary based on their usage.

I have a "Employee Model" that will contain say below items:- EmployeeID and EmployeeName

So I have created a component schema in YAML like below:-

components:
    schemas:
        Employee:
            type: object
            properties:
                EmployeeID:
                    type: integer
                EmployeeName:
                    type: string
                EmployeeAge:
                    type: integer

Now I want to use this in multiple paths like

  1. Use this in both request and response body, but with the caveat that in the request I should only take in the ID and response can hold all.
  2. Use this in the response body but only with Name and Age
  3. Use this in a request body with only Name

Can you please recommend the best approach to use $ref and achieve the above?

Sukant
  • 11
  • 3
  • 1
    Possible duplicate of [Combining defintions in Swagger docs](https://stackoverflow.com/questions/29463634/combining-defintions-in-swagger-docs) – Aleksi Aug 23 '19 at 13:21

1 Answers1

0

Check the JSON Schema docs on combining schemas; in this particular case you'd use allOf, for example.

Here's a related answer.

Aleksi
  • 4,483
  • 33
  • 45