昂首阔步的发送和接收数组

时间:2020-08-31 18:31:40

标签: swagger swagger-3.0

openapi: "3.0.0" 
info:   
  title: project 
servers:
- url: http://example1.net/v3
- url: http://example/v3

paths:

  /Pn/{PnId}/service1:
    post:
      summary: Pn data
      description: |
        can Pn the data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/dataInfo"
          application/x-www-form-urlencoded:
            schema:
              $ref: "#/components/schemas/dataInfo"
      parameters:
      - name: PnId
        in: path
        description: PnId
        required: true
        schema:
          $ref: "#/components/schemas/Pn"
      responses:
        '200':
          description: status
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/dataInfoStatus"
              example: infoable
        default:
          description: error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

components:   
  schemas:
    Error:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
      required:
      - message
    Pn:
      type: integer
      format: int64
    dataInfo:
      type: string
    dataInfoStatus:
      type: string
      enum: [infoable, non_infoable,ignorable]

我在请求中发送单个dataInfo并在响应中获取单个dataInfoStatus,但是我想发送dataInfo和array并获取dataInfo状态的数组。

我尝试了以下操作:

schema:
  type:array
  items:
    $ref: "#/components/schemas/dataInfo"

但我知道

解析器错误映射条目缩进

项。我正在关注this

如何在请求中以dataInfo数组形式发送dataInfo并以dataInfoStatus数组作为响应?

1 个答案:

答案 0 :(得分:2)

您必须在type:array之间再添加一个空格,然后错误消息消失了:

schema:
    type: array
    items:
        $ref: "#/components/schemas/dataInfo"

您可以为version of the openapi file添加info.version