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

Client-side OpenAPI schema fixes #38

Merged
merged 2 commits into from
May 29, 2018

Conversation

luksa
Copy link
Contributor

@luksa luksa commented Feb 21, 2018

These changes allow the client to properly handle the server-side changes planned to be introduced in kube v1.11:

  • RawExtension type will be removed and replaced with "type": "object" without either the additionalProperties or the properties field.
  • All type definitions stemming from Go structs will contain the "type": "object" property (next to the properties field, which they already contain).

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 21, 2018
Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

Looks mostly good. Just a few minor comments.

@@ -149,11 +154,13 @@ func (d *Definitions) parsePrimitive(s *openapi_v2.Schema, path *Path) (Schema,
}
switch t {
case String:
fallthrough
Copy link
Member

@apelisse apelisse Apr 4, 2018

Choose a reason for hiding this comment

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

This is equivalent to what it was doing before. I don't know which version I dislike the most :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I've now removed fallthrough and instead added a comment (// do nothing). Give how go doesn't fallthrough by default, a comment will help most of us that are used to how switch statements behave in other languages.

objectTypes := s.GetType().GetValue()
if len(objectTypes) == 1 {
if len(objectTypes) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

We could avoid the repetition here I think, by extracting the objectTypes[0] into a variable, that we would default to object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced the if/else if with a switch. Not sure what you meant about extracting it into a variable - it wouldn't change anything as it's only used once.

return d.parsePrimitive(s, path)
} else {
// the OpenAPI generator never generates (nor it ever did in the past) OpenAPI type definitions with multiple types
return nil, newSchemaError(path, "definitions with multiple types aren't supported")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be at the beginning

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now the default case in a switch statement.

luksa added 2 commits May 22, 2018 12:11
When an object contains a property of type RawExtension, that property's
definition in the OpenAPI schema only contains "type:object" and no
"additionalProperties". According to the OpenAPI specification, the
object's properties can be of any type (primitives, arrays or objects).
@luksa luksa force-pushed the openapi_schema_fixes_clientside branch from a3dee8c to 81dd575 Compare May 22, 2018 10:12
Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

Looks very good to me! Thank you!

@@ -132,6 +133,63 @@ var _ = Describe("Reading apps/v1beta1/Deployment from openAPIData", func() {
})
})

var _ = Describe("Reading apps/v1beta1/Deployment from v1.11 openAPIData", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Having test for both versions is great!

@apelisse
Copy link
Member

@mbohlool Could you PTAL?

@mbohlool
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mbohlool

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2018
@@ -27,8 +27,9 @@ import (
)

var fakeSchema = testing.Fake{Path: filepath.Join("testing", "swagger.json")}
var fakeSchemaNext = testing.Fake{Path: filepath.Join("testing", "swagger_next.json")}
Copy link
Member

Choose a reason for hiding this comment

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

I'm also writing a change to that code, and I don't want to create a new swagger file for every new piece of feature. Can we just have a new type that uses your feature?

@apelisse
Copy link
Member

/lgtm

That's a net improvement, we might want to simplify the test with the two swagger files.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 29, 2018
@k8s-ci-robot k8s-ci-robot merged commit c8e031d into kubernetes:master May 29, 2018
@luksa luksa deleted the openapi_schema_fixes_clientside branch June 20, 2018 10:21
sttts pushed a commit to sttts/kube-openapi that referenced this pull request Nov 5, 2020
* remove unnecessary debug logs

* allow trailing slash

* use strings.TrimRight

* intermediate commit

* a commit that passes the validation tests

* remove refmodifier

* remove comments for easier review

* fixed tests

* remove unnecessary debug messages

* remove some previously commented code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

4 participants