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);