Microprofile4/OpenApi3,如何定义示例请求值?

Microprofile4/OpenApi3, how to define example request value?

在我的设置中,我正在开发一个 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":
      ...

您必须将 mediaType 添加到 Content

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