[英]@nestjs/swagger: How to add API URL?
I'm using @nestjs/swagger.我正在使用@nestjs/swagger。 Here is the simple example how I'm using it
这是我如何使用它的简单示例
const document = SwaggerModule.createDocument(
app,
new DocumentBuilder()
.setTitle('API')
.setDescription('API')
.setVersion('1.0')
.addBearerAuth()
.build(),
);
SwaggerModule.setup('/api/doc', app, document);
Before I could add API url using setHost('URL HERE')
but now it is not working.在我可以使用
setHost('URL HERE')
添加 API url 之前,但现在它不起作用。 So I want to add api url to which will be sent the requests from the Swagger UI.所以我想添加 api url,将从 Swagger UI 发送请求。 I'm beginner so sorry if the question is not very smart Thanks!
如果问题不是很聪明,我是初学者很抱歉谢谢!
Looks like you are using @nestjs/swagger version 4***.看起来您正在使用 @nestjs/swagger 版本 4***。 setHost was removed in version 4*** but was available in version 3***.
setHost 在版本 4*** 中被删除,但在版本 3*** 中可用。 If it works before I guess the version of @nestjs/swagger was updated in your project.
如果它在我猜测 @nestjs/swagger 的版本在您的项目中更新之前有效。
If you're currently using @nestjs/swagger@3.*, note the following breaking/API changes in version 4.0.
如果您当前正在使用 @nestjs/swagger@3.*,请注意 4.0 版中的以下重大/API 更改。
The following decorators have been changed/renamed:
以下装饰器已更改/重命名:
DocumentBuilder breaking changes (updated method signatures):
DocumentBuilder 重大更改(更新的方法签名):
The following methods have been added:
添加了以下方法:
So if you need to add the API URL to you Swagger UI page, you can do that by adding .addServer(API_URL)
.因此,如果您需要将 API URL 添加到 Swagger UI 页面,您可以通过添加
.addServer(API_URL)
。 API_URL can be either something like /api
or https://example.com/api
. API_URL 可以是
/api
或https://example.com/api
。 And it can be added multiple times.并且可以多次添加。 If you need for example URL for local usage, development, and production environments.
如果您需要例如本地使用、开发和生产环境的 URL。
The full example will look like
完整的例子看起来像
const document = SwaggerModule.createDocument(
app,
new DocumentBuilder()
.setTitle('API')
.setDescription('API')
.setVersion('1.0')
.addBearerAuth()
.addServer(API_URL)
.build(),
);
SwaggerModule.setup(swaggerPath, app, document);
i think you might be missing the 'includes' param of where the controller is.我认为您可能缺少控制器所在位置的“包含”参数。 try to add
尝试添加
const document = SwaggerModule.createDocument(
app,
new DocumentBuilder()
.setTitle('API')
.setDescription('API')
.setVersion('1.0')
.addBearerAuth()
.build(),
{ incliude: [ModuleWhereControllerIs] }
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.