Skip to content

Encoding is not exploding a array property in requestBody in swagger-ui. #5106

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

Closed
knobik opened this issue Jan 4, 2019 · 4 comments
Closed

Comments

@knobik
Copy link

knobik commented Jan 4, 2019

Q&A (please complete the following information)

  • OS: ubuntu
  • Browser: chrome
  • Version: 71.0.3578.98 (Official Build) (64-bit)
  • Method of installation: composer
  • Swagger-UI version: 3.18.3
  • Swagger/OpenAPI version: OpenApi 3.0

Content & configuration

Swagger/OpenAPI definition:

paths:
  /match/started:
    post:
      tags:
        - match
      summary: 'Callback for when a game has started.'
      operationId: 'App\Http\Controllers\Api\V1\MatchController::started'
      requestBody:
        description: 'Something something batman!'
        required: true
        content:
          multipart/form-data:
            schema:
              required:
                - match_uuid
              properties:
                game_uuid:
                  type: string
                'player_uuids[]':
                  type: array
                  items:
                    type: string
              type: object
            encoding:
              'player_uuids[]':
                style: form
                explode: true
      responses:
        200:
          description: 'success response'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Api_V1_Match_Started'

Swagger-UI configuration options:

const ui = SwaggerUIBundle({
    dom_id: '#swagger-ui',

    url: "http://matchmaking.test/docs/api-docs.json",
    operationsSorter: null,
    configUrl: null,
    validatorUrl: null,
    oauth2RedirectUrl: "http://matchmaking.test/api/oauth2-callback",

    requestInterceptor: function() {
      this.headers['X-CSRF-TOKEN'] = '';
      return this;h
    },

    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],

    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],

    layout: "StandaloneLayout"
  })

Screenshots

screenshot from 2019-01-04 10-11-56

How can we help?

Encoding is not exploding a array property in requestBody in swagger-ui.
Im getting this command for curl:

curl -X POST "https://editor.swagger.io/api/v1/match/started" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "game_uuid=test" -F "player_uuids[]=aaa,bbb,ccc"

notice this part:
-F "player_uuids=aaa,bbb,ccc"

im trying to get this result
-F "player_uuids[]=aaa" -F "player_uuids[]=bbb" -F "player_uuids[]=ccc"

@paul-lysak
Copy link

Observing same behavior with Swagger UI 3.20.3. Here is our request definition:

  requestBody:
    content:
      multipart/form-data:
        schema:
          type: object
          required:
            - name
          properties:
            param1:
              type: array
              items:
                type: string
        encoding:
          param1:
            style: form
            explode: true

Both the request sent by SwaggerUI to the server and the generated curl command have param1 values comma-separated in the same parameter rather then sending them in multiple parameters with the same name.

@hkosova
Copy link
Contributor

hkosova commented Jan 11, 2019

OpenAPI 3.0 does not have a way to describe exploded arrays in multipart requests. Please see #4741 for an earlier discussion of this issue.

Exploded arrays location=2112&location=3232 is the default array style for application/x-www-form-urlencoded requests in OAS 3, but it's not clear if exploded arrays can be defined for multipart.

@webron commented on Aug 24, 2018
From reading the spec, I don't see a clear way to define what you're looking for, so I'd suggest filing a ticket with the spec itself. At the moment, there's nothing we can do more to solve this.

To request changes to the OpenAPI Specification you'll need to open an issue here. Once the Specification is updated, tool developers can implement the new behavior.

@paul-lysak
Copy link

Formally correct, but neither does OpenAPI spec says that array property values must be comma-separated. And such behavior is inconsistent with the handling of multiple files upload through multipart requests.

@shockey
Copy link
Contributor

shockey commented Jan 15, 2019

Closing as a duplicate - Parameter.encoding is not currently supported, and is being tracked in #3641 (soon to have its own ticket, but in backlog for now).

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

No branches or pull requests

4 participants