在我的设置中,我正在开发一个Microprofile4 (Quarkus2) Java应用程序。这和OpenApi3一起来的。
在此应用程序中,我希望为POST请求参数定义一个示例。
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
...
// IntegerInterval is a simple data class,
// having to int properties "start" and "end".
public List<IntegerInterval> returnIntervals(
@RequestBody(description = "Test description",
content = {@Content(example = "[{\"start\":0,\"end\":1}")})
List<IntegerInterval> intervals) {
return intervals;
}
虽然“测试描述”显示在OpenApi规范中,但示例值没有:
/merge-intervals
post:
requestBody:
description: Test description
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/IntegerInterval'
responses:
"200":
...
发布于 2021-07-08 12:41:01
您必须向内容中添加一个mediaType。
public List<IntegerInterval> returnIntervals(
@RequestBody(description = "Test description",
mediaType = javax.ws.rs.core.MediaType.APPLICATION_JSON,
content = {@Content(example = "[{\"start\":0,\"end\":1}]")})
List<IntegerInterval> intervals) {
OpenAPI规范:
/merge-intervals
post:
requestBody:
description: Test description
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/IntegerInterval'
example:
- start: 0
end: 1
https://stackoverflow.com/questions/68299731
复制相似问题