Search code examples
spring-bootspringdoc-openapi-uispringdoc-openui

Springdoc openapi migration from springfox


I am working on the migration of swagger spring fox to spring doc open api. I followed below link. https://deepak-shinde.medium.com/migrating-from-springfox-swagger-2-to-springdoc-openapi-3-79a79757b8d1

Below version used.

spring_boot_version=    "2.5.5"
springdoc_openapi_version=  "1.6.0"

In gradle dependency mentioned as below

implementation "org.springdoc:springdoc-openapi-ui:$springdoc_openapi_version"
implementation "org.springdoc:springdoc-openapi-javadoc:$springdoc_openapi_version"

I defined rest controller.

@RestController
@RequestMapping("/v1")
@Slf4j
@Tag(name = "Master",  description = "Master service API")
public class MasterController {

   @Operation(summary = "Get test data",security = {
        @SecurityRequirement(name = MasterConstant.HTTP_AUTH_SECURITY_SCHEME) },   tags = { 
        "Master" } ,description = " This method is used to get test data")
   @PostMapping("/codes")
   public ResponseEntity<MasterCodeResponse> getTestData()

    }

application.properties

springdoc.swagger-ui.path=swagger-ui
springdoc.packages-to-exclude=com.master.persistence.*
springdoc.packages-to-scan=com.master.controller,com.common.controller // here * by default not working as its not listing apis
springdoc.api-docs.resolve-schema-properties=false

When i invoke v3/apidocs - Tags is coming empty. No controller name or description is displayed.

"openapi":"3.0.1",
   "info":{
      "title":"Test REST API",
      "version":"1.0.0"
   },
   "servers":[
      {
         "url":"http://localhost:8082/master-service/",
         "description":"Generated server url"
      }
   ],
   "security":[
      {
         "bearerAuth":[
            
         ]
      }
   ],
   "tags":[
      {
         
      }
   ],

Same way for operations tags is coming empty.

  "/v1/codes":{
         "post":{
            "tags":[
               null
            ],
            "o

Below bean is defined

@Bean
    public OpenAPI customizeOpenAPI() {
        final String securitySchemeName = "bearerAuth";
        return new OpenAPI().addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
                .components(
                        new Components().addSecuritySchemes(securitySchemeName,
                                new SecurityScheme().name(securitySchemeName).type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer").bearerFormat("JWT")))
                .info(new Info().title("Test REST API").version("1.0.0"));
    }

Please let me know how to get the summary of the opertaion and controller tags in swagger as well as in the apidocs yaml. Please advice if i am doing something wrong here.


Solution

  • There were some issue about tags, as you can see here

    You should try to update springdoc-openapi to at least version 1.6.7.