标签: springdoc

springboot swagger3“无法加载远程配置。”

Spring Boot 2.6.3 与 Springdoc。

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.5</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

在 中applicaton.yaml,当我将路径设置为 /v3/api-docs 或将其删除时,这意味着使用默认路径“/v3/api-docs”。Swagger UI 页面使用 API http://localhost:8080/swagger-ui/index.html 正确显示

但我想重写路径如下

  api-docs.path: /bus/v3/api-docs
Run Code Online (Sandbox Code Playgroud)

然后 Swagger UI 显示“无法加载远程配置”错误:

加载api列表错误

java swagger-ui spring-boot springdoc springdoc-openapi-ui

34
推荐指数
5
解决办法
5万
查看次数

无法调用“org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()”,因为“this.condition”为空

我正在尝试使用 Spring Boot 2.6.7 运行 Springdoc。

配置:

@Configuration
public class SwaggerConfiguration {
  
  @Bean
  public GroupedOpenApi publicApi() {
    return GroupedOpenApi.builder()
            .group("springshop-public")
            .pathsToMatch("/public/**")
            .build();
  }
}
Run Code Online (Sandbox Code Playgroud)

错误堆栈:

00:50:54.956 [main] ERROR SpringApplication[reportFailure:830] - Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
    at com.atlas.psp.AtlasRouterApplication.main(AtlasRouterApplication.java:53) …
Run Code Online (Sandbox Code Playgroud)

java spring-boot springdoc springdoc-openapi-ui

28
推荐指数
3
解决办法
5万
查看次数

从 springfox swagger2 迁移到 springdoc openapi

https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/

试图遵循这些

我如何处理像这样的注释

@ApiModel(value = "Response container")

@ApiModelProperty(value = "Iventory response", required = true)
Run Code Online (Sandbox Code Playgroud)

swagger-2.0 openapi springdoc

26
推荐指数
2
解决办法
2万
查看次数

在 springdoc-openapi-ui 中为不记名令牌认证 (JWT) 启用授权按钮

如何在springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html) 中为不记名令牌认证启用“授权”按钮,例如 JWT。

Spring@Controller@Configuration类需要添加哪些注解?

授权按钮

不记名令牌认证的授权表

java spring jwt openapi springdoc

23
推荐指数
3
解决办法
1万
查看次数

使用/从 Springfox 迁移到 springdoc-openapi 有什么优势吗?

为了在 SpringBoot 2.7 中启用 Swagger,选择 springdoc-openapi 相对于 Springfox 的优点/缺点是什么

swagger swagger-ui spring-boot springfox springdoc

21
推荐指数
2
解决办法
2万
查看次数

springdoc-openapi-ui 如何将请求设置为HTTPS

当我发布时,我会使用HTTPS请求而不是HTTP,但是swagger原始URL仍然是HTTP,我不知道如何设置,并且原始springdoc-openapi-ui配置中没有服务器的文档

https://springdoc.org/index.html#properties 在此输入图像描述

springdoc springdoc-openui

20
推荐指数
2
解决办法
2万
查看次数

SpringDoc openAPI 工具未扫描 Spring Boot 项目中的 API

我无法让它发挥作用。我已经从一个工作的 SpringBoot (v2.2.2) 应用程序和一个工作的 @RestController 开始。为了让 springdoc 工作,我在我的 pom 中包含了以下依赖项:

\n\n
 <dependency>\n  <groupId>org.springdoc</groupId>\n  <artifactId>springdoc-openapi-ui</artifactId>\n  <version>1.2.28</version>\n</dependency>\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我构建并开始了我的服务。然后我浏览到 api-docs 端点,得到:

\n\n
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8081","description":"Generated server url"}],"paths":{},"components":{}}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我是不是少了一步?我假设在运行时它会扫描我的代码,找到 @RestController,找到 @RequestMapping 方法并从中生成 api。

\n\n

作为第二次尝试,我决定使用 swagger @Operation 注释来注释我的方法之一,但仍然没有被拾取。

\n\n

最后,我尝试使用 springdoc.packagesToScan 手动指定控制器的包,但这也不起作用。

\n\n

这感觉就像 springdoc 没有看到我的控制器..即使 spring 看到了..它完全活跃并且可以工作..

\n\n

不知道我错过了什么..

\n\n

这是我的项目依赖项:

\n\n
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.2.RELEASE:compile\n[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.2.2.RELEASE:compile\n[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.2.2.RELEASE:compile\n[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.2.RELEASE:compile\n[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.2.RELEASE:compile\n[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile\n[INFO] |  |  |  |  \\- ch.qos.logback:logback-core:jar:1.2.3:compile\n[INFO] | …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui spring-boot openapi springdoc

19
推荐指数
3
解决办法
5万
查看次数

springdoc-openapi 可以应用默认的全局 SecurityScheme 吗?

SecurityScheme对 java SpringBoot RESTful 应用程序使用 springdoc-openapi有以下定义:

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components().addSecuritySchemes("bearer-jwt",
                 new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")
                .in(SecurityScheme.In.HEADER).name("Authorization")))
                .info(new Info().title("App API").version("snapshot"));
    }
Run Code Online (Sandbox Code Playgroud)

是否可以将其全局应用于所有路径,而不必在代码中的任何地方添加@SecurityRequirement注释@Operation

如果是,如何向不安全的路径添加排除项?

java spring swagger openapi springdoc

15
推荐指数
2
解决办法
8404
查看次数

使用 Spring 的 Swagger UI 上出现 404 错误(springdoc-openapi 配置)

我正在将 swagger UI 添加到我的 Spring boot 应用程序中。当我尝试访问 swagger-ui.html 时。我收到 404 错误。

配置类:

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("JOYAS-STOCK API Docs")
                        .description("JOYAS-STOCK REST API documentation")
                        .version("v1.0.0"));
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序属性:

#swagger-ui config
springdoc.swagger-ui.path=/swagger-ui
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
Run Code Online (Sandbox Code Playgroud)

pom.xml:

<dependency>
   <groupId>org.springdoc</groupId>
   <artifactId>springdoc-openapi-ui</artifactId>
   <version>1.6.13</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

错误消息:Whitelabel 错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。

出现意外错误(类型=未找到,状态=404)。

我开始实施 swagger 的配置,显然它不起作用。

单击查看错误屏幕

spring swagger-ui spring-boot openapi springdoc

13
推荐指数
2
解决办法
3万
查看次数

如何使用 springdoc-openapi-webflux-ui 显示应用程序 API 文档?

我阅读了这个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

java spring spring-boot springdoc

12
推荐指数
1
解决办法
6671
查看次数