首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Microprofile4/OpenApi3 3,如何定义示例请求值?

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

Stack Overflow用户
提问于 2021-07-08 10:17:30
回答 1查看 151关注 0票数 0

在我的设置中,我正在开发一个Microprofile4 (Quarkus2) Java应用程序。这和OpenApi3一起来的。

在此应用程序中,我希望为POST请求参数定义一个示例。

代码语言:javascript
运行
复制
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规范中,但示例值没有:

代码语言:javascript
运行
复制
/merge-intervals
post:
  requestBody:
    description: Test description
    content:
      application/json:
        schema:
          type: array
          items:
            $ref: '#/components/schemas/IntegerInterval'
  responses:
    "200":
      ...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-08 12:41:01

您必须向内容中添加一个mediaType。

代码语言:javascript
运行
复制
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规范:

代码语言:javascript
运行
复制
/merge-intervals
post:
requestBody:
  description: Test description
  content:
    application/json:
      schema:
        type: array
        items:
          $ref: '#/components/schemas/IntegerInterval'
      example:
      - start: 0
        end: 1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68299731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档