-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Automatic Generation of Swagger Documentation in Types #10933
Automatic Generation of Swagger Documentation in Types #10933
Conversation
GCE e2e build/test passed for commit 36055bd3287b31233611820cb572e9817d6716f8. |
|
||
package api | ||
|
||
// AUTO-GENERATED FUNCTIONS START HERE |
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.
Add a comment here that thoroughly explains what this file is, what it's for, how it's generated, etc.
GCE e2e build/test passed for commit afb8f124a8a8c2e1cb723ea0100ea5649f74d333. |
return map[string]string{ | ||
"": "", | ||
"name": "Each container in a pod must have a unique name.", | ||
"state": "TODO(dchen1107): Should we rename PodStatus to a more generic name or have a separate states defined for container?", |
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.
We will need a way to keep these TODOs out of here :)
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.
Yep, I have it already in my todo list on my PR. Working on it
This is exciting. |
@bgrant0607 This is the method @andronat and I came up with to retrieve API documentation out of the comments and make it available to swagger, as per our earlier convo. |
GCE e2e build/test passed for commit 6f3d3828f62c0b4e37b9759006dddcdbf165ef9a. |
I am opposed to any solution that moves documentation out of our interface-definition files, currently |
@bgrant0607 it doesn't move any documentation from |
@bgrant0607 It's clear that this PR does not move documentation out of the current interface-definition files, which is the express purpose of this design, yes? |
Sorry, I don't have time to look at this in detail right now. How would this support additional properties, such as those in the following PR? Or would those remain in tags? |
The current PR is only for the descriptions. Most definitely, we could make the appropriate changes to support also additional properties but I am not sure if we really want to do that. The reason that makes me reluctant for something like this (supporting model attributes as comments) is that when a user/developer reads the source code he/she expects to see a description as a comment but "functional properties" as part of the code (e.g. max number, min number etc). I don't know if that makes any sense to you also :/ (I don't have a strong opinion though on that) |
I like the idea. I loathe the triple-line-wrapped description tags - I think they discourage good descriptions. Moving all of that into comments is a WAY better answer. Let's define a set of standard (for us) comment structures and enforce that every field and every struct in our API is documented fully. |
GCE e2e build/test failed for commit afff8f4cb82b00c555a42999c4bc3c91e9020bf7. |
GCE e2e build/test passed for commit 9823d915f4116e11e8b581c9636bb3228781a353. |
GCE e2e build/test passed for commit 443527908004385f71e4b8a4785ae87f5ef3fbd9. |
GCE e2e build/test passed for commit eef905a1b6493111ae099473dde9ef5c8d674cd5. |
Can someone please take a look on that f51274ed591906371cee4698747aca2f26b7bfc7. I am not 100% sure that I am doing it correctly and it also takes a lot of time. Some input would be appreciated. |
Have you thought about how to implement verify-descriptions? |
Hmm, I missed that part. How about using my generator's code to find if there are missing docs from fields and structs? The generator is parsing the AST of the source code and returns pairs of (field, doc). I can count the number of returned pairs with the number of fields and structs and return OK if none is missing. |
It would need to report which fields lack documentation |
How about this? Also, the command exits with the number of the missing doc definitions.
|
source "${KUBE_ROOT}/hack/lib/init.sh" | ||
|
||
kube::golang::setup_env | ||
"${KUBE_ROOT}/hack/build-go.sh" cmd/genswaggertypedocs |
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.
Similarly could you split this script as well? Thank you.
fixed omitempty. working on other issues. |
GCE e2e build/test passed for commit 6ed3ee3d11f178da1c1ff0f630127451e7758e3d. |
GCE e2e build/test failed for commit 9cb4c486b2aa8e2a04945810c85d3fae6e12a4d5. |
Thank you @andronat. I don't have extra comments. Ping me when you address all of the comments. |
ok just done with the after-build scripts |
Tell me @caesarxuchao when to start squashing |
Go ahead and squash, @andronat. It's already not easy to determine what you changed relative to the previous push. |
Yea sorry for that. I should had put everything as a new commit at the end :/ |
GCE e2e build/test failed for commit 04ed44abad7da107448e87e46a05e92a8029e6cd. |
@andronat, sorry just saw your message. Please add back the "omitempty" for nodeport. #10933 (comment) |
GCE e2e build/test passed for commit a44b3b5d961efca18d45720e52e9254efb46d479. |
found the problem: in |
GCE e2e build/test passed for commit 1074784. |
It is all green! |
Thanks for all the work on this. LGTM. |
Thank you! |
Thank you too for your time and effort! |
Automatic Generation of Swagger Documentation in Types
This is a proposal on how we can handle and export our documentation from api/*/types.go to Swagger API. Refs #3060
The basic idea
Problems
Ideally we would like
go-restful
to be able to parse our source files and export struct and fields comments in the Swagger API. Unfortunately this is not possible (or just very hard) as Swagger's JSON is builded dynamically on runtime and parsing the source files requires 1) having the files in the deployment environment 2) pass the file paths togo-restful
.Currently
go-restful
is able to export field descriptions of a struct by parsing struct tags (using thedescription
tag) and lately, struct description is also supported through themodelDescription
tag. The issue with this method is how can we maintain a source-reader-friendly documentation in our files and keep swagger-friendly tags up to date (these are 1 line long descriptions).Solution
In this PR: emicklei/go-restful#215 we suggest an alternative way of keeping struct documentation through special methods attached on structs.
This PR is about creating a generator that parses the documentation from the Type files (this is done by using
go/doc
andgo/ast
) and automatically generates the aforementioned special documentation methods for each struct.A smaller issue on TODOs and various other comments
We want this parser to ignore TODO lists and various other comments in our source code.
The suggested solution is:
---
in a line and everything after it will be not placed in swagger descriptionsTODO:
wait for Models can generate documentation through a struct method emicklei/go-restful#215 to be mergedignore TODOs (and maybe also other information) -> Use---
and ignore everything after itpolish output (keep paragraphs, keep indentation, keep newline chars in indented lines)ignorejson",inline"
tagsAdd a comment here that thoroughly explains what this file is, what it's for, how it's generated, etcGenerator should not print keys for empty documentation (empty values overwrite struct tags)Refactor verify-descriptionsFixed missing ptr description emicklei/go-restful#219 needs mergingfix description parsing on recursion emicklei/go-restful#222 needs mergingchange QueryParameter description in api_installer.goMove all description tags into commentsDepends on updated go-restful #11406