标签: springdoc-openapi-ui

在 IE 上为 SpringDoc Open API Swagger 迭代不可迭代实例的尝试无效

我最近将 swagger UI 从 更改SpringfoxSpringDoc OpenApi.

Swagger 在Chrome.

但在Internet Explore我得到以下错误。My IE version is 11

在此处输入图片说明

swagger-ui springdoc-openui springdoc-openapi-ui

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

springdoc-openapi:如何添加 POST 请求示例?

有以下Controller方法:

    @ApiResponses(value = {@ApiResponse(responseCode = "200")})
    @GetMapping(value = API_URI_PREFIX + PRODUCTS_URI, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(HttpStatus.OK)
    public Flux<Product> getProducts(@Valid @NotNull PagingAndSorting pagingAndSorting) {
   }
Run Code Online (Sandbox Code Playgroud)

我需要找到一种如何在对象Swagger示例中显示的方法PagingAndSorting

我正在使用springdoc-apiv1.4.3。

java swagger swagger-ui springdoc springdoc-openapi-ui

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

如何从我的 openapi swagger 中删除“api-resource-controller”

我目前正在使用以下openapi-ui依赖项。

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

如何从openapi-ui swagger屏幕中删除api-resource-controller

在此处输入图片说明

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

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

Springdoc-openapi - 有没有办法在 POST 请求中将默认值覆盖为 null 或空?

我正在使用 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)

这里消费者不愿意在发出请求时从字段中删除字符串。有什么办法吗

  1. 如果我们可以删除“string”作为值并将 null 或“”设置为默认值?
  2. 如果我们可以读取自定义对象并将找到“字符串”的所有值重置为 null,有什么办法吗?

springdoc springdoc-openui springdoc-openapi-ui

2
推荐指数
1
解决办法
5214
查看次数

如何根据 Spring Boot 和 Spring doc 中的配置文件隐藏端点?

我正在研究Spring Boot v2.2.2.RELEASE and SpringDoc UI and Open API Specification OAS3,我在这里发现了非常相关的问题:https ://github.com/springdoc/springdoc-openapi/issues/201 。

我有 4 个配置文件,分别是 Dev、Stage、UAT 和 Prod,并表示我有 Student API、Employee API 和 Department API。

我想要 UAT 和 Prod 配置文件,我想隐藏 Department API。怎能不呢?

springdoc springdoc-ui springdoc-openapi-ui

2
推荐指数
1
解决办法
3334
查看次数

WebFlux Swagger(开放 API)集成 - 发布请求示例

我已使用 RouterOperation 将 Swagger (OpenAPI) 与 Spring Webflux 集成,如下所述: https: //springdoc.org/#spring-weblfuxwebmvcfn-with-function-endpoints。集成工作正常,可通过 /swagger-ui.html 访问

但是,对于 POST API,当我单击“试用”按钮时,我没有看到“请求”示例。我的 Post API 接受 Json 作为请求正文。

我该如何配置这个?可以通过注释和 RouterOperation 或其他方式来完成吗?

编辑:下面是我的 Router 类代码:

@Configuration
public class  MyRouter {

    @RouterOperations({
            @RouterOperation(path = "/data", beanClass = MyHandler.class, beanMethod = "getData"),
            @RouterOperation(path = "/allData", beanClass = MyHandler.class, beanMethod = "getAllData") })

    @Bean
    public RouterFunction<ServerResponse> route(MyHandler MyHandler) {

        return RouterFunctions
                .route(RequestPredicates.POST("/data").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), MyHandler::getData)
                .andRoute(RequestPredicates.GET("/allData").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), MyHandler::getAllData);
    }
}
Run Code Online (Sandbox Code Playgroud)

添加 RouterOperations 注释后,我可以看到 swagger-ui 正确显示 GET 和 POST API,但没有显示请求架构示例。

我还遇到了 yaml / json …

java swagger-ui openapi spring-webflux springdoc-openapi-ui

2
推荐指数
1
解决办法
2961
查看次数

Springdoc 中自动生成基于 Swagger 注解的描述

基本上我的问题与此相同,但针对 Springdoc (而不是 Springfox)。

简而言之,我有一个 Spring-boot 应用程序,并且我正在使用 spring-security @PreAuthorize 注释来保护我的一些 api,目前hasAuthority仅基于。

有没有办法可以根据注解自动修改具体的资源swagger描述?我想这与重写 Springdoc 的默认类行为之一有关(也许OpenAPICustomiser?),但我不确定如何做到这一点。

java swagger swagger-ui springdoc springdoc-openapi-ui

2
推荐指数
1
解决办法
1617
查看次数

带有路径参数和命令对象的 Springdoc-OpenAPI

我在 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 页面似乎工作正常,但这并不那么重要。

java openapi springdoc springdoc-openapi-ui

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

无法在 Spring Boot 3 中使用 Openapi 打开 swagger-ui(Whitelabel 错误页面)

我在 Spring Boot 中通过 Openapi 打开 swagger-ui 时遇到问题。

当我尝试打开此 URL http://localhost:8080/swagger-ui.html 时,我收到Whitelabel 错误页面

我该如何解决这个问题?

这是pom.xml中定义的依赖项,如下所示。

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

这是如下所示的openpi 配置类

@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI customOpenAPI(@Value("${application-description}") String description,
                                 @Value("${application-version}") String version) {
        return new OpenAPI()
                .info(new Info().title("API")
                        .version(version)
                        .description(description)
                        .license(new License().name("API Licence")));
    }
}
Run Code Online (Sandbox Code Playgroud)

这是如下所示的 application.properties 文件。

springdoc.swagger-ui.path=/swagger-ui.html
application-description=API Description
application-version=1.0

logging.level.org.springframework.web=DEBUG
logging.level.io.springfox=DEBUG
Run Code Online (Sandbox Code Playgroud)

当我尝试打开此 URL 时,出现以下错误http://localhost:8080/swagger-ui.html

2023-02-09T08:36:16.593+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui.html", parameters={}
2023-02-09T08:36:16.594+03:00 …
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
2828
查看次数

openapi springboot - 错误“swaggerWelcome”引发异常

我使用 org.springdoc 的依赖项,请参阅下面的 y spring boot 项目

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

我有这个错误,我可以帮忙吗?

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:759) ~[spring-beans-5.3.23.jar:5.3.23]
    ... 20 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexPageTransformer' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Unsatisfied dependency expressed through method 'indexPageTransformer' parameter 3; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'swaggerWelcome' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springdoc.webmvc.ui.SwaggerWelcomeWebMvc]: Factory method 'swaggerWelcome' threw exception; nested …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot springdoc-openapi-ui

2
推荐指数
1
解决办法
2989
查看次数

OpenApi - 需要一个类型为“org.springdoc.webmvc.ui.SwaggerIndexTransformer”的 bean,但无法找到

我正在使用功能控制器将 Swagger 添加到我的 Spring Webflux 服务中。首先我收到这个错误:

描述:无法注册在类路径资源 [org/springdoc/webflux/ui/SwaggerConfig.class] 中定义的 bean“swaggerWelcome”。具有该名称的 bean 已在类路径资源 [org/springdoc/webmvc/ui/SwaggerConfig.class] 中定义,并且覆盖被禁用。

行动:

考虑重命名其中一个 bean 或通过设置 spring.main.allow-bean-definition-overriding=true 来启用覆盖

所以我将 spring.main.allow-bean-definition-overriding=true 添加到我的 application.properties 文件中。

现在我收到这个错误:

描述:

org.springdoc.webmvc.ui.SwaggerConfig 中方法 swaggerWebMvcConfigurer 的参数 1 需要一个类型为“org.springdoc.webmvc.ui.SwaggerIndexTransformer”的 bean,但无法找到。

行动:

考虑在配置中定义“org.springdoc.webmvc.ui.SwaggerIndexTransformer”类型的 bean。

Pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company/groupId>
    <artifactId>service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!-- For all mvc and web functions -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency> …
Run Code Online (Sandbox Code Playgroud)

api-doc openapi spring-webflux springdoc-openapi-ui

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