Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge multiple OpenAPI specifications?

I'm digging here around trying to find a solution, how to merge several OpenApi v3 component definitions in one file.

Let's imagine a situation:

  1. You decided to split your OpenApi into multiple files in different folders. (see image below)project structure
  2. Now you need to combine all your components.v1.yaml into a single schema (i named it blueprint.v1.yaml). Usually, I use swagger-cli to merge all $ref dependencies, but now it's not a case, because I can not refer to the whole components/schemas object list blueprint.v1.yaml content
  3. And use it to build a single OpenApi file with all fields filled: info, components, paths and so on with a swagger-cli bundle tool.

So, the question is - how to reuse already defined component blocks (files called components.v1.yaml) in my blueprint.v1.yaml file?

P.S. Every components.v1.yaml looks like this: components.v1.yaml content

And a, for ex, location-create-single.v1.yaml path definition is shown on picture below. Mention, that all $ref referes to components.v1.yaml files. enter image description here

like image 729
P. Savrov Avatar asked Apr 17 '20 01:04

P. Savrov


People also ask

Is Swagger and OpenAPI the same?

OpenAPI 3.0 is the latest version of the specification. The Swagger tools, which are supported by SmartBear Software, are among the most popular tools for implementing the OpenAPI Specification, and will continue to maintain the Swagger name (Swagger Editor, Swagger UI, SwaggerHub, etc.)

What is $ref in OpenAPI?

With OpenAPI 3.0, you can reference a definition hosted on any location. It can be the same server, or another one – for example, GitHub, SwaggerHub, and so on. To reference a definition, use the $ref keyword: $ref: 'reference to definition'

Is YAML OpenAPI?

Document SyntaxAn OpenAPI document is a text file, commonly called openapi. json or openapi. yaml , representing a JSON object, in either JSON or YAML format. This file is called the root document and it can be split into multiple JSON or YAML files, for clarity.

What is operationId OpenAPI?

The operationId section of the Paths and Operators page in the OpenAPI Guide describes this property as: operationId is an optional unique string used to identify an operation. If provided, these IDs must be unique among all operations described in your API.


1 Answers

I don't think there is a "native" OpenAPI solution to your problem. People are discussing for a while about OpenAPI overlays/extends/merges. There is currently (2020-04-24) not any consensus about this topic.

Although you could implement your own tool or use an existing one to preprocess your blueprint.v1.yaml and generate a "merged OAS".

like image 85
Raphael Medaer Avatar answered Oct 11 '22 17:10

Raphael Medaer