Swagger/OpenAPI联机验证程序验证架构失败

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

我有一个配置我的Swagger模式,/api-docs -〉openapi 3.0.1:

@Configuration
    public class SwaggerConfig {
        @Bean
        public OpenAPI customOpenAPI() {
            return new OpenAPI()
                    .components(new Components().addSecuritySchemes("Bearer",
                            new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("Bearer")
                                    .in(SecurityScheme.In.HEADER).name("Authorization")))
                    .info(new Info().title("SSM API").version("0.1"));
        }
    }

控制器示例:

@Tag(name = "MetalBalance", description = "Контроллер баланса металла")
@RestController
@RequestMapping(path = "/metal-balance", produces = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirement(name = "Bearer")
@ResponseBody
@RequiredArgsConstructor
public class MetalBalanceController {
...
    @DeleteMapping("/operations/{id}")
    @Operation(summary = "Удаление операции над агрегатом")
    @Parameters(value = {
            @Parameter(in = ParameterIn.PATH, name = "id", example = "720050516121420278143",
                    description = "Идентификатор операции",
                    content = @Content(schema = @Schema(type = "integer"))),
    })
    @RolesAllowed({"MASTER_SHIHTA", "NACH_SMEN_VZKKC1", "MASTER_KONV", "FERRO_R6", "NACH_SMEN_VZKKC1", "FERRO_R", "DESIGNER",
            "KONV_R", "LAB_ST_PR", "NACH_SMEN_VZKKC1", "NACH_UPPVS", "ING_CEN_CEH", "RAB_UPK", "UPK_R",
            "MASTER_VAK", "VAK_R", "R_VAKUUMAT", "MASTER_UDM", "UDM_R"})
    public void deleteOperation(@PathVariable("id") BigInteger operationId) {
        balanceService.deleteUnitOperation(operationId);
    }
}

openapi响应,我从“/api-docs”端点得到的内容:

"/metal-balance/operations/{id}": {
"delete": {
"tags": [
"MetalBalance"
],
"summary": "Удаление операции над агрегатом",
"operationId": "deleteOperation",
"parameters": [
{
"name": "id",
"in": "path",
"description": "Идентификатор операции",
"required": true,
"example": 720050516121420300000,
"content": {
"*/*": {
"schema": {
"type": "integer"
}}}}],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request",
"content": {
"*/*": {
"schema": {
"type": "object"
}}}}},
"security": [
{
"Bearer": []}
 ]}}

当我尝试通过Swagger/OpenAPI在线验证器验证它时,我收到了异常,附件:Validation Error
如何正确调整我的配置?
提前感谢!

dxxyhpgq

dxxyhpgq1#

对于路径参数和基本参数(即数字/字符串/布尔值),通常不需要将schema封装到content中。@Content注解通常只用于请求主体和响应。
替换

@Parameter(in = ParameterIn.PATH, name = "id", example = "720050516121420278143",
                    description = "Идентификатор операции",
                    content = @Content(schema = @Schema(type = "integer"))),

@Parameter(in = ParameterIn.PATH, name = "id", example = "720050516121420278143",
                    description = "Идентификатор операции",
                    schema = @Schema(type = "integer")),  // <----------

相关问题