How to merge multiple JSON files Swagger (v. 1.2)?

The presence of the main JSON file

{"swaggerVersion":"1.2", "apiVersion":"1.0", "apis":[{"path":"/api1"},{"path":"/api2"},{"path":"/api3"},{"path":"/api4"}]} 

and JSON files for each of the 4 APIs that work well with the Swagger library.

But when I tried to put all this into a single JSON file, like

  {"swaggerVersion":"1.2", "apiVersion":"1.0", "apis":[{<api1 json file contents>},{<api2 json file contents>},{<api3 json file contents>},{<api4 json file contents>}]} 

it did not work.

How to properly combine multiple Swagger v. Files 1.2 in one file?

+8
source share
2 answers

According to the Swagger 1.2 specification, you simply cannot do this.

The "master" JSON file (as you called it) represents the Swagger API Resource List , which simply contains an "inventory of available resources".

It is assumed that the "apis" property of this JSON document will be an array of a Resource Object with a specific structure:

 { "path": "/pets", "description": "Operations about pets." } 

Designation API declaration in the specification:

The API declaration contains information about the API displayed on the resource. There must be one file per resource described. The file MUST be used in the URL described in the path field.

+5
source

Take a look at the demo app to view all the service documents in one place: https://github.com/varghgeorge/microservices-single-swagger

The repo shows how to create a springboot application that will serve as the only place for all of your documents with flash files / chargers.

Swagger documentation from different services / locations can be configured on this server using yaml config. Details are at the github location.

+2
source

Source: https://habr.com/ru/post/973539/


All Articles