Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenApi 3 import schemas from external files

I am defining common schemas for Web services and I want to import them in the components/schema section of the specification. I want to create a canonical data model that is common across multiple services to avoid redefining similar objects in each service definition.

Is there a way to do this? Is there a similar mechanism to what XSD does with its import tag?

like image 619
Aldo Avatar asked May 04 '18 16:05

Aldo


1 Answers

To expand on Helen's answer for those landing here from Google, if Pet.yaml is not a plain object but has several objects like this:

components:
  schemas:
    pet:
      type: object
      properties:
        (...)

You can refer to it like this:

$ref: './common/Pet.yaml#/components/schemas/pet'
like image 150
ardal Avatar answered Sep 19 '22 09:09

ardal