SSK*_*SSK 2 swagger swagger-ui spring-boot springdoc springdoc-openui
我正在从 springfox 2.9.0 迁移到 springdoc-openapi-ui 1.2.33。我需要根据条件在 swagger ui 上显示或隐藏 PathVariable 。我有两条路径如下
字符串名称标识符 = "{fisrtName}/{lastName}"
字符串名称标识符 = "{fisrtName}"
我根据要求传递上述 nameIdentifier 之一。
我对上述路径使用单个控制器,如下所示
@GetMapping(path = "persons/${nameIdentifier}/display")
public List<Person> getPersons(@PathVariable String fisrtName,
@IgnoreLastName @PathVariable Optional<String> lastName) {
}
Run Code Online (Sandbox Code Playgroud)
在 springfox 中,我能够使用docket.ignoredParameterTypes(IgnoreLastName.class)
如下所示的方法来实现它。
@Bean
public Docket api() {
Docket docket;
docket = new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("go.controller")).paths(PathSelectors.any()).build()
.apiInfo(apiInfo());
if (!nameIdentifier.contains("lastName")) {
docket.ignoredParameterTypes(IgnoreLastName.class);
}
return docket;
}
Run Code Online (Sandbox Code Playgroud)
但在 springdoc open api 中我无法实现相同的目标。同样感谢您的帮助。编码是用java完成的
谢谢
您可以使用@Hidden
swagger 注释或@Parameter(hidden = true)
.
如果无法传递参数级别,可以全局设置:需要升级到 springdoc-openapi-ui v1.3.0。
static {
SpringDocUtils.getConfig().addAnnotationsToIgnore(IgnoreLastName.class);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8245 次 |
最近记录: |