这就是我配置swagger的方式:
const openapi = Openapi.initialize({
paths: openApiPaths,
app,
apiDoc,
});
const openApiSpec = openapi.apiDoc;
console.log(openApiSpec);
app.use(swaggerUI(openApiSpec));
如何将基本路径/docs/
更改为/projectName/docs/
?
我没有找到任何相关的答案
修改
我的api doc在其自己的文件中描述如下:
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是一种检查请求参数有效性的中间件(与我的问题无关):
export const checkBodyValidity: any = (req, res, next) => {}
Swagger在名为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));
}
- &GT;如果是doc,openApiPaths是路径{}部分。它是由目录和文件名构建的
最后在快递应用中:
await openapiSetup.init(app);
答案 0 :(得分:3)
你的YAML有什么?应该可以通过修改:
来更新您的路径# Relative URL to external documentation
externalDocs:
url: /docs
description: Find more info here
更多信息[这里] [1]
编辑:
您是否尝试将以下内容添加到apiDoc对象中。
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"
}
}