0

我正在尝试为我的 springboot 应用程序配置 swagger 3 spring 文档。我有 3 个控制器类,每个控制器类有 1 个功能端点方法。如果我打开 swagger 文档,我只能在 Swagger UI 中看到第一个类的端点详细信息。

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
    <type>pom</type>
</dependency>

    <dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-webflux-core</artifactId>
    <version>1.4.6</version>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-webflux-ui</artifactId>
    <version>1.4.6</version>
</dependency>

我的控制器类看起来像这样。

@Configuration
public class CompanyOneClass {
    
    @RouterOperations({ @RouterOperation(path = "/getAllPersons", beanClass = PersonService.class, beanMethod = "getAll"),
      @RouterOperation(path = "/getPerson/{id}", beanClass = PersonService.class, beanMethod = "getById"),
      @RouterOperation(path = "/createPerson", beanClass = PersonService.class, beanMethod = "save"),
      @RouterOperation(path = "/deletePerson/{id}", beanClass = PersonService.class, beanMethod = "delete") })
@Bean
public RouterFunction<ServerResponse> companyOneRoute(CompanyOneHandler companyOneHandler) {
  
   return route().path("/company-one", a1->a1.nest(accept.APPLICATION_JSON),
                                        a2->a2.GET("/getAllPersons",companyOneHandler::findAll)
                                        .GET("/{id}",companyOneHandler::findOne))
                                        .POST("",companyOneHandler::createPerson)
                                        .DELETE("/{id}",companyOneHandler::deletePerson)).build();
  
}
}

@Configuration
public class CompanyTwoClass {
    
    @RouterOperations({ @RouterOperation(path = "/getAllPersons", beanClass = PersonService.class, beanMethod = "getAll"),
      @RouterOperation(path = "/getPerson/{id}", beanClass = PersonService.class, beanMethod = "getById"),
      @RouterOperation(path = "/createPerson", beanClass = PersonService.class, beanMethod = "save"),
      @RouterOperation(path = "/deletePerson/{id}", beanClass = PersonService.class, beanMethod = "delete") })
@Bean
public RouterFunction<ServerResponse> companyTwoRoute(CompanyTwoHandler companyTwoHandler) {
  
   return route().path("/company-two", a1->a1.nest(accept.APPLICATION_JSON),
                                        a2->a2.GET("/getAllPersons",companyTwoHandler::findAll)
                                        .GET("/{id}",companyTwoHandler::findOne))
                                        .POST("",companyTwoHandler::createPerson)
                                        .DELETE("/{id}",companyTwoHandler::deletePerson)).build();
  
}
}

@Configuration
public class CompanyThreeClass {
    
    @RouterOperations({ @RouterOperation(path = "/getAllPersons", beanClass = PersonService.class, beanMethod = "getAll"),
      @RouterOperation(path = "/getPerson/{id}", beanClass = PersonService.class, beanMethod = "getById"),
      @RouterOperation(path = "/createPerson", beanClass = PersonService.class, beanMethod = "save"),
      @RouterOperation(path = "/deletePerson/{id}", beanClass = PersonService.class, beanMethod = "delete") })
@Bean
public RouterFunction<ServerResponse> companyThreeRoute(CompanyThreeHandler companyThreeHandler) {
     return route().path("/company-three", a1->a1.nest(accept.APPLICATION_JSON),
                                        a2->a2.GET("/getAllPersons",companyThreeHandler::findAll)
                                        .GET("/{id}",companyThreeHandler::findOne))
                                        .POST("",companyThreeHandler::createPerson)
                                        .DELETE("/{id}",companyThreeHandler::deletePerson)).build();
}
}

唯一的相似之处是所有这 3 个控制器都具有相似的端点 URL,但路由到不同的处理程序。仅供参考,我使用 java 11。

4

0 回答 0