Change swagger 2.0 docs path url

This is how I configure swagger:

const openapi = Openapi.initialize({ paths: openApiPaths, app, apiDoc, }); const openApiSpec = openapi.apiDoc; console.log(openApiSpec); app.use(swaggerUI(openApiSpec)); 

How to change the base path /docs/ to /projectName/docs/ ?

I did not find a suitable answer to this question

EDIT

My api doc is described below in its own file:

 export const apiDoc = { 'x-express-openapi-additional-middleware': [checkBodyValidity], swagger: '2.0', basePath: '/api/v1', info: { title: 'Documentation Rest API', version: 'v1', }, paths: {}, definitions: {} } 

CheckBodyValidity is a middleware that checks the validity of request parameters (not relevant to my question):

 export const checkBodyValidity: any = (req, res, next) => {} 

Swagger is initialized, as shown below, in a file called openapiSetup:

 export async function init(app: any): Promise<any> { [...] const openapi = Openapi.initialize({ paths: openApiPaths, app, apiDoc, }); const openApiSpec = openapi.apiDoc; app.use(swaggerUI(openApiSpec)); } 

-> openApiPaths is part of the path {} if the document. It is created from directories and file names.

Finally, in the express application:

 await openapiSetup.init(app); 
+5
source share
1 answer

What do you have in your YAML? Should update its path by changing:

 # Relative URL to external documentation externalDocs: url: /docs description: Find more info here 

Details [here] [1]

Edit:

You tried to add the following to your apiDoc object.

 export const apiDoc = { 'x-express-openapi-additional-middleware': [checkBodyValidity], swagger: '2.0', basePath: '/api/v1', info: { title: 'Documentation Rest API', version: 'v1', }, paths: {}, definitions: {}, externalDocs: { description: "Docs", url: "http://url/projectName/docs" } } 
+3
source

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


All Articles