question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Submit An Array of Integer Elements In formdata

See original GitHub issue

Swagger sends the field location (array) as a single value

formdataArray

/signup: {
        post: {
          tags: ['Authentication'],

          requestBody: {
            required: true,
            content: {
              'multipart/form-data': {
                schema: {
                  type: 'object',
                  properties: {
                    ...schema.CreateUserBody.properties,
                    location: {
                      type: 'array',
                      items: {
                        type: 'integer'
                      },
                      example: [32.3046505, 30.6080822]
                    },
                    profileImg: {
                      type: 'string',
                      format: 'binary'
                    },
                  },

                }
              }
            }
          },
          responses: {
            201: {
              description: 'User Created',
              content: {
                'application/json': {
                  // schema:{
                  //   $ref: '#/components/schemas/User'
                  // }
                }
              }
            }
          }
        },
      }

i expected that the field(location) will be repeated for each element in the array

how would i make it work this way ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
seanmetrixcommented, Aug 27, 2018

I just ran into this bug as well. My case is with application/x-www-form-urlencoded. I think the issue is related to the requestBody section.

I am attaching an example where explode is set to true in both the parameter block and the requestBody and they behave differently.

The example midway down this page mentions that you can specify the explode param in the encoding block for the requestBody - https://swagger.io/docs/specification/describing-request-body/

I’m using that exact example, except setting explode to true.

0

{
  "openapi" : "3.0.0",
  "info" : {
    "version" : "1.0.0",
    "title" : "Swagger Petstore",
    "license" : {
      "name" : "MIT"
    }
  },
  "servers" : [ {
    "url" : "http://petstore.swagger.io/v1"
  } ],
  "paths" : {
    "/pets" : {
      "post" : {
        "summary" : "Create a pet",
        "operationId" : "createPets",
        "tags" : [ "pets" ],
        "parameters" : [
          {
            "name" : "limit",
            "in" : "query",
            "description" : "How many items to return at one time (max 100)",
            "required" : false,
            "schema" : {
              "type" : "array",
              "items" : {
                "type": "string"
              }
            },
            "style": "form",
            "explode": true
          }
        ],
        "requestBody" : {
          "content" : {
            "application/x-www-form-urlencoded" : {
              "schema" : {  
                "type" : "object",
                "properties" : {
                  "color" : {
                    "type" : "array",
                    "items" : {
                      "type" : "string"
                    }
                  }
                }
              },
              "encoding" : {
                "color" : {
                  "style" : "form",
                  "explode" : true
                }
              }
            }
          }
        },
        "responses" : {
          "201" : {
            "description" : "Null response"
          }
        }
      }
    }
  }
}
1reaction
hkosovacommented, Jul 3, 2020

@Crackz the next version of the spec, OpenAPI 3.1, will support exploded arrays in multipart/form-data requests, and this is the default serialization style for arrays in form data (i.e. style: form + explode: true).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I append an array to 'formdata' in javascript?
I am attempting to upload an arbitrary number of files, with AJAX, which the user specifies with standard form input elements. The server-side...
Read more >
Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >
FormData append javascript array (JSON.stringify ... - Laracasts
I'm using Vue/ inertia, to submit a javascript array to be stored as JSON in ... For FormData.append() to work with an array,...
Read more >
Send Array as Part of x-www-form-urlencoded Using Postman
How to send array data using x-www-form-urlencoded via Postman. ... It sends an encoded form data set for submission to the server.
Read more >
JavaScript FormData
JavaScript FormData · const formData = new FormData(form); · const btn = document.querySelector('#submit'); const form = document.querySelector('#subscription'); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found