Use multiple json files in swagger-ui

I use Swagger-ui version 2.1.4 , I hosted it locally and provided it with my own Json file and API, it opens document fine and lists the whole method in the json file, but the json file becomes very large, I want to use several json files and I want to open one at a time, I don’t know how to provide it with several json files and use them, because the one file that I presented on the index page was as follows:

  var url = window.location.search.match(/url=([^&]+)/);
  if (url && url.length > 1) {
      url = decodeURIComponent(url[1]);
  } else {
      url = "http://localhost:1122/Json/Swagger-ui2.1.4V1.JSON";
  }
+2
source share
1 answer

The basic structure of your Swagger JSON should look something like this:

{
"swagger": "2.0",
"info": {
    "title": "",
    "version": "version number here"
},
"basePath": "/",
"host": "host goes here",
"schemes": [
    "http"
],
"produces": [
    "application/json"
],
"paths": {},
"definitions": {}
}

paths definitions - , , API, , . . .

, API - "".

:

{
"paths": {
    "/cars": {
        "get": {
            "tags": [
                "Car"
            ],
            "summary": "Get all cars",
            "description": "Returns all of the cars.",             
            "responses": {
                "200": {
                    "description": "An array of cars",
                    "schema": {
                        "type": "array",
                        "items": {
                            "$ref": "#/definitions/car"
                        }
                    }
                },
                "404": {
                    "description": "error fetching cars",
                    "schema": {
                        "$ref": "#/definitions/error"
                    }
                }
            }
        }
    }
}

:

{
"car": {
    "properties": {
        "_id": {
            "type": "string",
            "description": "car unique identifier"
        },
        "make": {
            "type": "string",
            "description": "Make of the car"
        },
        "model":{
            "type": "string",
            "description": "Model of the car."
        }
    }
}
}

. , JSON swagger ( paths definitions), Swagger JSON.

, ( API ). , " Swagger docs", Swagger JSON, .

" Swagger docs" /api-docs, :

app.get('/api-docs', function(req, res) {
  // return the created Swagger JSON object here
});
+1

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


All Articles