Skip to content

Support for multiple query parameter combinations on a path #706

Description

@gislikonrad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions