规范中没有定义任何操作!带弹簧靴

Sav*_*nil 7 java swagger spring-boot

我收到规范中没有定义的操作!在 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();
    }
}
Run Code Online (Sandbox Code Playgroud)

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

springdoc.paths-to-exclude=/swagger-resources/**      //wanted to exclude swagger-resource
springdoc.packagesToScan=io.swagger.api
springdoc.pathsToMatch=restapi/v2,restapi/v2/*
Run Code Online (Sandbox Code Playgroud)

我有许多具有以下形式的控制器,因为项目是从 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();
    
     }
    
    Run Code Online (Sandbox Code Playgroud)
  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 
    
     }
     }
    
    Run Code Online (Sandbox Code Playgroud)

我还尝试创建一个类文件而不是接口,然后创建类,但这不起作用。

@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    
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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

显示 swagger ui

提前致谢!

小智 1

问题似乎出在 application.properties 中的属性值springdoc.pathsToMatch

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