@@ -404,12 +404,42 @@ func (schema Schema) MarshalYAML() (any, error) {
404
404
405
405
// UnmarshalJSON sets Schema to a copy of data.
406
406
func (schema * Schema ) UnmarshalJSON (data []byte ) error {
407
- type SchemaBis Schema
407
+ type Alias Schema
408
+ type SchemaBis struct {
409
+ Alias
410
+ Discriminator json.RawMessage `json:"discriminator,omitempty"`
411
+ }
412
+
408
413
var x SchemaBis
409
414
if err := json .Unmarshal (data , & x ); err != nil {
410
415
return unmarshalError (err )
411
416
}
412
- _ = json .Unmarshal (data , & x .Extensions )
417
+
418
+ type DiscriminatorObject struct {
419
+ Discriminator * Discriminator `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`
420
+ }
421
+
422
+ if len (x .Discriminator ) > 0 {
423
+ // Attempt to unmarshal as a pointer to a string first
424
+ var ds * string
425
+ if err := json .Unmarshal (x .Discriminator , & ds ); err == nil {
426
+ // If it's a non-nil string pointer, assign it to PropertyName
427
+ if ds != nil {
428
+ x .Alias .Discriminator = & Discriminator {
429
+ PropertyName : * ds ,
430
+ }
431
+ }
432
+ } else {
433
+ // If it's not a string, try to unmarshal as an object
434
+ var do DiscriminatorObject
435
+ if err := json .Unmarshal (x .Discriminator , & do .Discriminator ); err == nil && do .Discriminator != nil {
436
+ // Assign the object if unmarshaling is successful
437
+ x .Alias .Discriminator = do .Discriminator
438
+ }
439
+ }
440
+ }
441
+
442
+ _ = json .Unmarshal (data , & x .Alias .Extensions )
413
443
414
444
delete (x .Extensions , "oneOf" )
415
445
delete (x .Extensions , "anyOf" )
@@ -464,7 +494,7 @@ func (schema *Schema) UnmarshalJSON(data []byte) error {
464
494
x .Extensions = nil
465
495
}
466
496
467
- * schema = Schema (x )
497
+ * schema = Schema (x . Alias )
468
498
469
499
if schema .Format == "date" {
470
500
// This is a fix for: https://github.com/getkin/kin-openapi/issues/697
0 commit comments