diff --git a/datamodel/high/base/schema.go b/datamodel/high/base/schema.go index 6ab2e53..f87e3c5 100644 --- a/datamodel/high/base/schema.go +++ b/datamodel/high/base/schema.go @@ -86,6 +86,9 @@ type Schema struct { Deprecated *bool Extensions map[string]any low *base.Schema + + // Parent Proxy refers back to the low level SchemaProxy that is proxying this schema. + ParentProxy *SchemaProxy } // NewSchema will create a new high-level schema from a low-level one. diff --git a/datamodel/high/base/schema_proxy.go b/datamodel/high/base/schema_proxy.go index 3ebe551..7939f0f 100644 --- a/datamodel/high/base/schema_proxy.go +++ b/datamodel/high/base/schema_proxy.go @@ -60,7 +60,9 @@ func (sp *SchemaProxy) Schema() *Schema { sp.buildError = sp.schema.Value.GetBuildError() return nil } - return NewSchema(s) + sch := NewSchema(s) + sch.ParentProxy = sp + return sch } // BuildSchema operates the same way as Schema, except it will return any error along with the *Schema diff --git a/datamodel/high/base/schema_test.go b/datamodel/high/base/schema_test.go index be3759f..85835ba 100644 --- a/datamodel/high/base/schema_test.go +++ b/datamodel/high/base/schema_test.go @@ -208,6 +208,8 @@ deprecated: true` schemaProxy := NewSchemaProxy(&lowproxy) compiled := schemaProxy.Schema() + assert.Equal(t, schemaProxy, compiled.ParentProxy) + assert.NotNil(t, compiled) assert.Nil(t, schemaProxy.GetBuildError()) diff --git a/datamodel/low/base/schema.go b/datamodel/low/base/schema.go index 9951481..9c3e8dd 100644 --- a/datamodel/low/base/schema.go +++ b/datamodel/low/base/schema.go @@ -105,6 +105,9 @@ type Schema struct { Example low.NodeReference[any] Deprecated low.NodeReference[bool] Extensions map[low.KeyReference[string]]low.ValueReference[any] + + // Parent Proxy refers back to the low level SchemaProxy that is proxying this schema. + ParentProxy *SchemaProxy } // Hash will calculate a SHA256 hash from the values of the schema, This allows equality checking against diff --git a/datamodel/low/base/schema_proxy.go b/datamodel/low/base/schema_proxy.go index 3260ee1..a5a3373 100644 --- a/datamodel/low/base/schema_proxy.go +++ b/datamodel/low/base/schema_proxy.go @@ -86,6 +86,7 @@ func (sp *SchemaProxy) Schema() *Schema { sp.buildError = err return nil } + schema.ParentProxy = sp // https://github.com/pb33f/libopenapi/issues/29 sp.rendered = schema return schema } diff --git a/datamodel/low/base/schema_test.go b/datamodel/low/base/schema_test.go index 38225f7..c46142f 100644 --- a/datamodel/low/base/schema_test.go +++ b/datamodel/low/base/schema_test.go @@ -155,6 +155,10 @@ func Test_Schema(t *testing.T) { assert.True(t, v.Value.Schema().ExclusiveMaximum.Value.A) j := v.Value.Schema().FindProperty("somethingBProp").Value.Schema() + k := v.Value.Schema().FindProperty("somethingBProp").Value + + assert.Equal(t, k, j.ParentProxy) + assert.NotNil(t, j) assert.NotNil(t, j.XML.Value) assert.Equal(t, "an xml thing", j.XML.Value.Name.Value)