From 04881d3d06aeba79e8dc910860a729e2b02dcbcc Mon Sep 17 00:00:00 2001 From: Adam Bouqdib Date: Mon, 14 Oct 2024 11:46:17 +0100 Subject: [PATCH 1/2] feat: support merging additionalProperties if both are equal --- gen/schema_gen_sum.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gen/schema_gen_sum.go b/gen/schema_gen_sum.go index b9dba14e4..24405bba0 100644 --- a/gen/schema_gen_sum.go +++ b/gen/schema_gen_sum.go @@ -836,6 +836,9 @@ func mergeSchemes(s1, s2 *jsonschema.Schema) (_ *jsonschema.Schema, err error) { case s1.AdditionalProperties == nil && s2.AdditionalProperties != nil: r.AdditionalProperties = s2.AdditionalProperties r.Item = s2.Item + case reflect.DeepEqual(s1.AdditionalProperties, s2.AdditionalProperties) && reflect.DeepEqual(s1.Item, s2.Item): + r.AdditionalProperties = s1.AdditionalProperties + r.Item = s1.Item case s1.AdditionalProperties != nil && s2.AdditionalProperties != nil: return nil, &ErrNotImplemented{Name: "allOf additionalProperties merging"} } From 887f69afd67c3f7961f037842f022b45f93642cc Mon Sep 17 00:00:00 2001 From: Adam Bouqdib Date: Mon, 14 Oct 2024 15:21:01 +0100 Subject: [PATCH 2/2] feat: merge additionalProperties schemas --- gen/schema_gen_sum.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gen/schema_gen_sum.go b/gen/schema_gen_sum.go index 24405bba0..2bc4cc9a9 100644 --- a/gen/schema_gen_sum.go +++ b/gen/schema_gen_sum.go @@ -836,9 +836,12 @@ func mergeSchemes(s1, s2 *jsonschema.Schema) (_ *jsonschema.Schema, err error) { case s1.AdditionalProperties == nil && s2.AdditionalProperties != nil: r.AdditionalProperties = s2.AdditionalProperties r.Item = s2.Item - case reflect.DeepEqual(s1.AdditionalProperties, s2.AdditionalProperties) && reflect.DeepEqual(s1.Item, s2.Item): + case reflect.DeepEqual(s1.AdditionalProperties, s2.AdditionalProperties): r.AdditionalProperties = s1.AdditionalProperties - r.Item = s1.Item + r.Item, err = mergeSchemes(s1.Item, s2.Item) + if err != nil { + return nil, errors.Wrap(err, "merge additionalProperties schema") + } case s1.AdditionalProperties != nil && s2.AdditionalProperties != nil: return nil, &ErrNotImplemented{Name: "allOf additionalProperties merging"} }