我正在尝试将 swagger-ui (OpenAPI 3.0) 添加到 Spring Boot v3 应用程序中。
我已经添加了 openapi-ui maven 依赖项,它应该按照文档工作。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但显然,它仍然不起作用,并且 localhost:8080/swagger-ui.html 返回 404 错误。
我缺少什么?
我使用Swagger UI来显示我的REST Web服务并将其托管在服务器上.
但是,Swagger的这项服务只能在特定服务器上访问.如果我想离线工作,有人知道如何使用Swagger UI创建静态PDF并使用它吗?此外,PDF很容易与无权访问服务器的人共享.
非常感谢!
开箱即用的配置在我的机器上完美运行,完全没有问题.
但是当我部署到我们的测试环境时 - 我收到以下消息
500:{"消息":"发生了错误."/api/swagger/docs/v1
我猜它与baseUrl或类似的东西有关,但我甚至不知道从哪里开始.
我的路线在项目中运行良好 - 我可以调用我的所有webapi端点并且它们正确响应.
任何帮助将非常感激
有没有办法将所有枚举显示为swagger中的字符串值而不是int值?
我希望能够提交POST操作并根据其字符串值放置枚举,而不必每次都查看枚举.
我试过,DescribeAllEnumsAsStrings但服务器接收字符串而不是枚举值,这不是我们正在寻找的.
有人解决了这个吗?
编辑:
public class Letter
{
[Required]
public string Content {get; set;}
[Required]
[EnumDataType(typeof(Priority))]
public Priority Priority {get; set;}
}
public class LettersController : ApiController
{
[HttpPost]
public IHttpActionResult SendLetter(Letter letter)
{
// Validation not passing when using DescribeEnumsAsStrings
if (!ModelState.IsValid)
return BadRequest("Not valid")
..
}
// In the documentation for this request I want to see the string values of the enum before submitting: Low, Medium, High. Instead of 0, 1, 2
[HttpGet]
public …Run Code Online (Sandbox Code Playgroud) 是否有任何Swagger UI替代品?我已经知道了:
我在我的应用程序中加入了swagger UI.
当我尝试看到swagger UI时,我很好地获得了API的文档但是在一段时间后它在按钮上显示了一些错误图标.
错误消息如下所示:
[{"level":"error","message":"无法从文件中读取 http:// MYIP/swagger/docs/v1 "}]
我不确定是什么导致它.如果我刷新它工作并在几秒后显示错误.
我的项目有Spring Security.主要问题:无法访问http:// localhost:8080/api/v2/api-docs中的 swagger URL .它表示缺少或无效的授权标头.
浏览器窗口的屏幕截图 My pom.xml包含以下条目
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
SwaggerConfig:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("My REST API", "Some custom description of API.", "API TOS", "Terms of service", "myeaddress@company.com", "License of API", "API license URL");
return apiInfo;
}
Run Code Online (Sandbox Code Playgroud)
AppConfig的:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.musigma.esp2" })
@Import(SwaggerConfig.class) …Run Code Online (Sandbox Code Playgroud) 我非常喜欢大量记录Restful API,特别是"试试看!" 按钮,但swagger-ui界面看起来不是很酷.
而且我无法相信这些神奇的开源工具没有模板(或者我找不到任何模板)?
我不希望它是免费的..像http://getbootstrap.com/有很多网站购买主题(如https://wrapbootstrap.com/),为什么我找不到任何swagger主题的网站?
lockdown-run.js:17 锁定失败:TypeError:在内在函数.Object.groupBy 预期布尔值不起作用
lockdown-more.js:99 保护内在函数失败:ReferenceError:harden 未定义(匿名)@lockdown-more.js:99
我试图解决这个问题但没有得到任何答案。
我在API中有一些端点 - /user/login, /products.
在扬鞭UI我张贴email,并password到/user/login和我收到的响应token串.
然后,我可以从响应中复制令牌,并希望将其用作Authorization对所有URL的请求中的标头值(如果它存在),并/products作为示例.
我应该在Swagger UI页面上的某处手动创建文本输入,然后将令牌放在那里并以某种方式注入请求或是否有工具以更好的方式管理它?
swagger-ui ×10
swagger ×4
swashbuckle ×3
c# ×2
api ×1
java ×1
pdf ×1
spring ×1
spring-boot ×1
spring-mvc ×1
springfox ×1
swagger-2.0 ×1
themes ×1