1

I have a Node.js server running on port 8080. I am using swagger, which allows a basepath to be set. I want to set multiple basepaths for different endpoints. I am using swagger-ui-express to server swagger ui files.

I have gone through swagger's documentation and tried with servers property, but it did not work. My endpoints are:

  1. Endpoint: /users/movies
    Should be served as: http://localhost:9090/cinema-mgr-api/users/movies
  2. Endpoint: /aws-mgr-api/storage
    Should be served as: http://localhost:9090/aws-mgr-api/storage

How do I define multiple basepaths with swagger-ui-express?

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
unnamed-bull
  • 361
  • 4
  • 15

1 Answers1

1

Below code is what I am having my project. I have used the swagger-tools dependency and the version is 0.10.4.

swagger.json

{
    "swagger": "2.0",
    "info": {
        "title": "Node JS APP",
        "description": "Node JS APP",
        "version": "1.0.0"
    },
    "produces": [
        "application/json"
    ],
    "host": "localhost:9000",
    "basePath": "/api",
    "paths": {
        "/cinema-mgr-api/users/movies":{
            "post": {
                "tags": ["controller"],
                "description": "movies",
                "x-swagger-router-controller": "controller",
                "operationId": "movies",
                "parameters": [
                    {
                        "name": "body",
                        "in": "body",
                        "description": "movies",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/movies"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "search successful"
                    }
                }
            }
        },
        "/aws-mgr-api/storage": {
            "post": {
                "tags": ["aws-controller"],
                "description": "storage",
                "x-swagger-router-controller": "aws-controller",
                "operationId": "storage",
                "parameters": [
                    {
                        "name": "body",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/storage"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "stored Successfully"
                    }
                }
            }
        }
    },
    "definitions": {
        "movies": {
            "type": "object",
            "required": [
                "movieName"
            ],
            "properties": {
                "movieId": {
                    "type": "string"
                },
                "movieName": {
                    "type": "string"
                },
                "filters": {
                    "type": "object",
                    "properties": {
                        "period": {
                            "type": "string"
                        },
                        "year": {
                            "type": "array"
                        },
                        "language": {
                            "type": "array"
                        }
                    }
                }
            }
        },
        "storage": {
            "type":"object"
        }
    }
}
Community
  • 1
  • 1
Alexpandiyan Chokkan
  • 1,025
  • 1
  • 10
  • 30