Forum Discussion

gokulak's avatar
gokulak
New Contributor
4 years ago

Generated swagger.json does not contain @PostMapping API's, it contains only @GetMapping API's

Dear All,

I am new to swagger.

I have implemented swagger2 for springboot microservice and I am able to generate swagger.json file 

but

the swagger.json file does not contain api's which are @PostMapping

the generated swagger.json file contains only @GetMapping API's

 

please give me pointer what I am missing.

 

Below are my swagger implementation details 

1) Controller Class

@ComponentScan("com.mysite")
@RestController
@RequestMapping("/myservice")
public class UserRestController {

@PostMapping("/user/{user_id}/action")
public ResponseEntity<UserActionAPIResponse> invokeUserActionsServiceAll(...) {
...
}


}

 

2) pom.xml

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>

 

3)

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.mysite.user.controller"))
.paths(regex("/.*"))
.build();
}

}

 

Please help !!!

Thank you in advance,

Gokula

 

  • Issue got resolved after upgrading spring-core 

  • gokulak's avatar
    gokulak
    New Contributor

    Here is the error log

     

    2021-06-16 06:52:18,826 ERROR [26991] Skipping process path[/myservice/user/{user_id}/action], method[invokeUserActionsServiceAll] as it has an error. java.lang.NoSuchMethodError: org.springframework.http.MediaType.equalsTypeAndSubtype(Lorg/springframework/util/MimeType;)Z at springfox.documentation.builders.BodyParameterSpecificationProvider.lambda$create$0(BodyParameterSpecificationProvider.java:37) ~[springfox-core-3.0.0.jar:3.0.0] at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) ~[?:1.8.0_292] at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1556) ~[?:1.8.0_292] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[?:1.8.0_292] at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[?:1.8.0_292] at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:1.8.0_292] at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:1.8.0_292] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_292] at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) ~[?:1.8.0_292] at springfox.documentation.builders.BodyParameterSpecificationProvider.create(BodyParameterSpecificationProvider.java:38) ~[springfox-core-3.0.0.jar:3.0.0] at springfox.documentation.builders.RootParameterSpecificationProvider.create(RootParameterSpecificationProvider.java:30) ~[springfox-core-3.0.0.jar:3.0.0] at springfox.documentation.builders.RequestParameterBuilder.build(RequestParameterBuilder.java:160) ~[springfox-core-3.0.0.jar:3.0.0] at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.parameter(DocumentationPluginsManager.java:121) ~[springfox-spring-web-3.0.0.jar:3.0.0] at springfox.documentation.spring.web.readers.operation.OperationParameterReader.readParameters(OperationParameterReader.java:126) ~[springfox-spring-web-3.0.0.jar:3.0.0] at springfox.documentation.spring.web.readers.operation.OperationParameterReader.apply(OperationParameterReader.java:81) ~[springfox-spring-web-3.0.0.jar:3.0.0] at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.operation(DocumentationPluginsManager.java:144) ~[springfox-spring-web-3.0.0.jar:3.0.0] at springfox.documentation.spring.web.readers.operation.ApiOperationReader.read(ApiOperationReader.java:72) ~[springfox-spring-web-3.0.0.jar:3.0.0] at springfox.documentation.spring.web.scanners.CachingOperationReader.lambda$new$0(CachingOperationReader.java:43) ~[springfox-spring-web-3.0.0.jar:3.0.0]

    • gokulak's avatar
      gokulak
      New Contributor

      Issue got resolved after upgrading spring-core 

      • anilkp's avatar
        anilkp
        New Member

        Hi,

         

        I am also facing the same error, the swagger documentation doesn't contain @PostMapping API's endpoints.

         

        http://localhost:8080/uwc/swagger-ui/index.html

         

        Here is my pom dependency.

         

        <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
        </dependency>

         

        I also have the error on sever startup,

         

        [main] ERROR springfox.documentation.spring.web.scanners.ApiDescriptionReader - Skipping process path[/demo/sendDetails], method[sendDetails] as it has an error.
        java.lang.NoSuchMethodError: io.swagger.annotations.ApiParam.type()Ljava/lang/String;
        at springfox.documentation.swagger.readers.parameter.ApiParamParameterBuilder.apply(ApiParamParameterBuilder.java:90)
        at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.parameter(DocumentationPluginsManager.java:117)
        at springfox.documentation.spring.web.readers.operation.OperationParameterReader.readParameters(OperationParameterReader.java:126)
        at springfox.documentation.spring.web.readers.operation.OperationParameterReader.apply(OperationParameterReader.java:81)
        at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.operation(DocumentationPluginsManager.java:144)
        at springfox.documentation.spring.web.readers.operation.ApiOperationReader.read(ApiOperationReader.java:72)
        at springfox.documentation.spring.web.scanners.CachingOperationReader.lambda$new$0(CachingOperationReader.java:43)
        at java.util.HashMap.computeIfAbsent(HashMap.java:1127)
        at springfox.documentation.spring.web.scanners.CachingOperationReader.read(CachingOperationReader.java:48)
        at springfox.documentation.spring.web.scanners.ApiDescriptionReader.read(ApiDescriptionReader.java:72)
        at springfox.documentation.spring.web.scanners.ApiListingScanner.scan(ApiListingScanner.java:169)
        at springfox.documentation.spring.web.scanners.ApiDocumentationScanner.scan(ApiDocumentationScanner.java:67)

         

        gokulak , can you please let me know to which spring-core version have you upgraded to?