Skip to content

Optional array query params are always sent when example is specified #4223

@theaeolianmachine

Description

@theaeolianmachine
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3.0
Which Swagger-UI version? 3.X
How did you install Swagger-UI? editor.swagger.io
Which browser & version? Google Chrome 64
Which operating system? macOS Sierra

Demonstration API definition

openapi: '3.0.0'
info:
  description: >-
    Repro API
  title: Repro API
  version: '1.0'
paths:
  /test:
    get:
      summary: Test get
      parameters:
        - name: fields
          in: query
          required: false
          explode: false
          schema:
            type: array
            items:
              type: string
          style: form
          example:
            - friends
            - family
      responses:
        200:
          description: Success!
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                  name:
                    type: string

Configuration (browser query string, constructor, config.yaml)

No additional configuration, just using editor.swagger.io with no query params

Repro

  • Click on /test, click on Try it out
  • Both examples will be pre-filled in the list of fields for the fields param.
  • Delete both arguments to the fields param, then send a request

Expected Behavior

When I set an example for a query array parameter, I should be able to delete all of the examples and run the request without sending over the param itself, e.g:

curl -X GET "https://editor.swagger.io/test" -H "accept: application/json"

Current Behavior

It still sends over the parameter without any args:
curl -X GET "https://editor.swagger.io/test?fields=" -H "accept: application/json"

Since I have not specified allowEmptyValue to be true, I should expect this parameter not to be sent.

Possible Solution

  • If allowEmptyValue is set to false (by default), the field should not be sent in the request if there are no arguments to the param.
  • If allowEmptyValue is set to true, I should be able to select whether it sends over the request either with the param but without a value, or without the param at all. This is likely dependent on the solution for Can't disable optional query parameter when using allowEmptyValue: true #4122.

Context

Unfortunately this means that I can't use examples in the spec for these arguments (there are two, and they are common to all requests), because sending them over empty completely changes the response of the API. It'd be great to still be able to set the examples!

Thanks so much in advance!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions