question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Group multiple parameter definitions for better maintainability

See original GitHub issue

Idea

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:open
  • Created 8 years ago
  • Reactions:246
  • Comments:85 (28 by maintainers)

github_iconTop GitHub Comments

28reactions
DavidBiesackcommented, Mar 25, 2016

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:

parameters:
    - name: id
      in: query
      description: Entry identification number
      required: false
      type: integer
      sets: [ "MetaData" ]

    - name: time_start
      in: query
      description: Start time of flare
      required: false
      type: string
      sets: [ "MetaData", "Alternate" ]

    - name: nar
      in: query
      description: Active region number
      required: false
      type: string
      sets: [ "Alternates" ]

paths:
  /test/:
    get:
      parameters:
        - $ref: "#/parameters/event_type"             <<<< $ref still works
        - $ref: "#/parameters/appearance_date"
      parameterSets: [ "MetaData", "Alternate" ] <<< yields id, time_start and nar
  /other/:
    get:
      parameters:
      parameterSets: [ "Alternate" ]         <<< yields time_start and nar


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.)

17reactions
ePaulcommented, Mar 23, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Group multiple parameter definitions for better maintainability
Sometimes you have some parameters you want to provide on every path. At the moment it is possible to reference them with the...
Read more >
Maintainability Guidelines
To keep constructors, methods, delegates and local functions small and focused, do not use more than three parameters. Do not use tuple parameters....
Read more >
16.4. Efficiency And Maintainability — The Cylc Suite Engine 7.8.8 ...
A properly designed family hierarchy fulfils three purposes in Cylc: efficient sharing of all configuration common to groups of related tasks; efficient bulk ......
Read more >
Maintainability - an overview | ScienceDirect Topics
Maintainability is defined as the probability that a failed component or system will be restored or repaired to a specified condition within a...
Read more >
Chapter 1. Reliable, Scalable, and Maintainable Applications
When you combine several tools in order to provide a service, ... The best choice of parameters depends on the architecture of your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found