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]

I am sending a single dataInfo in request and getting single dataInfoStatus in response, but I will like to send and array of dataInfo and get an array of dataInfo status.

I tried following:

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

but I get

Parser error bad indentation of a mapping entry

for items. I am following this.

How can I achieve sending dataInfo in request as an array of dataInfo and getting in response an array of dataInfoStatus?

James Z
  • 12,209
  • 10
  • 24
  • 44
Maazen
  • 107
  • 1
  • 14

1 Answers1

2

You have to add one more space between type: and array, then the error message is gone:

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

And you can add the info.version for the version of the openapi file.

flaxel
  • 4,173
  • 4
  • 17
  • 30
  • Thanks that resolved the error :) . "And you can add the info.version for the version of the openapi file" , could not follow this ? ( I have mentioned the version openapi: "3.0.0" above, if that is what you meant . – Maazen Aug 31 '20 at 19:38
  • If I used the [editor](https://editor.swagger.io/) I get a error `missing property` because I do not set the [version of the file](https://swagger.io/specification/#info-object). – flaxel Aug 31 '20 at 19:43