-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
use Go templates in protofile comments #1056
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1056 +/- ##
==========================================
+ Coverage 53.84% 53.85% +<.01%
==========================================
Files 41 41
Lines 4147 4176 +29
==========================================
+ Hits 2233 2249 +16
- Misses 1670 1681 +11
- Partials 244 246 +2
Continue to review full report at Codecov.
|
Hi Jeremy, thanks for this PR. A few thoughts:
|
Thanks for the fast reply Johan!
|
Could we also add an example of this to one of our example files? We usually put an example of how to use a new feature into one of the proto files in the examples folder. Since this one has to be explicitly turned on (thanks for that by the way!), you'll need to add a new file and ensure it is generated with the appropriate flags. Let me know if you need any help with this. Lastly, how do you feel about adding a small documentation page for this new feature? I think that would greatly help with adoption. Take a look in https://github.com/grpc-ecosystem/grpc-gateway/tree/master/docs/_docs for other pages and examples of what they can look like. |
Can you help me understand why it is preferable to have an unstructured description of the request response object in the swagger definition? Wouldn't it be better to improve the logic that pulls this information to fill in the request and response objects with more definition? |
Hi Andrew, |
I have added a funcmap to the Go template which contains a function called "import". This function makes it possible to import documentation from an external file. For example a markdown file which contains a long detailed documentation. This way your protofile doesn't have to be flooded with documentation.
I'm trying to make an example file right now, but I have no experience with Bazel. So I would really appreciate if you could help me with that.
Will do! |
Unfortunately, I, too, don't really undestand Bazel so the best I can say is "just do what the other example files do". @drigz or @achew22 might be able to help more. |
My first question is whether it makes sense to add a new flag for this. Will anyone want to disable templating? On the one hand, maybe it would break people who have If you continue with the flag, you can follow the example of #944. You can test by installing Bazel, then running: (assuming you call the new target
and inspecting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for the documentation page before merging.
FYI, don't be too worried about the generate job failing in CI, #1058 is currently blocking any other merges to master. As soon as that's in, just rebase on master and everything should be happy again.
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
Hi again @Jeremytjuh, please rebase on master to fix CI. |
Hi @johanbrandhorst, |
You'll also need to pull the latest generator image before regenerating the files again. See CONTRIBUTING.md. Sorry for the inconvenience 😅. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small points. I think the bazel error is real:
ERROR: file 'examples/proto/examplepb/stream.swagger.json' is generated by these conflicting actions:
Label: //examples/proto/examplepb:examplepb_protoc_gen_swagger, //examples/proto/examplepb:examplepb_protoc_gen_swagger_template
The node test looks flaky, I will rerun it.
post: "/v1/example/login" | ||
body: "*" | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the indentation here looks a bit off.
docs/_docs/usegotemplates.md
Outdated
*.proto | ||
``` | ||
|
||
For an example of a protofile which has Go templates enabled, [click here](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/proto/examplepb/use_go_template.proto "Example protofile with Go template"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start! Do you think you could just add a protofile snippet and some screen shots as well to show what this looks like when rendered to swagger?
Ah, the node_test error is because our runner doesn't have |
|
I think this is due to a limitation/bug of If that's not easy, then we could just remove the Bazel rule for the example. |
Co-Authored-By: Johan Brandhorst <[email protected]>
Hi @johanbrandhorst, All tests seem to be working now. Let me know if you want me to change anything. |
I consent to have my contributions to this PR merged into the repo under the relevant license. @achew22 could you make the bot happy please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @achew22 if you have any more questions around this I'll leave it for a few days before merging.
@johanbrandhorst @achew22 Are we good to go? |
I'm afraid we still need the CLA situation manually resolved by someone with authority. I've sent some reminders around. Sorry for the delay. |
@googlebot I consent |
@googlebot I consent. |
I am confused by the internal debugging state of the tool, but as I think I have the power to make this go through and as the consent has been granted, let's try. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
Alright we got there in the end. Thanks for your contribution @Jeremytjuh, sorry for the arcane bot treatment. I should know better than to make actual github suggestions on PRs. |
I didn't open a new internal bug for the tool, but I did fire off an email. Someone should do something! |
* use GO templates in protofile comments * Added support for the other swagger documentation fields * Added feature for Go templates in imported files * Fixed typo in main.go Co-Authored-By: Johan Brandhorst <[email protected]> * Added Go template example * Added Go template documentation * Generated examples using build image * Generated bazel files using build image * Added use_go_templates.pb.gw.go in build file * Enhanced documentation * Fixed indents * Edited Go template bazel test * Excluded use_go_template.pb.gw.go in buildfile
Introduce GO Templates into proto comments to allow more advanced documentation such as from
external (markdown) files and automatically generated content based on the proto definitions.
For example:
The comments in this proto file:
would generate the following documentation in Swagger UI:
or when imported in Postman: