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

Handle "any value" openapi definitions properly #25

Merged
merged 3 commits into from
Dec 5, 2017

Conversation

luksa
Copy link
Contributor

@luksa luksa commented Nov 27, 2017

This will allow us to support the k8s RawExtension object

This will allow us to support the k8s RawExtension object
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 27, 2017
@luksa
Copy link
Contributor Author

luksa commented Nov 27, 2017

Fixes kubernetes/kubernetes#55890

@mengqiy
Copy link
Member

mengqiy commented Nov 29, 2017

/assign @apelisse

@apelisse
Copy link
Member

OK, I've read the other pull-request that you've created. I might have misunderstood the intent here. Looking at it again.

@apelisse
Copy link
Member

@@ -242,6 +242,21 @@ func (p *Primitive) GetName() string {
return fmt.Sprintf("%s (%s)", p.Type, p.Format)
}

// AnyValue is an arbitrary value (object, array or primitive)
Copy link
Member

Choose a reason for hiding this comment

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

Can we figure out a better name? My initial understanding was that this was "AnyOf" (from openapi 3.0).

var _ Schema = &AnyValue{}

func (m *AnyValue) Accept(v SchemaVisitor) {
// A AnyValue accepts any type of value, so it's not necessary to call the SchemaVisitor
Copy link
Member

Choose a reason for hiding this comment

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

I think that decision should be taken by each individual visitor, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@pwittrock Do you have an opinion?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should call a schema visitor. The visitor may want to do something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, that was my initial implementation. Then, since all the visitors' methods were empty, I thought I could remove it, since all visitors should always accept any value.

I'll add the methods again and also rename this to ArbitraryValue or whatever you guys think is a better name.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 29, 2017
@@ -55,6 +55,7 @@ type SchemaVisitor interface {
VisitMap(*Map)
VisitPrimitive(*Primitive)
VisitKind(*Kind)
VisitArbitraryValue(*ArbitraryValue)
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 happy you thought of that word Arbitrary. Can I nit and ask you to just keep Arbitrary without the Value?

@apelisse
Copy link
Member

That looks good to me. I have no right here, but lgtm. @mbohlool

@mbohlool mbohlool merged commit fff8c87 into kubernetes:master Dec 5, 2017
@ericchiang
Copy link
Contributor

On master I'm getting this when trying to generate the openapi schema with this change.

$ ./hack/update-openapi-spec.sh
make: Entering directory '/home/eric/src/k8s.io/kubernetes'                                                                                                                                                        
make[1]: Entering directory '/home/eric/src/k8s.io/kubernetes' 
# ...
    cmd/kube-apiserver                              
# k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/strategicpatch                                   
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/meta.go:166:17: cannot use kindItem (type *kindItem) as type "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor in argument to s.Schema
.Accept:                                            
        *kindItem does not implement "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor (missing VisitArbitrary method)                                                                   
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/meta.go:181:17: cannot use sliceItem (type *sliceItem) as type "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor in argument to s.Sche
ma.Accept:                                          
        *sliceItem does not implement "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor (missing VisitArbitrary method)                                                                  
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/types.go:55:5: cannot use kindItem literal (type *kindItem) as type LookupPatchItem in assignment:                                                              
        *kindItem does not implement LookupPatchItem (missing VisitArbitrary method)                     
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/types.go:79:28: cannot use item (type *kindItem) as type "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor in argument to schema.SubSc
hema().Accept:                                      
        *kindItem does not implement "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor (missing VisitArbitrary method)                                                                   
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/types.go:118:5: cannot use sliceItem literal (type *sliceItem) as type LookupPatchItem in assignment:                                                           
        *sliceItem does not implement LookupPatchItem (missing VisitArbitrary method)                    
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/types.go:146:28: cannot use item (type *sliceItem) as type "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor in argument to schema.Sub
Schema().Accept:                                    
        *sliceItem does not implement "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor (missing VisitArbitrary method)                                                                  
vendor/k8s.io/apimachinery/pkg/util/strategicpatch/types.go:169:18: cannot use item (type *sliceItem) as type "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor in argument to subschema.
Accept:                                             
        *sliceItem does not implement "k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/util/proto".SchemaVisitor (missing VisitArbitrary method)    

@ericchiang
Copy link
Contributor

ericchiang commented Dec 11, 2017

Actually sorry false alarm. I don't think this is related to this change. sorry for the noise.

edit: actually see my comment below.

@@ -55,6 +55,7 @@ type SchemaVisitor interface {
VisitMap(*Map)
VisitPrimitive(*Primitive)
VisitKind(*Kind)
VisitArbitrary(*Arbitrary)
Copy link
Contributor

Choose a reason for hiding this comment

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

Expanding this interface causes a ton of code to break in kubernetes/kubernetes...

kubernetes/kubernetes#57059

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants