-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
This will allow us to support the k8s RawExtension object
/assign @apelisse |
OK, I've read the other pull-request that you've created. I might have misunderstood the intent here. Looking at it again. |
OK I think this is it: https://tools.ietf.org/html/draft-zyp-json-schema-04#section-5.1 |
pkg/util/proto/openapi.go
Outdated
@@ -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) |
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.
Can we figure out a better name? My initial understanding was that this was "AnyOf" (from openapi 3.0).
pkg/util/proto/openapi.go
Outdated
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 |
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.
I think that decision should be taken by each individual visitor, what do you think?
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.
@pwittrock Do you have an opinion?
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.
Yes, it should call a schema visitor. The visitor may want to do something.
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.
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.
pkg/util/proto/openapi.go
Outdated
@@ -55,6 +55,7 @@ type SchemaVisitor interface { | |||
VisitMap(*Map) | |||
VisitPrimitive(*Primitive) | |||
VisitKind(*Kind) | |||
VisitArbitraryValue(*ArbitraryValue) |
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.
I'm happy you thought of that word Arbitrary
. Can I nit and ask you to just keep Arbitrary
without the Value
?
That looks good to me. I have no right here, but lgtm. @mbohlool |
On master I'm getting this when trying to generate the openapi schema with this change.
|
edit: actually see my comment below. |
@@ -55,6 +55,7 @@ type SchemaVisitor interface { | |||
VisitMap(*Map) | |||
VisitPrimitive(*Primitive) | |||
VisitKind(*Kind) | |||
VisitArbitrary(*Arbitrary) |
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.
Expanding this interface causes a ton of code to break in kubernetes/kubernetes...
Fix str->bson function usages
This will allow us to support the k8s RawExtension object