如果我在Rest控制器中只放置路径变量属性,则在OpenAPI swagger页面中出现405错误

aij0ehis  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(121)

我正在尝试使用OpenAPI 3.0创建Swagger文档。我使用的是spring-boot-starter****1.5.4.RELEASEspringdoc-openapi-ui版本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>

我的代码如下:

@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 "";
    }
}

运行应用程序时,出现以下错误:

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

但是,如果我形成类似value =“test/{operationType}/{listName}”的url,问题就解决了
我不知道这到底是什么原因。

xwbd5t1u

xwbd5t1u1#

试试上面这个注解控制器的方法:

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

查看Swagger UI,尝试不设置内容类型

相关问题