我阅读了这个https://springdoc.github.io/springdoc-openapi-demos/文档以使用 springdoc-openapi-webflux-ui。正如文档所说,我刚刚springdoc-openapi-webflux-ui在我的应用程序中添加了库:implementation('org.springdoc:springdoc-openapi-webflux-ui:1.2.26')
此外,我在 application.yml 中自定义了 API 的路径:
springdoc:
swagger-ui:
path: /swagger-ui.html
Run Code Online (Sandbox Code Playgroud)
当我启动应用程序并转到http://localhost:8080/swagger-ui.html 时,它会将我重定向到http://localhost:8080/webjars/swagger-ui/index.html?configUrl=/v3/api -docs/swagger-config。在该页面中,我收到一个错误:
Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Mon Jan 20 05:16:10 UTC 2020
[7192d9dc] There was an unexpected error (type=Not Found, status=404).
No matching handler
Run Code Online (Sandbox Code Playgroud)
问题是:我应该向我的应用程序添加其他配置以显示 API 文档吗?
PS:我使用 spring.boot 2.2.2:RELEASE
我现有的项目在 Spring Framework 上,而不是 Spring Boot。
我想将 Open API 3 与它集成。
我想使用 springdoc-openapi 而不使用 Jersey 进行集成。
如何在springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html) 中启用“授权”按钮以进行基本身份验证。
Spring@Controller和@Configuration类需要添加哪些注解?
我正在使用 Springdoc 来记录在 Spring Boot 中制作的 REST API。\n我需要从Swagger UI 的Schemas部分隐藏一些模型/架构,这些模型/架构仅在 API 内部使用,因此无需在Schemas部分中显示它们。
\n这是我试图隐藏的模型之一:
\n@Getter\n@Setter\n@EqualsAndHashCode(callSuper = true)\n@AllArgsConstructor\n@NoArgsConstructor\n@Entity\n@Table\npublic class EventRole extends AbstractEntity implements Serializable {\n @Column(nullable = false, length = 25)\n private String descriptor;\n}\nRun Code Online (Sandbox Code Playgroud)\n上面显示的模型的超类:
\n@Data\n@RequiredArgsConstructor\n@SuperBuilder\n@MappedSuperclass\npublic abstract class AbstractEntity {\n @Id\n @GeneratedValue(strategy = GenerationType.IDENTITY)\n private Long id;\n\n @CreationTimestamp\n @Column(nullable = false, updatable = false)\n private LocalDateTime creationDate;\n\n @UpdateTimestamp\n @Column(nullable = false)\n private LocalDateTime modificationDate;\n}\nRun Code Online (Sandbox Code Playgroud)\n这些示例中的大多数注释都来自 JPA 或 Lombok。\n需要明确的是:在模式AbstractEntity部分 \xe2\x80\x93中不可见,我将其包含在此处以防万一。
我可以通过代码自定义 OpenAPI 。
我可以像swagger-petstore
一样对 openapi.yaml 做同样的事情吗
?我用一个 @RestController 创建简单的 springboot 项目。
我创建 openapi.yaml 并将其复制到 /src/main/resources/。
但我在打开的 swagger-ui 页面上看到默认值。
我正在使用SpringDoc 1.4.3招摇。
我添加了以下配置以禁用中的petstoreURLapplication.yml
配置
springdoc:
swagger-ui:
disable-swagger-default-url: true
tags-sorter: alpha
operations-sorter: alpha
doc-expansion: none
Run Code Online (Sandbox Code Playgroud)
但是当我在探索文本框中点击https://petstore.swagger.io/v2/swagger.json时,它仍然显示如下图所示的 petsore URL。
招摇形象
swagger-ui openapi springdoc springdoc-ui springdoc-openapi-ui
需要 springdoc-openapi-ui 的一些帮助!
我正在使用 springdoc-openapi-ui 来呈现我的 API 模式。这是它的版本详细信息。
现在,我已经在我的 Spring Boot 应用程序中完成了一些配置,如下所示

现在,我期望当我点击 时localhost:15041/swagger-ui.html,它应该默认带我http://localhost:15041/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config到此并呈现我的 API 文档,但不幸的是它只呈现 Petstore。即使我直接转到http://localhost:15041/swagger-ui.html?configUrl=/v3/api-docs/swagger-config,它也不会使用 swagger-config 进行渲染。

虽然如果我去localhost:15041/v3/api-docs我会得到我的 json API 文档localhost:15041/v3/api-docs/swagger-config,并且我会得到 swagger-config。另外,如果我进入/v3/api-docspetstore 页面的 Explore 搜索区域,它会显示我的 API 文档。
我花了超过 1.5 天的时间来修复它,但它不起作用。如果有人可以提供帮助,我真的很感激。
我使用这个库来生成文档:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我有这个控制器:
@RestController
public class TestController {
@GetMapping("/test{hz}")
public String test(@PathVariable(value = "hz", required = false) String hz) {
return "test";
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个文档:
为什么required = false不起作用?
我试过这个:
@RestController
public class TestController {
@GetMapping("/test{hz}")
public String test(
@Parameter(description = "foo", required = false)
@PathVariable(value = "hz", required = false) String hz) {
return "test";
}
}
Run Code Online (Sandbox Code Playgroud)
也不起作用
编辑:(@Helen 评论的答案)-我当然知道这一点:
@RestController
public class TestController {
@GetMapping(value = {"/test", "/test{hz}"})
public String test(
@Parameter(description …Run Code Online (Sandbox Code Playgroud) spring swagger spring-restcontroller springdoc springdoc-openui
我正在尝试创建springdocswagger 文档,并且我想Map<String, Object>以更好的客户端可读方式表示具有数据类型的请求正文。但是当我声明@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(schema = @Schema(implementation = Map.class)架构如下String(附有下面的屏幕截图)
方法声明
@Operation(security = {@SecurityRequirement(name = "bearer-key")}, summary = "Create Data", operationId = "createData", description = "Create createData for the **`type`**. ")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Data created", content = @Content(schema = @Schema(implementation = Map.class),
examples = {@ExampleObject(value = "{\n" +
" \"id\": \"927d810c-3ac5-4584-ba58-7c11befabf54\",\n" +
"}")})),
@ApiResponse(responseCode = "400", description = "BAD Request")})
@PostMapping(value = "/data/type", produces = APPLICATION_JSON_VALUE, consumes …Run Code Online (Sandbox Code Playgroud) 我已经使用 Java 项目的 pom 文件中的以下工件安装了 swagger-ui:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>1.5.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我访问此 URL 时,我可以查看 RESTful 端点的 swagger ui
http://localhost:8081/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
Run Code Online (Sandbox Code Playgroud)
但不是这个链接
http://localhost:8081/swagger-ui/index.html
Run Code Online (Sandbox Code Playgroud)
为什么是这样?如何将其改回预期的 URL?
springdoc ×10
swagger-ui ×5
openapi ×4
spring ×4
swagger ×4
java ×3
spring-boot ×3
springdoc-ui ×2
rest ×1