Closed cansik closed 3 months ago
Thanks for opening the issue, there's just one thing that's not clear. On one hand, you're saying that you want to provide them for 'every path' which implies a global definition that won't require you to reference it, and on other hand, you go ahead and reference from a specific method to the group of parameters. So which of the two are you looking for? or is it both?
Ok the formulation every path is maybe wrong (too open). We still have paths which do not need this parameter. We would like to use it as described in the example to reference a group of parameter with one reference. Otherwise it would look like this:
/test/:
get:
tags:
- TEST
operationId: routes.test
parameters:
# In path parameter
- $ref: "#/parameters/event_type"
- $ref: "#/parameters/appearance_date"
# Meta Data Properties
- $ref: "#/parameters/param1"
- $ref: "#/parameters/param2"
- $ref: "#/parameters/param3"
- $ref: "#/parameters/param4"
- $ref: "#/parameters/param5"
- $ref: "#/parameters/param6"
# Data Properties
- $ref: "#/parameters/param7"
- $ref: "#/parameters/param8"
- $ref: "#/parameters/param9"
- $ref: "#/parameters/param10"
# Specific Properties
- $ref: "#/parameters/param11"
- $ref: "#/parameters/param12"
- $ref: "#/parameters/param13"
- $ref: "#/parameters/param14"
- $ref: "#/parameters/param15"
- $ref: "#/parameters/param16"
- $ref: "#/parameters/param17"
responses:
200:
description: OK
With the enhancement we could write it like this and manage the items of each group in one place:
/test/:
get:
tags:
- TEST
operationId: routes.test
parameters:
# In path parameter
- $ref: "#/parameters/event_type"
- $ref: "#/parameters/appearance_date"
# Meta Data Properties
- $ref: "#/parameters/MetaDataParamGroup"
# Data Properties
- $ref: "#/parameters/DataParamGroup"
# Specific Properties
- $ref: "#/parameters/SpecificParamGroup"
responses:
200:
description: OK
Okay, thank you for the clarification. The reason I asked is because we have a feature request for global parameters already.
People have asked for parameter groups in various places, but nobody opened a feature request, so thank you for taking the time to do so. The value of it is understandable. I'm not sure the syntax you shared works, but we can evaluate it further over time.
If $ref: "#/parameters/MetaDataParamGroup"
resolves to a hash (as described above) parameters
will have that hash in it which is not valid as Swagger 2.0. Unless we change the parameters
array format to allow hashs (which I don't think it's a good idea) it will not work.
@mohsen1 Ok and what is the problem with hashes for parameters? Is there a discussion in another issue about this?
parameters
is an array of parameter objects. I'm not sure if we want parameterName:parameterObject hashs in the spec also.
@cansik, @mohsen1: /parameters
is a hash of parameter objects but /paths/{path}/parameters
and /paths/{path}/{operation}/parameters
are arrays of parameters objects. There is no confusion.
@cansik For your request, I suggest that you define your own vendor extension for parameter groups, and write a processing tool that would inline your group references into a pure Swagger 2.0 spec for external consumption. This is how I work for my own API: I write my spec in YAML (that allows me to use comments) and will only publish the JSON version of it.
I already find that many tools do not fully support the current spec (for example I found issues with /parameters
and /paths/{path}/parameters
and I had to write a processor to inline them). We don't need now to complexify the spec if tools do not follow it.
+1 Want to see this feature as well.
+1 we too have predefined query params to almost all api paths
+1 this would save me a lot of time and lines in my doc spec
+1 this too, everything that gets me to reuse code is a huge +1.
+1 would love to see it
+1
It's worth noting that RAML take on this, 'traits' (really not much different from the proposed structure). http://raml.org/developers/raml-200-tutorial#traits
+1
Reference OAI/OpenAPI-Specification#560
+1
+1
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.
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.)
+1
@OAI/tdc propose closing this with no action. The fix in OAI/OpenAPI-Specification#633 will help with this
I think we still need to support this, and should be fairly easy.
OAI/OpenAPI-Specification#633 doesn't really help with this. This is not about global parameters, and reusable parameters existed in 2.0 already.
FWIW, I would like OAS to use structural abstractions (such as the tags I suggest above) over $ref
representation "tricks" which IMHO hide or obscure the intent. The API designer's goal is to reuse common API constructs such as sets of parameters. Implementing that through $ref
and JSON schema inclusion works, but doing so adds a level of redirection (which to me equates to obfuscation.)
I agree with @webron that sets deserve consideration on their own.
This should absolutely be a feature. For API endpoints with many shared configuration parameters, it is a huge hassle to maintain those same params everywhere.
+
1 this would save me time and lines
+1
+1
+1
+1
+1
As my previous note seems to not be followed anymore, here a repetition:
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.
Please don't add a comment with just "+1", instead just upvote the top post. Just post a new comment if you actually are adding any content.
Parameter sets seem better than the original proposal. Pretty simple QoL change that probably doesn't play badly with other proposals.
+1
Grouping makes it much more clean, when having multiple endpoints with multiple parameters.
Would save quite a few lines of code and can focus on the specifics in an operation. Must have.
Convenience is not a 'must have'. Not saying we're not in favor of supporting it, but keep it in proportion.
+1
+1
We strongly recommend this feature. For example consider HMAC auth headers. If we could group the parameters then we could use them with a single ref, now I have to use many small refs. I believe if grouping of definfitions like allOf exists then for the same reason grouping of parameters must also exist.
We're past feature freeze for 3.0.0, so expect this isn't happening initially.
+1
2 years later and this still isn't a thing? any idea if this is going to be adopted?
Seems like plenty of positive reactions :)
@cansik did you ever get a more elegant solution than https://github.com/OAI/Overlay-Specification/issues/34? Or did you go the route @dolmen suggested with https://github.com/OAI/Overlay-Specification/issues/34
This is definitely something we would like to do. The big question is what is the best way of doing it. This was my thought experiment on the subject https://github.com/OAI/Gluecon-Workshop/blob/master/Experiments/GroupRef.yml
@darrelmiller looks good. anything that promotes reuse and grouping of commom elements where ever possible has got to be a priority. Your implementation definitely seems fairly flexible, I will have a think on it and see if I have any further suggestions.
In API design I tend to favour having parameters rather than relying on a body object + schema definition so I can have better descriptions, examples and easier access to those properties from the swagger UI (have had a look around for best practises / knowledge on this but couldn't find much).
This means on resources with GET / PUT / POST, they usually end up exposing the same, or mostly the same params. Then this duplicated across various resources can get pretty duplicate heavy unless doing something like @cansik does here - https://github.com/OAI/Overlay-Specification/issues/34
@poppahorse As you mentioned, the issue is two years old. I have to admit that don not work with Swagger anymore, but I still think it is an important topic.
To solve the problem in our project, we decided to write a preprocessor (as @dolmen suggested) and to inject the parameters on startup. But I do not think that this is the right way to go. Because, as you see, there are a lot of people who would like to have a in-framework solution for that problem.
So, instead of everybody writing their own isolated tools, it would be better to have it directly in the specification.
But at the moment I do not know, what is needed to go a step further. Maybe the discussion about how it really could be implemented, should be opened again.
@cansik When you moved away from Swagger, where did you move to?
At the current state swagger generates more work than it solves and is just not flexible enough. Many things are missing including this one from this issue. So I really don't want to use it anymore...
@cansik @wzrdtales Many of the improvements in V3 of the spec came from people creating issues that proposed solutions to problems. Discussing how important things are and how much is missing, doesn't really move us forward. Proposing a concrete solution or commenting on solutions proposed by others does. The next version of the spec will most likely be a 3.1 and will come much quicker than 3.0 did.
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):
And here is how I would like to reference it:
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