diff --git a/datamodel/high/base/schema_proxy.go b/datamodel/high/base/schema_proxy.go index 188e7347..2ebd7ee3 100644 --- a/datamodel/high/base/schema_proxy.go +++ b/datamodel/high/base/schema_proxy.go @@ -164,6 +164,22 @@ func (sp *SchemaProxy) BuildSchema() (*Schema, error) { return schema, er } +func (sp *SchemaProxy) BuildTempSchema() (*Schema, error) { + if sp.rendered != nil { + return sp.rendered, nil + } + if sp.schema == nil { + return nil, nil + } + s := sp.schema.Value.TempSchema() + if s == nil { + return nil, sp.schema.Value.GetBuildError() + } + sch := NewSchema(s) + sch.ParentProxy = sp + return sch, nil +} + // GetBuildError returns any error that was thrown when calling Schema() func (sp *SchemaProxy) GetBuildError() error { return sp.buildError diff --git a/datamodel/low/base/schema_proxy.go b/datamodel/low/base/schema_proxy.go index 54e5f54c..cf35f6ef 100644 --- a/datamodel/low/base/schema_proxy.go +++ b/datamodel/low/base/schema_proxy.go @@ -85,9 +85,11 @@ func (sp *SchemaProxy) Build(ctx context.Context, key, value *yaml.Node, idx *in // If anything goes wrong during the build, then nothing is returned and the error that occurred can // be retrieved by using GetBuildError() func (sp *SchemaProxy) Schema() *Schema { - if sp.rendered != nil { - return sp.rendered - } + sp.rendered = sp.TempSchema() + return sp.rendered +} + +func (sp *SchemaProxy) TempSchema() *Schema { schema := new(Schema) utils.CheckForMergeNodes(sp.vn) err := schema.Build(sp.ctx, sp.vn, sp.idx) @@ -96,8 +98,6 @@ func (sp *SchemaProxy) Schema() *Schema { return nil } schema.ParentProxy = sp // https://github.com/pb33f/libopenapi/issues/29 - sp.rendered = schema - // for all the nodes added, copy them over to the schema if sp.NodeMap != nil { sp.NodeMap.Nodes.Range(func(key, value any) bool {