我正在使用java spring boot框架为我的项目创建REST api,我使用"springfox-swagger2和springfox-swagger-ui"来生成swagger文档.我可以使用url http:// localhost:8080/swagger-ui.html查看我的文档.
如何创建或生成swagger.json/spec.json,文档不应该与此应用程序一起使用我们使用单独的应用程序列出api文档
我将我们的网络核心 API 应用程序从 2.1 更新到 3.1,将 SwashBuckle.Asp.NetCore 更新到 5.0.0。这是我的启动集:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
string authServerUrl = "http://testserver.com/identityserver4";
services.AddControllersWithViews();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "NetCore API V1" });
// Define the OAuth2.0 scheme that's in use (i.e. Implicit …Run Code Online (Sandbox Code Playgroud) localhost/swagger 正在按预期加载,但 remoteserver/swagger 出现问题。我可以保存生成的 swagger 文档的离线副本吗?在尝试调试远程问题时,我可以将 zip 文件发送给几个用户。
我在 FastAPI 中的 REST API 端点上遇到问题,该端点通过单个查询参数接受字符串列表。此端点的用法示例如下:
http://127.0.0.1:8000/items/2?short=false&response=this&response=that
Run Code Online (Sandbox Code Playgroud)
此处,名为“response”的参数接受 FastAPI 教程“查询参数和字符串验证”部分中记录的字符串列表。端点在浏览器中按预期工作。
但是,它在 Swagger 文档中不起作用。单击“执行”以测试端点时,标记为“添加字符串项目”的按钮会晃动。Swagger UI 似乎无法使用嵌入的查询参数创建预期的 URL(如图 1 所示)。
端点的代码如下。我尝试过有验证和没有验证。
@app.get("/items/{item_ID}")
async def getQuestion_byID(item_ID: int = Path(
...,
title = "Numeric ID of the question",
description = "Specify a number between 1 and 999",
ge = 1,
le = 999
), response: Optional[List[str]] = Query(
[],
title="Furnish an answer",
description="Answer can only have letters of the alphabet and is case-insensitive",
min_length=3,
max_length=99,
regex="^[a-zA-Z]+$"
), short: bool = Query(
False,
title="Set …Run Code Online (Sandbox Code Playgroud) 我使用 Visual Studio Add-Service-Reference 添加使用 OpenAPI 规范的服务。

我输入了 swagger URL 并生成了代码。
但是,当我尝试构建时出现错误。
该向导包含此链接
该服务是使用 AutoRest 生成的。我使用的是VS2022 17.2.5
完整的错误是
错误 MSB3073 命令“”C:\Users\kirst.nuget\packages\nswag.msbuild\13.0.5\build../tools/Win/NSwag.exe” openapi2csclient /className:myapicls /namespace:myapi /input:D :\dev\MyApi\UnitTestProject1\OpenAPIs\index.html /output:obj\indexClient.cs " 退出,代码为 -1。UnitTestProject1 C:\Users\kirst.nuget\packages\nswag.apidescription.client\13.0.5\build\NSwag.ApiDescription.Client.targets 28
我正在运行express/node 应用程序并使用"swagger-ui-express": "^4.5.0",. 我已经设置了一个要求,即需要将jsonwebtoken不记名令牌与所有请求一起发送到我的 api 中的任何端点。
我已经加载了 swagger 文档并正常工作,但现在当试图弄清楚如何将其传递Authorization: Bearer <token>到我的所有端点时,它似乎不起作用。我可以添加securitySchemes+ 子选项,并在我的 swagger 文档中获得绿色Authorize按钮,但是当我输入不记名令牌并发送请求时,加载旋转器会继续旋转并且从不发送请求。我morgan在我的应用程序中设置了日志记录,因此我可以看到对我的端点的请求永远不会被发送或记录。
如何向从 swagger UI 发送的请求发送不记名令牌?
在 app.js 中,我有一条可以在 localhost 中正确加载的路由
// Single entry point for swagger docs
router.use(
'/swaggerDocs',
swaggerDoc.serve,
swaggerDoc.setup(swaggerDocumentation),
);
Run Code Online (Sandbox Code Playgroud)
swaggerDocumentation来自上面的代码片段(配置文件)。
import getCountryRegions from './getCountryRegions.doc.js';
export default {
openapi: '3.0.3',
info: {
title: 'Node/express rest api app',
version: '0.0.1',
},
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
in: 'header', …Run Code Online (Sandbox Code Playgroud) 我有 Swagger,效果很好。但我找不到将路由导出为 JSON 的方法。我记得这样做过,只需在浏览器中访问一个 URL,但现在我不记得了。
我的招摇设置是这样的:
const swaggerOptions = new DocumentBuilder()
.setTitle('Some API Docs')
.setDescription('Some API description')
.setVersion('1.0')
.build();
const swaggerDocument = SwaggerModule.createDocument(app, swaggerOptions);
SwaggerModule.setup('docs', app, swaggerDocument);
Run Code Online (Sandbox Code Playgroud)
我可以使用以下命令访问 Swagger UI: localhost:3000/docs
我已阅读官方文档,他们提到使用:
另外,我看了SO,有这个线程
不幸的是,这些都不适用于我的情况。
获取 JSON 格式文档的 URL 是什么?
swagger ×7
swagger-ui ×5
c# ×2
openapi ×2
.net ×1
.net-core ×1
autorest ×1
fastapi ×1
java ×1
nestjs ×1
node.js ×1
nswag ×1
spring-mvc ×1
springfox ×1
swagger-2.0 ×1
swashbuckle ×1