0

I am trying to create Swagger documentation using OpenAPI 3.0. I am using spring-boot-starter 1.5.4.RELEASE and springdoc-openapi-ui version 1.4.2

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
</parent>

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.4.2</version>
</dependency>

My code is as follows:

@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "test", version = "2.0", description = "sample description3"))
public class SwaggerSpringDemoApplication {


    public static void main(String[] args) {
        SpringApplication.run(SwaggerSpringDemoApplication.class, args);
    }
}

@RestController
@RequestMapping("/")
public class PersonController {

    @RequestMapping(value = "/{operationType}/{listName}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED)
    @CrossOrigin
    public String rollingUpgrade( @PathVariable String operationType, @PathVariable String listName,
                                @RequestParam(value = "rowData") String rowData) throws Exception {
        ..........
        return "";
    }
}

When I run the application, I get the following error:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri May 13 09:58:38 IST 2022
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported

But the issue is resolved if I form the url like value = "test/{operationType}/{listName}"

I dont know what is the exact reason for this.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Can you share a `curl` call to your endpoint? – devang May 13 '22 at 04:58
  • When I executed the curl command, I dont get anything [root@oms1 log]# curl 'https://192.100.100.120:18080/oms-service/webapi/swagger-ui.html' -k [root@oms1 log]# – Suswan Mondal May 13 '22 at 06:37
  • It's a `POST` operation. Your `curl` should include `-X POST -H 'Content-Type: application/x-www-form-urlencoded`. Add `-v` to get verbose curl output. – devang May 13 '22 at 16:43
  • I tried using POST. got the following exception "status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/oms-service/webapi/swagger-ui.html"}* Connection #1 to host localhost left intact – Suswan Mondal May 16 '22 at 05:28

1 Answers1

0

Try this annotation above controller method:

@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content)

See Swagger UI not setting content-type on try it out

Grigory Kislin
  • 16,647
  • 10
  • 125
  • 197