1

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?

4
  • Please clarify what you mean by "not being sent properly". What result do you expect and what actually happens? Commented Sep 8, 2021 at 22:41
  • The array angle brackets are being removed. That is, this "{},{}" is being sent instead of this "[{},{}]" Commented Sep 10, 2021 at 6:01
  • here is the result image Commented Sep 10, 2021 at 6:21
  • It's a bug in Swagger UI. Commented Sep 10, 2021 at 7:45

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.