'Getting 405 error in OpenAPI swagger page if I put only path variable attributes in a Rest Controller

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source