有没有方法为最新版本的API创建Swagger Doc?
我使用名为“ Swagger”的dotnet工具来创建一个Swagger JSON文件,其中包含特定版本的API规格。 命令像: Swagger Tofile -serializeasv2-输出REST-API.JSON C:\ service.dll V1
,
您可以看到,我必须将Swagger Doc doc name v1 v1
传播到导出文件。该名称是API的版本。 有没有办法导出最新版本?
我试图创建一个带有名称“最新”的Swagger Doc,其中包含最新版本的API,但我不能。有人知道如何创建显示最新版本API的Swagger Doc吗?
I use dotnet tool called "swagger" to create a swagger json file that contains API spec for specific version.
Command be like:swagger tofile --serializeasv2 --output rest-api.json C:\Service.dll v1
As you can see I have to pass swagger doc name v1
to export file. The name is version of API.
Is there a way to export the latest version?
I tried to create a swagger doc with name "latest" that contains the latest version of API but I couldn't. Do anyone know how to create a swagger doc that display the latest version of API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
V1
是代码示例给出的默认名称,来自 swashbuckle项目:它没有特定的含义作为版本编号,而这正是代码作者选择称之为的。 “最新版本”是代码当前指定的任何内容。调用
C.SwaggerDoc
多次使用不同的名称揭示不同的摇摇欲坠文档,您可以选择使其名称表示一个版本 - 这取决于该项目的swashbuckle配置。v1
is the default name given by the code example from the Swashbuckle project:It has no particular meaning as a version number beyond this - it's just what the code author has chosen to call it. The 'latest version' is whatever the code currently specifies. Calling
c.SwaggerDoc
multiple times with different names would expose different Swagger documents and you could choose to make their name indicate a version - this is down to the project's Swashbuckle configuration.谢谢每个人的帮助。我找到了解决方案。
主要目标是避免在出现新版本API时更改控制台命令。我说的是最后一部分
v1
。如果出现V2 DOC,我必须将其传递给命令。现在,我可以将
最新
值传递给命令,并获取包含最新版本API的REST-API.JSON。我所做的是:
在我的项目中,我实施了一个实现
iswaggerProvider
的服务装饰仪,然后在服务集合中注册。
现在,当我使用“最新”参数运行命令时,我将使用最新的API版本获得生成的文件。
Thanks every one for help. I have found a solution.
The main goal is to avoid changing the console command when new version API appears. I am talking about the last part
v1
. If v2 doc appears, I have to pass it to the command.Now I can pass
latest
value to the command and get rest-api.json that contains the latest version of API.What I did:
In my project I have implemented a decorator for the service that implements
ISwaggerProvider
Then register it in service collection.
Now, when I run the command with 'latest' parameter, I get generated file with the latest API version.