Skip to content
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

OpenAPI / Swagger2 spec generation #30233

Merged
merged 3 commits into from
Aug 19, 2016

Conversation

mbohlool
Copy link
Contributor

@mbohlool mbohlool commented Aug 8, 2016

This is alpha version of OpenAPI spec generation. Generated "/swagger.json" file (accessible on api server) is a valid OpenAPI spec with some warnings that will be fixed in next versions of spec generation. Currently it is possible to generate a client using this spec though I did not test the clients.

reference: #13414

Release note:

Alpha support for OpenAPI (aka. Swagger 2.0) specification served on /swagger.json (enabled by default)

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. release-note-label-needed labels Aug 8, 2016
// fixOperation tries to rename operation IDs to make OpenAPI spec valid. The best solution to repeated
// ops is to fix it in the source. If that is not possible, the opFix map would let customize the renaming. If the ID
// is not in the opFix map, the name will be concatenated with a string computed from the path. see inferNamePartFromPath
// for more information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we fix generation so this is not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be done in api_installer. We should pass unique Operation name for each operation. There were just too many of them. I think it is better to have swagger 2.0 working and mark it as alpha, then fix those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass this function in to the installer as a fixup func so the implementation in this package knows nothing about Kube.

@mbohlool mbohlool force-pushed the swagger2 branch 2 times, most recently from ded91bb to c661b56 Compare August 9, 2016 02:52
@mbohlool mbohlool added this to the v1.4 milestone Aug 11, 2016
func (o *openAPI) buildModels() (definitions spec.Definitions, err error) {
definitions = spec.Definitions{}
for _, decl := range swagger.NewSwaggerBuilder(*o.config.SwaggerConfig).ProduceAllDeclarations() {
for _, oldNamedModel := range decl.Models.List {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why calling it oldNamedModel?

@nikhiljindal
Copy link
Contributor

Looks good, mostly naming comments.

Would be good to add unit tests for the new code.
We also have unit tests to test the swagger response from /api at server:

resp, err := http.Get(server.URL + "/apis")
.

We can add a simple test for swagger.json path.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2016
@nikhiljindal
Copy link
Contributor

Would be great if we can have unit tests for all methods with non-trivial code.
I will leave it up to you to make a call on which functions in this PR need tests.

@mbohlool mbohlool force-pushed the swagger2 branch 3 times, most recently from 97b3f57 to 61b69af Compare August 18, 2016 15:12
@mbohlool
Copy link
Contributor Author

I've added some test that covers most of the code. This is ready for another round of review.

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 18, 2016
@@ -272,6 +272,7 @@ func Run(s *options.APIServer) error {
genericConfig.ProxyDialer = proxyDialerFn
genericConfig.ProxyTLSClientConfig = proxyTLSClientConfig
genericConfig.Serializer = api.Codecs
genericConfig.OpenAPIInfo.Title = "Kubernetes"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also have to set version here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newConfig set both Title and Version to "Generic API Server" and "unversioned". here we just overwrite the title.

@smarterclayton
Copy link
Contributor

Has verification failures

@nikhiljindal
Copy link
Contributor

Thanks, LGTM.
Feel free to self apply the label when you get all checks to pass.

@mbohlool
Copy link
Contributor Author

@k8s-bot test this issue #30407

1 similar comment
@mbohlool
Copy link
Contributor Author

@k8s-bot test this issue #30407

@mbohlool mbohlool added lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. labels Aug 19, 2016
@k8s-bot
Copy link

k8s-bot commented Aug 19, 2016

GCE e2e build/test passed for commit c5f1d63.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 5898f87 into kubernetes:master Aug 19, 2016
@@ -1,6 +1,6 @@
{
"ImportPath": "k8s.io/kubernetes",
"GoVersion": "go1.6",
"GoVersion": "go1.7",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intentional? If not please revert.

cc @wojtek-t

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it was not. sent the PR to revert it.

@nikhiljindal
Copy link
Contributor

Now that we have a separate param, we should mention in the release note that admins can turn off this new endpoint by setting EnableOpenAPISupport = false.

However for admins to be able to turn it off, we will need to expose it as a command line flag in server_run_options and use that to set config.EnableOpenAPISupport.

@smarterclayton
Copy link
Contributor

Is there a downside to this endpoint being exposed?

On Tue, Aug 23, 2016 at 5:27 PM, Nikhil Jindal notifications@github.com
wrote:

Now that we have a separate param, we should mention in the release note
that admins can turn off this new endpoint by setting EnableOpenAPISupport
= false.

However for admins to be able to turn it off, we will need to expose it as
a command line flag in server_run_options and use that to set
config.EnableOpenAPISupport.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#30233 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABG_p0A6IpnMGAee9vCam1xj-IO6XUxMks5qi2WngaJpZM4JfQc-
.

@mbohlool
Copy link
Contributor Author

@nikhiljindal, @smarterclayton Sorry I missed these comment. I see swagger is enabled by default and we do not have a server config for it. I don't see any downside having this enabled by default, but I can add server config if you think that is useful.

@nikhiljindal
Copy link
Contributor

I am fine with keeping this enabled by default - should probably mention that explicitly in release notes. Right now it says "Alpha support". We use alpha at other places to mean disabled by default.

Re: allowing admins to disable it. Its generally good to allow admins to turn off new features. Not critical.

@mbohlool
Copy link
Contributor Author

Sure, I will send another PR to allow admins to disable it after my improvement #31468 got merged. Do we still have time to change release note of 1.4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants