Skip to content

Commit 5e85c60

Browse files
committed
OpenAPI extension feedback
1 parent 9bcae5a commit 5e85c60

File tree

2 files changed

+23
-79
lines changed

2 files changed

+23
-79
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
kep-number: 1027
22
alpha:
3-
approver: "@deads2k"
3+
approver: "@johnbelamaric"

keps/sig-api-machinery/1027-api-unions/README.md

Lines changed: 22 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ kubebuilder types):
247247
discriminator values). This field MUST be required if there is no default
248248
option, omitempty if the default option is the empty string, or optional and
249249
omitempty if a default value is specified with the `// +default` marker.
250-
- `// +unionMember=<memberName>,<optional> before a field means that this
250+
- `// +unionMember[=<memberName>][,optional] before a field means that this
251251
field is a member of a union. The `<memberName>` is the name of the field that will be set as the discriminator value.
252252
It MUST correspond to one of the valid enum values of the discriminator's enum
253253
type. It defaults to the go (i.e `CamelCase`) representation of the field name if not specified.
@@ -478,90 +478,34 @@ type Union struct {
478478
}
479479
```
480480

481-
turns into:
482-
```
483-
OpenAPIDefinition{
484-
Schema: spec.Schema{
485-
SchemaProps: spec.SchemaProps{
486-
... // schema props omitted
487-
},
488-
VendorExtensible: spec.VendorExtensible{
489-
Extensions: spec.Extensions{
490-
"x-kubernetes-unions": []interface{}{
491-
map[string]interface{}{
492-
"discriminator": "Union1",
493-
"fields-to-discriminateBy": map[string]interface{}{
494-
"FieldA": map[string]interface{}{
495-
"discriminatorValue": "FieldA",
496-
"optional": false,
497-
}
498-
"FieldB": map[string]interface{}{
499-
"discriminatorValue": "FieldB",
500-
"optional": true,
501-
}
502-
}
503-
},
504-
map[string]interface{}{
505-
"discriminator": "Union2",
506-
"fields-to-discriminateBy": map[string]interface{}{
507-
"Alpha": map[string]interface{}{
508-
"discriminatorValue": "ALPHA",
509-
"optional": false,
510-
}
511-
"Beta": map[string]interface{}{
512-
"discriminatorValue": "BETA",
513-
"optional": true,
514-
}
515-
}
516-
}
517-
}
518-
}
519-
}
520-
}
521-
}
522-
```
523-
The OpenAPI data will then be deserialized into go structs as follows:
481+
The OpenAPI x-kubernetes-unions extension will then be attached to the discriminator's property and
482+
deserialized into go structs as follows:
524483
```
525484
// XKubernetesUnions is the top level extension
526-
// that lists all the unions in the object.
527-
// Each union is determined by its identifying
528-
// discriminator.
529485
type XKubernetesUnions struct {
530-
// Discriminators are the list of unions in an object.
531-
// There is a 1:1 mapping between a union and its discriminator
532-
// and hence we identify a union by its discriminator.
533-
Discriminators []Discriminator
486+
// FieldMembers are the mapping of all valid discriminator values in a
487+
// union to the corresponding member field.
488+
// Discriminator value is the value to which the discriminator is set to
489+
// in order to indicate that a given member field is the currently set member
490+
// of the union.
491+
// MemberField may be nil in the case of empty union members where a valid
492+
// discriminator value has no corresponding member field.
493+
FieldMembers map[DiscriminatorValue]*MemberField `json:"fieldMembers"`
534494
}
535495
536-
// Discriminator defines a union. It has
537-
// a name and a list of member fields
538-
type Discriminator struct {
539-
// Name is the go (CamelCase) representation of the
540-
// discriminator field
541-
// It is the value that `// +unionDiscriminatedbBy=<discriminatorName>`
542-
// should be set to on member fields.
543-
Name string
544-
// FieldsToDiscriminateBy are all the member fields that
545-
// are in a given discriminator's union.
546-
FieldsToDiscriminateBy []MemberField
547-
}
496+
// DiscriminatorValue is the value that the discriminator is set to
497+
// in order to indicate the selection of a union member.
498+
type DiscriminatorValue string
548499
549-
// MemberField is a member of a union.
550-
// It has a go representation of the field name
500+
// MemberField
551501
type MemberField struct {
552-
// The camel case representation of the member field used to identify which
553-
// field in the union struct corresponds to the member.
554-
GoName string
555-
// DiscriminatorName is the value that the discriminator is set to in order
556-
// to identify a member field as the currently chosen one.
557-
// It will only be different from the GoName if API authors set a member
558-
// name value in the union member marker `// +unionMember=<MemberName>`
559-
DiscriminatorName string
560-
// Optional determines whether the discriminator can be set to a member field
561-
// even if the member field is not present (or nil). Default is false, and is
562-
// set to true by setting the union member marker as optional, i.e.
563-
// `// +unionMember,optional` or `// +unionMember=<MemberName>,optional`
564-
Optional bool
502+
// Name is the name of the field corresponding to the member.
503+
// It will be the json representation of the field marked with the
504+
// `// +unionMember` marker in the go type.
505+
Name string `json:"name"`
506+
// Optional determines whether the discriminator _may_ select this member
507+
// even when the member field is empty. Optional defaults to false.
508+
Optional bool `json:"optional"`
565509
}
566510
```
567511

0 commit comments

Comments
 (0)