【发布时间】:2021-03-15 19:01:29
【问题描述】:
这有点奇怪。 springdoc-openapi-ui v1.2.32,生成的文档只包含控制器内的少数映射。
例子:
@Operation(
summary = "Foo",
description = "Foo"
)
@PostMapping(path="/v1/foo")
public ResponseEntity<ResponseObject> postFoo(@RequestBody FooRequestObject searchRequest, HttpServletRequest request){ ... }
@Operation(
summary = "Bar",
description = "Bar"
)
@GetMapping(path="/v1")
public ResponseEntity<ResponseObject> getBar(@RequestBody BarRequestObject request, HttpServletRequest request){ ... }
@Operation(
summary = "Bar",
description = "Bar"
)
@PostMapping(path="/v1")
public ResponseEntity<ResponseObject> postBar(@RequestBody BarRequestObject request, HttpServletRequest request){ ... }
仅为postBar 和getBar 服务生成文档,忽略其他路径。
我尝试过的:
- 最初两种 POST 方法都命名为
post。我重命名以避免冲突。 - 我没有设置控制器级路径。
- 检查注释导入
- 未命中文档的缓存版本
如果我向控制器添加另一个服务(带有或不带有注释标记),它也不会显示在生成的 Swagger 中。例如:
@GetMapping(path="/test")
public String getTest(){
return "test";
}
如果我将此方法添加到全新的控制器,则会生成 doc。
谢谢
编辑 配置类
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springOpenAPI() {
return new OpenAPI()
.info(new Info().title("My API")
.description("My API service documentation. ")
.version("v1.0")
.license(new License().name("Terms of Use").url("https://myapi.com/terms.html")));
}
}
【问题讨论】:
-
您能否分享显示此错误的代码的可重现副本?
-
我不能,但我可以在原始问题中添加任何可能有用的内容。
-
如果有的话,你能分享
application.properties(或类似的)中的属性吗 -
我还看到
(@RequestBody BarRequestObject request, HttpServletRequest request)是错误的,因为两个参数具有相同的名称,这会导致编译错误。我已经尝试了修改当前代码以修复错误,它确实对我有用 -
这个错误只是我混淆的一个错字,代码本身是正确的并且构建良好。这是
application.properties的部分:springdoc.paths-to-match=/api/v1,/v2,/v3,/status
标签: spring-boot swagger openapi springdoc springdoc-openapi-ui