@@ -260,11 +260,6 @@ kubebuilder types):
260
260
is not present in the ` unionMember ` tag, then the object will fail validation
261
261
if the discriminator selects the field but it is nil. A field can be marked as
262
262
optional without specifying memberName via ` // +unionMember,optional ` .
263
- - ` // +unionDiscriminatedBy=<discriminatorName> ` before a member field identifies which
264
- discriminator (and thus which union) the member field belongs to. Optional
265
- unless there are multiple unions/discriminators in a single struct. If used,
266
- it must be the go (i.e. ` CamelCase ` ) representation of the field name tagged
267
- with ` unionDiscriminator ` .
268
263
269
264
#### Discriminator Values
270
265
@@ -352,7 +347,7 @@ type Union struct {
352
347
// +unionMember
353
348
// +optional
354
349
FieldA int `json:"fieldA"`
355
- // +unionMember
350
+ // +unionMember,optional
356
351
// +optional
357
352
FieldB int `json:"fieldB"`
358
353
}
@@ -365,54 +360,20 @@ const (
365
360
Beta = "BETA"
366
361
)
367
362
368
- // This will generate one union that can be embedded because the members explicitly define their discriminator.
369
- // Also, the unionMember markers here demonstrate how to customize the names used for
370
- each field in the discriminator.
363
+ // This generates a union where the unionMember markers demonstrate how to
364
+ customize the names used for each field in the discriminator.
371
365
type Union2 struct {
372
366
// +unionDiscriminator
373
367
// +required
374
368
Type2 Union2Type `json:"type"`
375
- // +unionMember=ALPHA,
376
- // +unionDiscriminatedBy=Type2
369
+ // +unionMember=ALPHA
377
370
// +optional
378
371
Alpha int `json:"alpha"`
379
- // +unionMember=BETA
380
- // +unionDiscriminatedBy=Type2
372
+ // +unionMember=BETA,optional
381
373
// +optional
382
374
Beta int `json:"beta"`
383
375
}
384
376
385
- // +enum
386
- type FieldType string
387
-
388
- const (
389
- Field1 FieldType = "Field1"
390
- Field2 = "Field2"
391
- FieldNone = "None"
392
- )
393
-
394
- // This has 3 embedded unions:
395
- // One for the fields that are directly embedded, one for Union, and one for Union2.
396
- type InlinedUnion struct {
397
- Name string `json:"name"`
398
-
399
- // +unionDiscriminator
400
- // +required
401
- FieldType FieldType `json:"fieldType"`
402
- // +unionMember
403
- // +unionDiscriminatedBy=FieldType
404
- // +optional
405
- Field1 *int `json:"field1,omitempty"`
406
- // +unionMember
407
- // +unionDiscriminatedBy=FieldType
408
- // +optional
409
- Field2 *int `json:"field2,omitempty"`
410
-
411
- // Union does not label its members, so it
412
- cannot be inlined
413
- union Union `json:"union"`
414
- Union2 `json:",inline"`
415
- }
416
377
```
417
378
418
379
### OpenAPI
@@ -441,12 +402,6 @@ const (
441
402
FieldD Union1Type = "FieldD"
442
403
FieldNone Union1Type = ""
443
404
)
444
- const (
445
- Alpha Union2Type = "ALPHA"
446
- Beta Union2Type = "BETA"
447
- Gamma Union2Type = "GAMMA"
448
- Null Union2Type = "NULL"
449
- )
450
405
451
406
// This will generate one union, with two fields and a discriminator.
452
407
type Union struct {
@@ -463,18 +418,6 @@ type Union struct {
463
418
// +optional
464
419
FieldB int `json:"fieldB"`
465
420
466
- // +unionDiscriminator
467
- // +required
468
- Union2 Union2Type `json:"union2"`
469
-
470
- // +unionMember=ALPHA,
471
- // +unionDiscriminatedBy=Union2
472
- // +optional
473
- Alpha int `json:"alpha"`
474
- // +unionMember=BETA,optional
475
- // +unionDiscriminatedBy=Union2
476
- // +optional
477
- Beta int `json:"beta"`
478
421
}
479
422
```
480
423
0 commit comments