Forum Discussion

mona2020's avatar
mona2020
New Contributor
5 years ago

How to pass array of strings in post body?

Hi everyone, I'm trying to get my Swagger UI 3.17.1 POST operation to take a JSON array of strings but am currently getting a runtime error from Symfony/API Platform: "Invalid value provided (invalid IRI?)."  I'd appreciate any help on how to get my configuration working.  Here is my current YAML configuration:

        zooniverse-datasheets:
            method: 'POST'
            path: '/projects/{id}/zooniverse/datasheets'
            controller: 'App\Controller\ZooniverseSendDatasheetsAction'
            # read: false
            swagger_context:
                summary: Send project's datasheet(s) to Zooniverse
                parameters:
                    - in: path
                      name: id
                      required: true
                      type: string
                    - in: body
                      name: datasheets
                      required: false
                      schema:
                          type: array
                          items:
                              type: string
                          example: ["ID1", "ID2", "ID3"]
                      # description: list of datasheet IDs in JSON array format
                responses:
                    '201':
                        description: 'Success'
                    '400':
                        description: 'Invalid input'
                    '404':
                        description: 'Resource not found'

 and here is a screen shot of the operator so far: 

 I'm pretty new to Swagger but have gotten other operators to work but having trouble with this one.  Any help is greatly appreciated!

thanks,

Mona

 

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Mona,

    The OpenAPI definition of your POST request body is correct.

                        - in: body
                          name: datasheets
                          required: false
                          schema:
                              type: array
                              items:
                                  type: string
                              example: ["ID1", "ID2", "ID3"]

    The issue seems to be specific to API Platform. I suggest that you open an issue with that project directly.

  • Hey instead of passing the data in parameters just try by pass in request body like this

    "requestBody": {
    "description": " User Post Object",
    "required": true,
    "content": {
    "application/json": {
    "schema": {
    "type": "object",
    "properties": {
    "ID": {
    "type": "string",
    "format": "string"
    }
    }
    }
    }
    },
    "produces": [
    "application/json"
    ],