我有一个配置我的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
如何正确调整我的配置?
提前感谢!
1条答案
按热度按时间dxxyhpgq1#
对于路径参数和基本参数(即数字/字符串/布尔值),通常不需要将
schema
封装到content
中。@Content
注解通常只用于请求主体和响应。替换
与