-
Notifications
You must be signed in to change notification settings - Fork 231
Add parsing of openapi oneof/union semantic into smd #152
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
Conversation
|
/assign @lavalamp |
pkg/schemaconv/smd.go
Outdated
| return tr | ||
| } | ||
|
|
||
| func parseOneOfDiscriminator(v interface{}) (bool, error) { |
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.
these two functions shouldn't be here.
e630821 to
4f55afd
Compare
|
tests are expected to fail, there is a dependency to kubernetes-sigs/structured-merge-diff#72 |
pkg/schemaconv/smd.go
Outdated
| Fields: map[string]string{}, | ||
| } | ||
|
|
||
| if idiscriminator, ok := extensions["x-kubernetes-oneof-discriminator"]; ok { |
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.
is this a new extension or do we publish it already now?
pkg/schemaconv/smd.go
Outdated
| if idiscriminator, ok := extensions["x-kubernetes-oneof-discriminator"]; ok { | ||
| discriminator, ok := idiscriminator.(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf(`"x-kubernetes-oneof-discriminator" is of invalid type: %T`, idiscriminator) |
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.
Might be nice to print the value, too. I think %#v includes both.
pkg/schemaconv/smd.go
Outdated
| for ifield, value := range fields { | ||
| field, ok := ifield.(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf(`"x-kubernetes-oneof-fields": field is of invalid type: %T`, ifield) |
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.
Definitely need to print the value to make this error actionable.
pkg/schemaconv/smd.go
Outdated
| } | ||
|
|
||
| if union.Discriminator != nil && len(union.Fields) == 0 { | ||
| return nil, fmt.Errorf("discriminator set to %v, but no fields in union", *union.Discriminator) |
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.
Is this actually an error?
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.
How does one indicate whether or not "None" is a permitted value?
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.
Is this actually an error?
What's the point? if the only thing you have a discriminator, then it's just an enum. I would suspect that they happen because of a user-error.
| type: | ||
| namedType: io.k8s.api.core.v1.VsphereVirtualDiskVolumeSource | ||
| union: | ||
| fields: |
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.
Sorry to leave this comment here and not in an earlier change, but...
would this make more sense as "choices", where it's a list of structs which set "field" and "discriminatedBy" or something? e.g.
union:
discriminator: type
options:
- fieldName: fc
discriminatedBy: FC
- fieldName: azureDisk
discriminatedBy: AzureDisk
...
I think it is more understandable that way, 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.
You could even indicate a "none" option that way by permitting a single entry to have no fieldName and just a discriminatedBy.
(no strong opinion about the exact names intended)
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.
Yeah, Jenny made a similar comment on the other PR, I agree. That's also much more kubernetes-style.
4f55afd to
a2590a3
Compare
pkg/schemaconv/smd.go
Outdated
| if idiscriminator, ok := extensions["x-kubernetes-union-discriminator"]; ok { | ||
| discriminator, ok := idiscriminator.(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf(`"x-kubernetes-union-discriminator" is of invalid type: %#v`, idiscriminator) |
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.
nit: write which type you expect
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.
Very good point, I just fixed them all! Thanks, PTAL
9ae72f6 to
f30e972
Compare
f30e972 to
0a103ed
Compare
pkg/schemaconv/smd.go
Outdated
|
|
||
| } | ||
| sort.Strings(keys) | ||
| reverseMap := map[string]string{} |
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.
What's the point of keeping the values in here?
pkg/schemaconv/smd.go
Outdated
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if schemaUnion != nil { |
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.
Why would it be nil, should that be an error also?
0a103ed to
62f1ac3
Compare
|
Fixed, PTAL |
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: apelisse The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
| "description": "DeploymentStrategy describes how to replace existing pods with new ones.", | ||
| "x-kubernetes-unions": [{ | ||
| "discriminator": "type", | ||
| "fields-discriminated": { |
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.
does this mean we don't support non-discriminator unions? Would rather call it fields instead of fields-discriminated.
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.
as the type is different, we would in fact need fields []string and discriminatedFields map[string]string.
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.
Yeah I'll probably do that ... if discriminator is set, then fields must be unset and fields-discriminated must be set. and the other way around.
Implements first part of kubernetes/enhancements#926.
We still need to change the OpenAPI generation to add these extensions.