-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Path variables with segments may produce invalid Swagger file #407
Comments
@calbach thank you for your issue report. Does openapi spec have the descriptive power to differentiate between those two? |
I'm not sure. I couldn't find much in the specification about paths and templates. From searching around, my best guess is that you cannot use pattern matching within a path template - if that's the case the best approximation of this might be something like:
I don't know if such an approach can generalize to all possible http patterns, but at least it would support Google's recommended approach for defining resource names. |
For future reference, looks like the relevant code is here. |
Came here to post about this issue. The issue is obviously that the extracted path name (e.g. TBH I'm still not 100% clear on why Google recommend naming resources like they do. Anyone any ideas? |
I suppose the question is, what's the right thing to do? If I have the following grpc paths:
What should the corresponding swagger paths look like? Perhaps we could give wildcards sequentially generated names after extracting and prepending strings, e.g.:
or, if a segment only contains a single wildcard, use the key of the segment as the placeholder, e.g.:
Since I have basically no idea of the relationship between this plugin and how the gRPC gateway works (i.e. if it uses this plugin internally) does this approach look feasible and make sense @tmc ? It also doesn't resolve the problem of paths using the |
@boosh to answer your question (though it may be retorical)
Not speaking for the people who designed it, but as I understand it, idea is that you don't want your generators changing variable names on you willy nilly. Right now it is pretty easy to rename things to I'm looking forward to some more discussion! |
@achew22 what do you mean by "generators changing variable names on you"? I thought the reason for Google's recommendations for declaring endpoints like I've found in my own APIs this does indeed lead to cleaner interfaces (e.g. because I can do things like return That's my understanding at least. Do you have any feedback on my suggestion for how we can map these sorts of names to swagger path templates? I'd like to get cracking on this as soon as possible because it's thrown a spanner in the works of a project I've been working on and need a resolution or workaround. |
I've created the following python code as a testbed:
It yields:
I believe the above would solve this issue if translated into go. Any thoughts? |
So converting
|
Has there been any traction on this since 2017? I'd like to help out where possible, as this problem is currently biting us a little hard, and I can't seem to find a way to 'override' the http path used for swagger, without changing the entire implementation. |
Is this a dupe of #702? |
Yes - I think it's a dupe AFAICT. That said, I don't have an explanation of why @Multiply hit this if that dupe is marked "fixed", unless they're on an older version. |
Not sure if you want me to reply here, or elsewhere, but I am indeed still hitting this. Just to make sure I wasn't using an older version, I just removed the protoc-gen-swagger, and installed it again, and same result. Currently I'm seeing the following results:
I kind of hoped, this would be generating the following swagger path instead:
Please let me know if that's not how it's meant to work. |
@Multiply thanks for replying, I think that sounds reasonable, looking at the PR that closed #702 it appears we're only doing this expansion for fields called |
@johanbrandhorst I tried adding I also tried using What is the expected path when using prefix? |
I don't know, sorry. If you'd like to experiment with it and find something that works for your use case feel free to open a PR. @achew22 might have a better understanding about why it does or doesn't work. |
Also limiting it to just I might just have the wrong expectations of the functionality, and in that case, what I'd rather want, is a way to override the path used for swagger, using an option of sorts. (Edit: if that even makes sense?) |
To be honest I think this is just one of those things where the gRPC expectation and the swagger expectation differ. I don't really have a good solution. As an example of the difference it could interpret I do not know what a great is.I would expect Do we know the exact definition of a resource name? I think getting clarity on that would be very useful. |
The reason I use underscore, is because my gRPC implementation takes All of the scenarios can be fixed for my use-case, if I can override the generated swagger path. I don't want to modify the actual implementation details, just the generated code the user sees in the UI. The consumer of the documentation might not know from reading How feasible is it to be able to override the generated path? |
…points in protoc-gen-openapiv2 (grpc-ecosystem#407)
… multiple HTTP path/method endpoint support (#2461) * Support standard OpenAPI paths for all valid path params for gRPC endpoints in protoc-gen-openapiv2 (#407) * Fix issue with URL encoded path segments not being split when unescaping mode is legacy, default or all characters * Adding docs for path template syntax and new functionality (#1700) * Removed unused old code * Additional tests for regular expressions * Formatting code * Fix lint error * Removing duplicate test * Adding additional test for path escaping * Fix failing test because of path change * Fix failing tests in code coverage * Change determination of unescaping by supporting default mode change * Regenerated files from changes * Remove unused parameters in test * Remove code warnings in test * Implement changes from PR #2461 comments * Correcting incorrect documentation * Adding test case to show change in docs is warranted
For example:
This produces conflicting paths in the YAML file:
/v1/{name}
twice; the pattern of the variable is not captured in the swagger spec.The text was updated successfully, but these errors were encountered: