我试图让Swagger UI使用Spring Boot 1.2.1.我按照https://github.com/martypitt/swagger-springmvc上的说明操作,然后添加@EnableSwagger了我的spring配置.
我现在回到JSON http://localhost:8080/api-docs但是没有好的HTML.
我正在使用Maven并添加了对swagger-ui的依赖:
<dependency>
<groupId>org.ajar</groupId>
<artifactId>swagger-spring-mvc-ui</artifactId>
<version>0.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是我完整的依赖列表:
<dependencies>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.9.4</version>
</dependency>
<dependency>
<groupId>org.ajar</groupId>
<artifactId>swagger-spring-mvc-ui</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我也尝试http://localhost:8080/docs/index.html过URL,但这只是给出了"Whitelabel错误页面"
更新:
我在Github上创建了一个测试项目以显示问题:https://github.com/wimdeblauwe/springboot-swagger-test
我是Swagger的新手.
我正在使用Swagger UI生成swagger文档.我有两个API调用.第一个调用是根据用户名和密码生成令牌.第二次呼叫需要第一次呼叫生成的令牌.
我如何使用Swagger UI为第二次调用设置该令牌?
为了在 SpringBoot 2.7 中启用 Swagger,选择 springdoc-openapi 相对于 Springfox 的优点/缺点是什么
我正在运行一个服务,可以在以下位置访问Swagger UI:
http://serviceURL/swagger-ui.html
Run Code Online (Sandbox Code Playgroud)
但是,它位于代理之后,例如:
http://proxyURL/serviceName
Run Code Online (Sandbox Code Playgroud)
Swagger UI生成的URL看起来像:
http://proxyURL/
Run Code Online (Sandbox Code Playgroud)
而不是具有serviceName作为后缀的实际URL.据我所知,这意味着操纵basePath属性.根据文件:
swagger API文档无法再描述不同基本路径上的操作.在1.2及更早版本中,每个资源都可以有一个单独的basePath.在2.0中,为整个规范定义了basePath等价物(scheme + host + basePath).
@Api(basePath)已弃用,它没有说明使用什么以及如何使用它.如何使Swagger生成的路径正确显示?
我正在使用Spring Boot,Springfox Swagger和注释.
我正在尝试在.NET Core 3 Preview 5 Web API项目中从Swashbuckle的4.0.1版本迁移到5.0.0-rc2。
我已经完成了项目的编译,并且Swagger UI正常运行,但是我无法使Bearer身份验证正常工作,这是由于我没有正确设置新格式的安全性。
这是我在版本4中使用的旧代码:
c.AddSecurityDefinition("Bearer", new ApiKeyScheme
{
Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
Name = "Authorization",
In = "header",
Type = "apiKey"
});
var security = new Dictionary<string, IEnumerable<string>>
{
{"Bearer", new string[] { }},
};
c.AddSecurityRequirement(security);
Run Code Online (Sandbox Code Playgroud)
这就是我将其更改为v5的内容:
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] …Run Code Online (Sandbox Code Playgroud) 几天前,应用程序正在使用 Springfox Swagger 3.0。突然它停止工作。一周前创建的 Jar 文件仍在工作,但现在当我们尝试构建一个新的 Jar 文件时,即使没有任何代码/库更改,它也无法工作。我什至参考了以下 URL,但仍然面临问题。
swagger-ui 和 spring webflux 的 404 错误
下面给出了我的配置:
POM文件:
<properties>
<java.version>1.8</java.version>
<springfox.version>3.0.0-SNAPSHOT</springfox.version>
<spring.version>2.3.1.RELEASE</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-milestone</id>
<name>Spring Milestone Maven Repository</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
配置文件:
@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfiguration implements WebFluxConfigurer {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.description("My Reactive API")
.title("My Domain object API") …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 API 生成 swagger 文档。每次我导航到 swagger 文档时都会收到此错误:
不明确的 HTTP 操作方法 - [ControllerName]Controller.DownloadFile。操作需要 Swagger/OpenAPI 3.0 的显式 HttpMethod 绑定
这是我的控制器中抱怨的“有问题的”代码:
using Models;
using Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LibrarianController : ControllerBase
{
private IFileUploadUtilties fileUtilities;
private IConfiguration config;
private ApiContext context;
private IFileRetrieval fileRetrieval;
public LibrarianController(IFileUploadUtilties utilities, IConfiguration config, FinwiseApiContext context, IFileRetrieval fileRetrieval)
{
fileUtilities = utilities;
this.config = config;
this.context = context;
this.fileRetrieval = fileRetrieval;
} …Run Code Online (Sandbox Code Playgroud) 我找不到任何有用的例子,如何实现以下内容:我希望我的Swagger-UI中的API方法按方法(GET-POST-PUT-DELETE)或/按字母顺序排序.
到目前为止,所有方法都以随机顺序显示,甚至不按给定源代码的顺序显示.
我使用Jax-RS + Jersey 1.
使用@ApiOperation的position属性进行排序对我来说不是一个选项,因为有太多的方法而且API仍在扩展,所以如果有一个新的,我需要更新所有.
任何提示?
我有一个使用嵌入式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-ui ×10
swagger ×7
spring-boot ×4
springfox ×4
swagger-2.0 ×3
.net ×1
.net-core ×1
asp.net-core ×1
c# ×1
java ×1
jax-rs ×1
jersey ×1
rest ×1
springdoc ×1
swashbuckle ×1