【问题标题】:No operations defined in spec! with spring boot规范中没有定义操作!带弹簧靴
【发布时间】:2022-11-01 23:01:41
【问题描述】:

我没有在规范中定义任何操作!在 Spring Boot 中加载 swagger-ui 时

以下是代码详细信息:

pom.xml
 <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.4.8</version>
        </dependency>

On my main file,
   
@OpenAPIDefinition(
        info = @Info(
                title = "RESTAPI",
                //version = "${app.version}",
                description = "svsjsjj ssksj",
                contact = @Contact(
                            name = "bajaj", 
                            url = "https://jhakja.com"
                )
        )
)

@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = { "io.swagger", "io.swagger.api" , "io.swagger.configuration"})
public class Swagger2SpringBoot extends SpringBootServletInitializer implements CommandLineRunner  {

// I have sqlitcode + Date and time code,

    public static void main(String[] args) throws Exception {
     new SpringApplication(Swagger2SpringBoot.class).run(args);
    }

    @Bean
    public Docket customImplementation(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.basePackage("io.swagger.api"))
                    .build();
    }
}

我只是尝试在我的 application.properties 添加如下:

springdoc.paths-to-exclude=/swagger-resources/**      //wanted to exclude swagger-resource
springdoc.packagesToScan=io.swagger.api
springdoc.pathsToMatch=restapi/v2,restapi/v2/*

我有许多具有以下形式的控制器,因为项目是从 swagger.io 生成的 -> 导出为 spring 项目 -> 在 IDE 上导入相同

  1. 界面 :

    @Validated
    @Api(value = "alert", description = "the alert API")
    @RequestMapping(value = "/v2")
    public interface AlertApi {
    
     @ApiOperation(value = "Finds all alerts", nickname = "findAllAlerts", notes = "Provides list of all alerts", responseContainer = "List", authorizations = {
         @Authorization(value = "api_key"),
         @Authorization(value = "settings_auth", scopes = {
             @AuthorizationScope(scope = "write:settings", description = "modify settings in your system"),
             @AuthorizationScope(scope = "read:settings", description = "read your settings")
             })
     }, tags={ "alert", })
     @ApiResponses(value = { 
         @ApiResponse(code = 200, message = "successful operation", responseContainer = "List"),
         @ApiResponse(code = 400, message = "Invalid status value") })
     @RequestMapping(value = "/alert/history",
         produces = {"application/json" },
         method = RequestMethod.GET)
     ResponseEntity<Object>  findAllAlerts();
    
     }
    
  2. 类文件:

      @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2021-10-12T11:46:11.648Z")
    
      @Controller
      public class AlertApiController implements AlertApi {
    
     public ResponseEntity<Object> findAllAlerts() {
      // processing 
    
     }
     }
    

    我还尝试创建单个类文件而不是接口然后类,但这没有用。

    @Tag(name = "PingController", description = "This is responsible for give the status of application")
    @RestController
    @RequestMapping(restapi/v2)
    public class PingController {
    
    
        @Operation(summary = "End-point to test ping")
        @GetMapping("/v2/ping")
        public ResponseEntity<String> getMessages() {
        //other code    
        }
    }
    

    我也有与 jwt 相关的代码,但移到了不同​​的包中。

    无法加载控制器。在这方面需要帮助。

    swagger ui displayed

    提前致谢!

【问题讨论】:

    标签: java spring-boot swagger


    【解决方案1】:

    问题似乎是application.properties 中springdoc.pathsToMatch 属性的值。

    尝试在您的 application.properties 中注释掉 springdoc.pathsToMatch=restapi/v2,restapi/v2/* 并查看是否可以解决问题。如果是,则将该值调整为类似于springdoc.pathsToMatch=restapi/v2/** 的值。

    【讨论】:

      猜你喜欢
      • 2022-07-18
      • 2018-02-14
      • 1970-01-01
      • 2014-06-27
      • 2021-07-15
      • 2021-02-16
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多