我正在实施一个 Swagger UI 来公开现有的 POST REST API。 Rest API 用于发布人员数据(JSON 对象)以及相关文件
这里是来自 Rest Controller 的 Post 方法:
@Operation(summary = "Upload a document for a person")
@PostMapping(value = "/personEndpoint/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Object> savePerson(@RequestPart PersonDTO person, @RequestPart MultipartFile document) throws JsonMappingException, JsonProcessingException {
String personId = personService.storePersonData(person, document);
if (null != personId) {
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("{\"personId\": \"" + personId + "\"}");
return ResponseEntity.ok(json);
} else {
return ResponseEntity.badRequest().body("Error occurred while processing the request");
}
}
如果我将人员内容类型明确定义为 application/json,则该帖子与 Postman 一起工作正常
但是,使用 Swagger Ui,我收到 http 415 错误(不支持的媒体类型)(如下图所示)
我正在使用 Springboot 3.0.2 和 springdoc-openapi-starter-webmvc-ui 2.1.0 for swagger UI
这是我的 Swagger 配置:
@Configuration
@OpenAPIDefinition(info = @Info(title = "Person REST Service", version = "1.0.0", description = "Person managment Services"))
public class SwaggerConfig {
}
我是否需要特定配置才能使此端点在 Swagger UI 上运行?
注意:我不想在端点中将人 JSON 定义为字符串,因为我希望它在 SwaggerUi 上显示为文本区域
请问我需要哪种配置才能使此端点在 Swagger UI 上运行?
非常感谢
请为
@RequestParam
打上
Person object
你可以看到 curl on swagger show
person
as File。 -F