-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Allow implicit path parameter matching #132
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
Comments
It should be noted that @fehguy suggested this should be a tooling feature rather than a spec, and I tend to agree with him. For auto-generated specs (using the language libraries), this has no benefit. For the libraries that read the specs, it requires extra processing (to do the matching and so on). The only tool I can think of that could benefit from it is indeed the swagger-editor for human-written specs, and there it may be a nice feature to add, but again, has no effect on the spec itself. |
Note that Swagger spec files are still source files that are read by humans and written by humans. Adding extra redundant but required code to a source file adds verbosity and dilutes the API, making it harder to grasp and understand. The API spec, as source file, is used to communicate with people, so it should include human factors in the design as well. "Convention over configuration" is very successful because of this. |
That's where we disagree. To me, implicit declarations make it less human readable and not more, and not necessarily easier to maintain. |
Note that I'm not requesting an implicit declaration - the declaration is explicit in the "definitions" section. All that is implicit/default is the association from a path to that definition/declaration. I don't think anyone would have to "guess" where it is defined; it would be in the "definitions" section, with a matching name and "in" : "path" (and tools could easily provide a mechanism to "jump" to that definition or lookup/popup the definition) |
I agree with @webron on this. Let's make tools nice for human and specs vebose and easy for machine. I had this bug open in editor from a while back swagger-api/swagger-editor#96 The idea is if you type a path that has parameter in it editor recognizes it and after you hit enter, it will populate the parameters with a parameter from your path. With your example I got another idea. So now my plan is, if editor sees the path param it will lookup parametersDefinition and if sees it there, it will use |
If you favor a "tooling" approach to this, then might I suggest a way to "hide" all the redundant autogen elements such as
and
that get in the way. (For an I don't mean just a folding editor as we currently see, but one that simply hides all the redundant, inferrable specification that does not add value or convey useful information to me, the person authoring the spec. |
Actually now that I'm thinking about it more I like your approach @DavidBiesack. We already have a custom way of parsing Same for path parameters. We should focus developer happiness. Here is how the resolver algorithm should work:
//cc @fehguy @earth2marsh |
+1 : " We should focus [on] developer happiness." Thanks. As I like to say, developer experience matters. Your users are the API developers. |
@mohsen1 Thanks, |
@mohsen1 there is this old, related thread, too: … which also points out how it could be applied to |
Parent #560. |
see #633 for this issue |
Say a Swagger 2.0 API has the following paths (I'm using YAML here, as it's easier to write and read)
I can define
productId
once in Parameters Definitions Object and$ref
it as per Reference Object:but this gets pretty verbose pretty quickly. (Note: I think the editor incorrectly flags this as an error.)
Swagger should automatically match a path parameter with a definition (by
{paramName}
and{ name: paramName, in: path}
)I could still override it if I don't want the common def, which would be no more work than currently.
This would help greatly in cases like the above where the same path parameter is used in multiple separate paths, doubly so for paths that have multiple path parameters.
tony tam replied on this Swagger Google Groups thread that this is intentional to avoid ambiguity. I think this is unnecessarily cumbersome, repetitive, error prone, and a maintenance nightmare. I'd like this to be reconsidered, not just as a tooling convenience, but in the spec.
The text was updated successfully, but these errors were encountered: