Skip to content
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

Support for multiple query parameter combinations on a path #706

Closed
gislikonrad opened this issue Jun 1, 2016 · 2 comments
Closed

Support for multiple query parameter combinations on a path #706

gislikonrad opened this issue Jun 1, 2016 · 2 comments

Comments

@gislikonrad
Copy link

Let's say you have these two routes in your API where the bold parameters are required.

  1. GET - /values?type={type}
  2. GET - /values?from={from}&to={to}

How would you describe this in Swagger 2.0?

Currently you can "hack" it by defining the route like the following.

paths:
  /values:
    get:
      summary: Get values
      parameters:
        - in: query
          name: type
          required: false
          type: string
        - in: query
          name: from
          required: false
          type: string
          format: date
        - in: query
          name: to
          required: false
          type: string
          format: date
      responses:
        '200':
          description: values
          schema:
            type: array
            items: 
              $ref: '#/definitions/value'

What this means is that the way the API is described, consumers could see it as being able to call GET - /values?type={type}&to={to}.

What I propose is a way to create a group or set of parameters and specify multiple possible groups or sets in a route. Example follows.

paths:
  /values:
    get:
      summary: Get values
      parameters:
        - $ref: '#/parameterSets/optional_type_filter'
        - $ref: '#/parameterSets/date_filter'
      responses:
        '200':
          description: values
          schema:
            type: array
            items: 
              $ref: '#/definitions/value'

parameterSets:
  optional_type_filter:
    - in: query
      name: type
      required: false
      type: string
  date_filter:
    - in: query
      name: from
      required: true
      type: string
      format: date
    - in: query
      name: to
      required: false
      type: string
      format: date
@VladRassokhin
Copy link

Looks like duplicate of #182

@webron
Copy link
Member

webron commented Jun 1, 2016

This is a mix of #182 and #256, so let's keep the suggestions there. The suggested solution here introduces an additional level of complexity that will cause extra confusion with the potential parameter grouping in the future. I think the generic solution to #182 would be better in this case.

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

No branches or pull requests

3 participants