Skip to content

Input fields for arrays of references in request body #4975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
IonelLupu opened this issue Oct 29, 2018 · 4 comments
Open

Input fields for arrays of references in request body #4975

IonelLupu opened this issue Oct 29, 2018 · 4 comments

Comments

@IonelLupu
Copy link

Q&A (please complete the following information)

  • OS: Ubuntu
  • Browser: chrome
  • Version: 69
  • Method of installation: composer
  • Swagger-UI version: 3.0
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Swagger/OpenAPI definition:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Hotels
paths:
  /hotel:
    post:
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                name:
                  type: string
                images:
                  type: array
                  items:
                    type: string
                    format: binary
                rooms:
                  type: array
                  items:
                    $ref: '#/components/schemas/Room'
      responses:
        '200':
          description: response
          content:
            application/json:
              schema:
                type: string
components:
  schemas:
    Room:
      type: object
      properties:
        name:
          type: string
        image:
          type: string
          format: binary

Swagger-UI configuration options:

SwaggerUI({
  // Auto-configured through bundle
})

Screenshots

image

How can we help?

As you can see in the image there are input fields for the images parameter but not for the rooms parameters. These are in JSON format.
It is possible to have input fields for each element in the arrays? Also, I seems the data is not sent in the proper format. I want to send to the server a request in this format(from Chrome Header/Form Data):

------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="name"

Hotel 1
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[0][name]"

First room
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[0][image]"; filename="img1.jpg"
Content-Type: application/octet-stream

<image data here>
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[1][name]"

Second  room
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[1][image]"; filename="img2.jpg"
Content-Type: application/octet-stream

<image data here>
------WebKitFormBoundarynP2Wq5aK1GFB5j8h--

But Swagger is sending it in this format:

------WebKitFormBoundaryB71611XhkBfcjbca
Content-Disposition: form-data; name="name"

Hotel 1
------WebKitFormBoundaryB71611XhkBfcjbca
Content-Disposition: form-data; name="rooms"

{
  "name": "string",
  "image": "string"
},{
  "name": "string",
  "image": "string"
}
------WebKitFormBoundaryB71611XhkBfcjbca--
@IonelLupu IonelLupu changed the title Input fields for arrays of references for parameters Input fields for arrays of references in request body Oct 29, 2018
@hkosova
Copy link
Contributor

hkosova commented Jul 3, 2020

I want to send to the server a request in this format(from Chrome Header/Form Data):

------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="name"

Hotel 1
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[0][name]"

First room
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[0][image]"; filename="img1.jpg"
Content-Type: application/octet-stream

<image data here>
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[1][name]"

Second  room
------WebKitFormBoundarynP2Wq5aK1GFB5j8h
Content-Disposition: form-data; name="rooms[1][image]"; filename="img2.jpg"
Content-Type: application/octet-stream

<image data here>
------WebKitFormBoundarynP2Wq5aK1GFB5j8h--

OpenAPI Specification does not provide a way to define such requests.

Field names like rooms[1][name] resemble the deepObject serialization style, which can be applied to multipart/* form fields in the next version of the spec, OpenAPI 3.1. However, deepObject behavior is defined only for simple non-nested objects, but not for arrays and not for nested objects.The rooms field in your example is an array (array of Room), so it's not covered by what deepObject currently supports.

This is a limitation of the OpenAPI Specification, not Swagger UI.

@hkosova
Copy link
Contributor

hkosova commented Jul 3, 2020

As for the first question

It is possible to have input fields for each element in the arrays?

see #2771 (comment)

@IonelLupu
Copy link
Author

@hkosova I honestly forgot what was the problem here. It has been almost two years. You can close it if you think the issues is fixed

@nsourov
Copy link

nsourov commented Sep 16, 2021

The issue is not fixed yet. multipart/form-data still cannot render a nested form for an array of objects. Only works with an array of strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants