标签: swagger-ui

无法从spring-boot应用程序中调出swagger-ui

我有一个使用嵌入式tomcat服务器运行的spring启动应用程序.我部分成功地将springfox-swagger与应用程序集成在一起.如果我执行/ v2/api-docs,我可以在webapp中查看所有api的所有文档.但是,当我尝试从UI访问相同时,它不起作用.以下是详细结果.

输出 - localhost:8080/api/swagger-resources

[ {
  "name" : "default",
  "location" : "/v2/api-docs",
  "swaggerVersion" : "2.0"
} ]
Run Code Online (Sandbox Code Playgroud)

输出 - localhost:8080/api/v2/api-docs

I get valid results. I can confirm that and the output is too large to paste here
Run Code Online (Sandbox Code Playgroud)

但是当我尝试访问swagger-ui时,它不起作用.下面是我调用以访问swagger-ui的不同URL.

http://localhost:8080/swagger-ui.html - UI is loading, but no documentation of API's is present
http://localhost:8080/api/swagger-ui.html  - 404 Not Found
http://localhost:8080/springfox - 404 Not Found
http://localhost:8080/api/springfox - 404 Not Found
Run Code Online (Sandbox Code Playgroud)

下面是我的SwaggerConfig.java类

package com.vmware.vrack.lcm;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui spring-boot swagger-2.0

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

Swagger 2.0在哪里声明Basic Auth Schema

如何使用Swagger 2.0注释定义基本身份验证并将其显示在swagger UI中.

在我拥有的资源中:

@ApiOperation(value = "Return list of categories", response=Category.class, responseContainer="List", httpMethod="GET", authorizations = {@Authorization(value="basicAuth")})
public Response getCategories();
Run Code Online (Sandbox Code Playgroud)

我看了看这里:

https://github.com/swagger-api/swagger-core/wiki/Annotations#authorization-authorizationscope

并且它说"一旦你声明并配置了你在API中支持的授权方案,你就可以使用这些注释来记录资源或特定操作需要哪种授权方案"但我找不到任何谈论的内容.在哪里声明和配置授权方案.

更新:

我找到了有关如何声明架构的代码,但我仍然没有在UI中看到有关身份验证架构的任何信息.我不确定我错过了什么

@SwaggerDefinition
public class MyApiDefinition implements ReaderListener {
    public static final String BASIC_AUTH_SCHEME = "basicAuth";

    @Override
    public void beforeScan(Reader reader, Swagger swagger) {
    }

    @Override
    public void afterScan(Reader reader, Swagger swagger) {
        BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
        swagger.addSecurityDefinition(BASIC_AUTH_SCHEME, basicAuthDefinition);
    }
}
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui swagger-2.0

19
推荐指数
2
解决办法
2万
查看次数

SpringDoc openAPI 工具未扫描 Spring Boot 项目中的 API

我无法让它发挥作用。我已经从一个工作的 SpringBoot (v2.2.2) 应用程序和一个工作的 @RestController 开始。为了让 springdoc 工作,我在我的 pom 中包含了以下依赖项:

\n\n
 <dependency>\n  <groupId>org.springdoc</groupId>\n  <artifactId>springdoc-openapi-ui</artifactId>\n  <version>1.2.28</version>\n</dependency>\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我构建并开始了我的服务。然后我浏览到 api-docs 端点,得到:

\n\n
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8081","description":"Generated server url"}],"paths":{},"components":{}}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我是不是少了一步?我假设在运行时它会扫描我的代码,找到 @RestController,找到 @RequestMapping 方法并从中生成 api。

\n\n

作为第二次尝试,我决定使用 swagger @Operation 注释来注释我的方法之一,但仍然没有被拾取。

\n\n

最后,我尝试使用 springdoc.packagesToScan 手动指定控制器的包,但这也不起作用。

\n\n

这感觉就像 springdoc 没有看到我的控制器..即使 spring 看到了..它完全活跃并且可以工作..

\n\n

不知道我错过了什么..

\n\n

这是我的项目依赖项:

\n\n
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.2.RELEASE:compile\n[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.2.2.RELEASE:compile\n[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.2.2.RELEASE:compile\n[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.2.RELEASE:compile\n[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.2.RELEASE:compile\n[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile\n[INFO] |  |  |  |  \\- ch.qos.logback:logback-core:jar:1.2.3:compile\n[INFO] | …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui spring-boot openapi springdoc

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

具有查询字符串的Swagger API

我想部署一个具有查询字符串的API.这是API

v1/products?q=circuit breaker&locale=en-GB&pageSize=8&pageNo=1&project=GLOBAL
Run Code Online (Sandbox Code Playgroud)

以下是我的实施方式

"/v1/products?q={searchText}&locale={ctrCode}&pageSize={pageSize}&pageNo={pageNo}&project={project}&country={country}":{  
         "get":{  
            "tags":[  
               "Search Text"
            ],
            "summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)",
            "description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)",
            "operationId":"getProductName",
            "produces":[  
               "application/json",
               "application/xml"
            ],
            "parameters":[  
               {  
                  "name":"searchText",
                  "in":"path",
                  "description":"The Product that needs to be fetched",
                  "required":true,
                  "type":"string"
               },
               {  
                  "name":"ctrCode",
                  "in":"path",
                  "description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.",
                  "required":true,
                  "type":"string"
               },
               {  
                  "name":"pageSize",
                  "in":"path",
                  "description":"The Product PageSize that needs to be fetched. …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui

18
推荐指数
2
解决办法
4万
查看次数

如何在Swagger UI中发送带有请求的Authorization标头?

我有一个ASP.NET Web Api 2应用程序.我添加了Swashbuckle(Swagger for .NET).它显示我的端点没问题,但是为了发送请求,我需要将Authorization标头附加到该请求.如果我理解为了做到这一点我需要修改index.html文件(https://github.com/swagger-api/swagger-ui#how-to-use-it)所以我git克隆了Swashbuckle项目为了修改index.html并添加一些标题.

这是在Swashbuckle中发送带有请求的Authorization标头的唯一方法吗?

swagger swagger-ui swagger-2.0 swashbuckle

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

Swagger(Swashbuckle)隐藏标题

我使用Swashbuckle将Swagger文档添加到我的ASP.NET Web API项目中.如何在不注入CSS的情况下从文档页面隐藏默认标题(带有swagger徽标)?

swagger swagger-ui swashbuckle

18
推荐指数
2
解决办法
7530
查看次数

Django REST框架Swagger 2.0

很难配置Swagger UI以下是非常简洁的文档:https://django-rest-swagger.readthedocs.io/en/latest/

YAML文档字符串已弃用.有人知道如何从python代码中配置Swagger UI吗?或者我应该将哪个文件更改为组api端点,为每个端点添加注释,在Swagger UI中添加查询参数字段?

django django-rest-framework swagger-ui swagger-2.0 openapi

18
推荐指数
3
解决办法
6417
查看次数

动作需要 Swagger 的独特方法/路径组合

HTTP GET在同一个控制器中有 2 个方法并给我这个错误

HTTP 方法“GET”和路径“api/DataStore”被动作重载 - DPK.HostApi.Controllers.DataStoreController.GetByIdAsync (DPK.HostApi),DPK.HostApi.Controllers.DataStoreController.GetAllAsync (DPK.HostApi)。操作需要 Swagger 2.0 的唯一方法/路径组合。

我的控制器:

[Route("api/[controller]")]
[ApiController]
public class DataStoreController : ApiControllerBase
{
    private readonly IDataStoreService _dataStoreService;

    public DataStoreController(IDataStoreService dataStoreService)
    {
        _dataStoreService = dataStoreService;
    }


    [HttpPost]
    public async Task<IActionResult> PostAsync([FromBody] DataStoreCommand dataStoreCommand)
    {
        try
        {
            if (ModelState.IsValid)
            {
                await _dataStoreService.PostAsync(dataStoreCommand);
                return Ok();
            }

            var errorList = ModelState.Values.SelectMany(m => m.Errors).Select(e => e.ErrorMessage).ToList();
            return ValidationProblem();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }


    [HttpPut]
    public async Task<IActionResult> PutAsync([FromBody] DataStoreCommand dataStoreCommand) …
Run Code Online (Sandbox Code Playgroud)

c# swagger swagger-ui asp.net-core asp.net-core-webapi

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

有没有 Springfox 的替代品?

过去两年,我使用 Springfox 开发 Spring Boot 应用程序。Springfox 为您的 REST API 生成文档和测试用户界面。这太棒了。

但实际上 Springfox 项目已经死了并且不支持最新的 Spring。我有三个问题

  1. 有没有其他方法可以直接生成 Swagger UI?任何其他图书馆/项目?
  2. 你如何在你的 Spring Boot 项目中实现 swagger ui?
  3. 也许我已经过时了,有没有更好的替代 Spring Boot 的招摇人员?

更新 经过数月的大量使用和测试

SpringDoc OpenApi

我们的经历很好。

swagger swagger-ui spring-boot springfox

18
推荐指数
2
解决办法
7869
查看次数

规范中没有定义任何操作!- 即使设置了swagger并定义了端点,我也会收到此错误

我正在尝试使用 swagger npm 包在我的节点应用程序之上设置 swagger。我的终点和招摇设置完美(至少几乎完美),我确实对出了什么问题进行了大量研究,但我找不到踪迹。我的招摇设置文件:

const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const abc= require('./routes/abc');
var app = express();

const swaggerDefinition = {
    info: {
        title: 'Analytics Project',
        version: '1.0.0',
        description: 'Analytics API swagger documentation'
    }
};
const options = {
    swaggerDefinition,
    apis: ['./routes/abc.js']
};

const swaggerSpec = swaggerJSDoc(options);

var api = require('./routes/abc');
app.use('/', api);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/api/v1/abc', abc); …
Run Code Online (Sandbox Code Playgroud)

swagger-ui swagger-node-express

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