【发布时间】:2022-12-21 21:56:32
【问题描述】:
我使用使用表单数据的 openapi 3.0 生成了端点。不知道我做错了什么,因为它全部生成并且在过去我已经能够上传这样的文件。不同的是,现在我除了文件之外还有多个字段。
paths:
/movie:
post:
operationId: createMovie
description: creates movie
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/MovieRequest'
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/Movie'
电影请求组件:
MovieRequest:
type: object
properties:
title:
type: string
description:
type: string
director:
type: string
length:
type: integer
format: int64
category:
$ref: '#/components/schemas/Category'
ageCategory:
$ref: '#/components/schemas/AgeCategory'
poster:
type: string
format: binary
trailerLink:
type: string
shortDescription:
type: string
生成的控制器:
@ApiOperation(value = "", nickname = "createMovie", notes = "creates movie", response = MovieModelApi.class, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "", response = MovieModelApi.class) })
@RequestMapping(
method = RequestMethod.POST,
value = "/movie",
produces = { "application/json" },
consumes = { "multipart/form-data" }
)
default ResponseEntity<MovieModelApi> createMovie(@ApiParam(value = "") @Valid @RequestPart(value = "title", required = false) String title,@ApiParam(value = "") @Valid @RequestPart(value = "description", required = false) String description,@ApiParam(value = "") @Valid @RequestPart(value = "director", required = false) String director,@ApiParam(value = "", allowableValues = "HORROR") @Valid @RequestPart(value = "category", required = false) CategoryModelApi category,@ApiParam(value = "", allowableValues = "PG13") @Valid @RequestPart(value = "ageCategory", required = false) AgeCategoryModelApi ageCategory,@ApiParam(value = "") @Valid @RequestPart(value = "poster", required = false) MultipartFile poster) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"director\" : \"director\", \"isEnabled\" : true, \"description\" : \"description\", \"id\" : 5, \"title\" : \"title\", \"poster\" : \"poster\" }";
ApiUtil.setExampleResponse(request, "application/json", exampleString);
break;
}
}
});
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
但是我收到 415 unsupported media 错误
【问题讨论】:
标签: spring spring-boot rest postman openapi