Skip to content

Commit 9bcae5a

Browse files
committed
Add open api deserialization struct
1 parent 182167d commit 9bcae5a

File tree

1 file changed

+44
-0
lines changed
  • keps/sig-api-machinery/1027-api-unions

1 file changed

+44
-0
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,50 @@ OpenAPIDefinition{
520520
}
521521
}
522522
```
523+
The OpenAPI data will then be deserialized into go structs as follows:
524+
```
525+
// 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.
529+
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
534+
}
535+
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+
}
548+
549+
// MemberField is a member of a union.
550+
// It has a go representation of the field name
551+
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
565+
}
566+
```
523567

524568
### Normalization and Validation
525569

0 commit comments

Comments
 (0)