Group multiple parameter definitions for better maintainability
See original GitHub issueIdea
Sometimes you have some parameters you want to provide on every path. At the moment it is possible to reference them with the $ref
tag. This works great if you have a lot of different parameter combination for each route.
But we now have a complex api with a lot of optional get parameters for every path. Now the problem we encounter is, that if we have to add new parameters to this get parameters, it is very cumbersome and inconvenient to set the reference to them on each path. Often it happens that you forget one.
It would be great if we could group parameter definitions for a better maintainability and usability.
Example
As already presented on stackoverflow here an example of the definition (how it could look like):
parameters:
MetaDataParameters:
# Meta Data Properties
- name: id
in: query
description: Entry identification number
required: false
type: integer
- name: time_start
in: query
description: Start time of flare
required: false
type: string
- name: nar
in: query
description: Active region number
required: false
type: string
And here is how I would like to reference it:
/test/:
get:
tags:
- TEST
operationId: routes.test
parameters:
- $ref: "#/parameters/MetaDataParameters"
responses:
200:
description: OK
To get more on the user experience, this definition is much more readable than 20 parameters for each route.
Other Ideas?
Have you already thought about something like this or do you want us swagger users to go another way to deal with this problem?
Regards Florian
Issue Analytics
- State:
- Created 8 years ago
- Reactions:246
- Comments:85 (28 by maintainers)
Top GitHub Comments
How about allowing us to organize parameters into sets? Then a path could reference parameter sets to automatically get all the parameters in those sets:
This is analogous to
tags
, but I used “sets” to avoid ambiguity. It’s basically a shorthand for multiple $ref, but I think would be easier to read, maintain and reuse. It would not require changing the structure of parameters as in the OP, and would allow parameters to be in multiple sets, which the OP proposal does not allow (I think).(I don’t think there is a UI aspect to these sets, so no set descriptions are needed. Syntax for describing parameter sets would be added for documentation purposes, though.)
Just as a note for everyone wanting to vote this up: Github recently added a feature allowing a “reaction” to each post, using the button in the top left corner of each post. This will not clutter the thread with contentless comments.