相关疑难解决方法(0)

如何生成swagger.json

我正在使用java spring boot框架为我的项目创建REST api,我使用"springfox-swagger2和springfox-swagger-ui"来生成swagger文档.我可以使用url http:// localhost:8080/swagger-ui.html查看我的文档.

如何创建或生成swagger.json/spec.json,文档不应该与此应用程序一起使用我们使用单独的应用程序列出api文档

spring-mvc swagger swagger-ui swagger-2.0

27
推荐指数
5
解决办法
5万
查看次数

使用springfox和Swagger2时,为什么v2/api-docs是默认URL?

我刚开始按照这个指南开始使用招摇,但我发现了一些非常奇怪的东西对我来说毫无意义.

据我所知,当您拥有API版本号为2的文档时,应使用v2/api-docs.

所以,默认应该只是api-docs,但由于一些奇怪的原因,我发现默认是v2/api-docs.

检查库文档我发现了这个.

如何在不能使用v2的情况下覆盖该值?(当我的API将达到v2但我也想展示旧版文档).

或许我使用v2的概念是错误的?有人可以帮我弄这个吗?

java swagger springfox

25
推荐指数
1
解决办法
3万
查看次数

用于 net core 3.1 api 的 Swagger UI 非常慢

我将我们的网络核心 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)

c# swagger swagger-ui .net-core swashbuckle

9
推荐指数
2
解决办法
3935
查看次数

是否有可能获得网站的 swagger 文档的离线版本?

localhost/swagger 正在按预期加载,但 remoteserver/swagger 出现问题。我可以保存生成的 swagger 文档的离线副本吗?在尝试调试远程问题时,我可以将 zip 文件发送给几个用户。

.net c# asp.net-web-api swagger asp.net-web-api2

7
推荐指数
1
解决办法
8570
查看次数

FastAPI swagger 不喜欢通过查询参数传递的字符串列表,但端点在浏览器中工作

我在 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 教程“查询参数和字符串验证”部分中记录的字符串列表。端点在浏览器中按预期工作。

图。1

但是,它在 Swagger 文档中不起作用。单击“执行”以测试端点时,标记为“添加字符串项目”的按钮会晃动。Swagger UI 似乎无法使用嵌入的查询参数创建预期的 URL(如图 1 所示)。

图2

端点的代码如下。我尝试过有验证和没有验证。

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

swagger-ui fastapi

5
推荐指数
1
解决办法
6689
查看次数

MSB3037 openapi2csclient 退出,代码为 -1

我使用 Visual Studio Add-Service-Reference 添加使用 OpenAPI 规范的服务。 添加服务参考

我输入了 swagger URL 并生成了代码。

.csproj 表示该服务已配置。 服务参考

但是,当我尝试构建时出现错误。

该向导包含链接

该服务是使用 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

swagger autorest openapi nswag

5
推荐指数
1
解决办法
1440
查看次数

无法在 Swagger-ui-express npm 的授权标头中发送承载令牌

我正在运行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)

node.js swagger swagger-ui openapi

2
推荐指数
1
解决办法
4733
查看次数

NestJS - Swagger JSON 导出

我有 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

我已阅读官方文档,他们提到使用:

  • http://localhost:3000/api/json 或 http://localhost:3000/api-json

另外,我看了SO,有这个线程

不幸的是,这些都不适用于我的情况。

获取 JSON 格式文档的 URL 是什么?

swagger swagger-ui nestjs

0
推荐指数
1
解决办法
3895
查看次数