首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Swagger Open API 3.0.1:如何为响应示例定义对象数组

Swagger Open API 3.0.1:如何为响应示例定义对象数组
EN

Stack Overflow用户
提问于 2021-06-17 12:19:33
回答 1查看 56关注 0票数 1

使用Open API 3.0.1定义API规范的swagger定义。但是,这里定义的响应示例GoodResponse不会被呈现。不过,语法似乎是有效的。如果有人指出我做错了什么,我将不胜感激

代码语言:javascript
运行
复制
paths:
  /java/api/play:
    post:
      tags:
        - some-controller
      operationId: someOperation
      requestBody:
        content:
          application/xml:
            schema:
              $ref: '#/components/schemas/HarryKartType'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                items:
                  $ref: '#/components/schemas/GoodResponse'
components:
  schemas:
    GoodResponse:
      required:
        - goodstatusCode
        - goodresponseMessage
      type: object
      properties:
        goodstatusCode:
          type: integer
          example: 200
        goodresponseMessage:
          type: array
          example:
            - position: 1
              horseName: "TIMETOBELUCKY"
            - position: 2
              horseName: "HERCULES BOKO"
            - position: 3
              horseName: "CARGO DOOR"
          items:
             $ref: '#/components/schemas/GoodResponseMessage'
             
    GoodResponseMessage:
      type: object
      properties:
        position:
                type: integer
                example: 1
        horseName:
                type: string
                example: "TIMETOBELUCKY"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-17 18:19:02

您需要在schema中定义$ref,而不是在items中尝试以下命令:

代码语言:javascript
运行
复制
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GoodResponse'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68012877

复制
相关文章

相似问题

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