我正在从 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完成的
谢谢
我正在使用 Spring Boot 和 Open API 3。当我发出 POST 请求时,通过 OAS2 Swagger,我看到所有字符串字段都以 Spring 的默认值出现,并且我没有看到通过 SpringDoc Open UI 删除它的方法也不通过代码。
{
"firstName": "string",
"lastName": "string",
"age": 0,
"email": "string",
"address1": "string",
"address2": "string",
"address3": "string",
"telephone" : "0",
"department" : "string",
.....
}
Run Code Online (Sandbox Code Playgroud)
这里消费者不愿意在发出请求时从字段中删除字符串。有什么办法吗
Springdoc 自动为所有处理程序方法生成 API 文档。即使没有 OpenAPI 注释。
如何从 API 文档中隐藏端点?
基本上我的问题与此相同,但针对 Springdoc (而不是 Springfox)。
简而言之,我有一个 Spring-boot 应用程序,并且我正在使用 spring-security @PreAuthorize 注释来保护我的一些 api,目前hasAuthority仅基于。
有没有办法可以根据注解自动修改具体的资源swagger描述?我想这与重写 Springdoc 的默认类行为之一有关(也许OpenAPICustomiser?),但我不确定如何做到这一点。
我在 Springdoc 生成的 OpenAPI 规范中遇到验证错误,并且无法在网上找到与我的 Java 代码的形成方式相匹配的示例。
我正在尝试使用 Springdoc 为 Spring Boot 控制器生成 OpenAPI 规范。我有一个具有多个路径变量的路径的映射,并且方法签名接受命令对象(命令对象是从这些路径变量自动构造的)。Swagger-UI.html 似乎或多或少可以工作,但生成的 JSON/YAML 规范似乎无效。
我指的代码片段:
@GetMapping("/myPath/{foo}/{bar}/{baz}")
public Mono<MyServiceResponse> doSomethingInteresting(@Valid DoSomethingInterestingCommand command) {
return interestingService.doSomethingInteresting(command);
}
Run Code Online (Sandbox Code Playgroud)
生成的 OpenApi 片段是:
paths:
'/myPath/{foo}/{bar}/{baz}':
get:
tags:
- my-controller
operationId: doSomethingInteresting
parameters:
- name: command
in: query
required: true
schema:
$ref: '#/components/schemas/DoSomethingInterestingCommand'
Run Code Online (Sandbox Code Playgroud)
这会产生如下错误:
Semantic error at paths./myPath/{foo}/{bar}/{baz}
Declared path parameter "foo" needs to be defined as a path parameter at either the path or operation level
Run Code Online (Sandbox Code Playgroud)
为了使生成的规范格式良好,我应该采取哪些不同的做法?我也很好奇为什么 swagger-ui.html 页面似乎工作正常,但这并不那么重要。
我正在使用 yaml 文件来控制项目的 swagger 页面上的内容。我几乎可以让所有东西看起来都正确,除了我想让顶部栏有“选择定义”下拉菜单(或者没有任何内容,如果现在更简单的话)而不是“探索”控件。到目前为止,我已经看到了如何实现这一点的零碎内容,但还没有从头开始完成。
\n\n\n\n问题是如何使用自定义 Swagger YML 文件在 Spring Boot 中创建自定义布局?看来你需要使用 React 创建一个自定义布局,我对此一无所知。一些进行自定义布局的示例非常简单。但是,我不知道将带有 React 代码的文件放在哪里。此外,一些示例表明 ok\xe2\x80\xa6yes 您需要通过指向 application.yml 文件中的自定义布局来配置它,如下所示:
\n\n我不知道以 aka MyLayout.js .jsx 或其他内容为后缀的 React 文件类型是什么。\n我也不知道在 Spring Boot 项目中的何处放置此自定义布局文件。\n我要编译它吗?如果是这样怎么办?
\n我正在尝试使用 Spring Boot 3、Java 17、Open Api 3 查看 Swagger 页面。
我一定做错了什么,但是什么?是不是有什么不兼容的地方?
在 http://localhost:8080/v3/api-docs/ 或 http://localhost:8080/swagger-ui 我得到Whitelabel错误页面。
我正在从 Spring Boot 2.5 迁移,但为了确保我没有忘记删除导致此错误的某些内容,我从此处复制了一个教程https://www.techgeeknext.com/spring-boot/spring-boot- swagger3-example(我在这篇文章的末尾写了它)。
虽然运行了,但控制台中出现错误:
ERROR Class 'org.springframework.core.io.support.PathMatchingResourcePatternResolver' could not be processed by org.zeroturnaround.javarebel.integration.spring.core.cbp.PathMatchingResourcePatternResolverCBP@jdk.internal.loader.ClassLoaders$AppClassLoader@7a46a697: org.zeroturnaround.bundled.javassist.NotFoundException: retrieveMatchingFiles(..) is not found in org.springframework.core.io.support.PathMatchingResourcePatternResolver
at org.zeroturnaround.bundled.javassist.CtClassType.getDeclaredMethod(SourceFile:1356)
at org.zeroturnaround.javarebel.integration.spring.core.cbp.PathMatchingResourcePatternResolverCBP.registerScannedDirs(PathMatchingResourcePatternResolverCBP.java:255)
at org.zeroturnaround.javarebel.integration.spring.core.cbp.PathMatchingResourcePatternResolverCBP.process(PathMatchingResourcePatternResolverCBP.java:41)
at org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor.process(SourceFile:137)
at org.zeroturnaround.javarebel.integration.support.CacheAwareJavassistClassBytecodeProcessor.process(SourceFile:34)
at org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor.process(SourceFile:83)
at com.zeroturnaround.javarebel.yg.a(SourceFile:413)
at com.zeroturnaround.javarebel.yg.a(SourceFile:340)
at com.zeroturnaround.javarebel.SDKIntegrationImpl.runBytecodeProcessors(SourceFile:44)
at com.zeroturnaround.javarebel.vk.transform(SourceFile:140)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:43009)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at org.springframework.core.io.support.ResourceArrayPropertyEditor.<init>(ResourceArrayPropertyEditor.java:77)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot + Spring Rest Pagination + Open API 3。
@Operation(summary = "Find Contacts by name", description = "Name search by %name% format", tags = { "contact" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful operation", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Contact.class)))) })
@Parameter(in = ParameterIn.QUERY, description = "Zero-based page index (0..N)", name = "page"
, content = @Content(schema = @Schema(type = "integer", defaultValue = "0")))
@Parameter(in = ParameterIn.QUERY, description = "The size of …Run Code Online (Sandbox Code Playgroud) 我有一个 Spring Boot 应用程序,它从 2 个规范文件生成 2 个 API。我可以swagger-ui通过添加为其中之一生成一个页面
springdoc.swagger-ui.url=/firstAPI.yaml
Run Code Online (Sandbox Code Playgroud)
到application.properties。但是我怎样才能包含第二个 API 呢?
我试过:
springdoc.swagger-ui.urls=/firstAPI.yaml,/secondAPI.yaml
Run Code Online (Sandbox Code Playgroud)
这会创建一个组合http://localhost:8080/v3/api-docs/,但http://localhost:8080/v3/api-docs/尽管可以在顶部栏中的两个规格之间进行选择,但页面显示“无法加载 API 定义”。
之前在 SpringBoot v2.5.7 中,我有这个 Spring REST 控制器方法。它有一个TestCriteriaDTO 类型作为路径参数。
@GetMapping(path = "/test")
public void test(TestCriteria testCriteria) {
}
Run Code Online (Sandbox Code Playgroud)
而TestCriteria班级就是这样的。(Language是一个可以采用 或EN的枚举FR)。
public class TestCriteria {
@ApiModelProperty(allowEmptyValue = true)
List<Language> langauges;
}
Run Code Online (Sandbox Code Playgroud)
我使用了 Springfox Swagger (springfox-boot-starter v3),Swagger UI 如下所示:
但后来我不得不将 SpringBoot 升级到 v3,并使用 Springdoc 和 OpenAPI v3 for Swagger。现在TestCriteria类看起来像这样:
public class TestCriteria {
@Schema(type="array")
@Parameter(allowEmptyValue = true)
List<Langauge> languages;
}
Run Code Online (Sandbox Code Playgroud)
现在 Swagger UI 不再显示languages为可选择值的字段,而是显示为对象。

我还比较了生成的 OpenAPI 定义,发现:
以前的 API …
swagger-ui spring-boot openapi springdoc springfox-boot-starter
我已经在外部安装了 swagger-ui,我只想将 swagger-ui (开源)实例从 openapi.yaml 连接到 localhost:8000/doc/api (.yaml) 。有什么想法吗?PS:我尝试使用
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components().addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
.info(new Info().title("SpringShop API").version("0.1")
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
.externalDocs(new ExternalDocumentation()
.url("restapi/doc/openapi.yaml"));
}
@Bean
public SpringDocConfiguration springDocConfiguration(){
return new SpringDocConfiguration();
}
@Bean
public SpringDocConfigProperties springDocConfigProperties() {
return new SpringDocConfigProperties();
}
Run Code Online (Sandbox Code Playgroud)
但我没有发现任何有用的东西。谢谢。
application.properties:
springdoc.api-docs.enabled=false
springdoc.swagger-ui.url=openapi.yaml
springdoc.swagger-ui.path=/doc/api/ui.html
dependecies:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)