Opeyemi
Opeyemi

Reputation: 121

How to send a JSON array in multipart/form-data in Swagger UI?

I’m trying to send an array of objects through multipart/form-data:

post:
      summary: Creates a user
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties: # Request parts
                id:
                  type: string
                  format: uuid
                address:      # <---------
                  type: array
                  items:
                    type: object
                    properties:
                      street:
                        type: string
                      city:
                        type: string
                profileImage:
                  type: string
                  format: base64

But Swagger UI sends the address array incorrectly - as {},{} instead of [{},{}], that is, without the enclosing square brackets:

I even tried encoding it separately as JSON.

What am I missing, please?

Upvotes: 1

Views: 3567

Answers (1)

Opeyemi
Opeyemi

Reputation: 121

i later got it to work by adding example

post:
      summary: Creates a user
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties: # Request parts
                id:
                  type: string
                  format: uuid
                address:
                  type: array
                  items:
                    type: object
                    properties:
                      street:
                        type: string
                      city:
                        type: string
                    example:
                      - street: Jones Street, Manhattan
                        city: New York
                      - street: Hollywood Boulevard
                        city: Los Angeles
                profileImage:
                  type: string
                  format: base64

my observation is just send or modify what you already have in the example, adding new ones won't be correctly formatted. that is, if you have two items in an array work with those two do not add extra items

Upvotes: 3

Related Questions