Skip to content

Commit 89d9b91

Browse files
feat: add new schema builder methods which allow GC to collect built schemas
1 parent 8e9d97c commit 89d9b91

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

datamodel/high/base/schema_proxy.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ func (sp *SchemaProxy) BuildSchema() (*Schema, error) {
164164
return schema, er
165165
}
166166

167+
func (sp *SchemaProxy) BuildTempSchema() (*Schema, error) {
168+
if sp == nil {
169+
return nil, nil
170+
}
171+
s := sp.schema.Value.TempSchema()
172+
if s == nil {
173+
return nil, sp.schema.Value.GetBuildError()
174+
}
175+
sch := NewSchema(s)
176+
sch.ParentProxy = sp
177+
return sch, nil
178+
}
179+
167180
// GetBuildError returns any error that was thrown when calling Schema()
168181
func (sp *SchemaProxy) GetBuildError() error {
169182
return sp.buildError

datamodel/low/base/schema_proxy.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func (sp *SchemaProxy) Schema() *Schema {
8888
if sp.rendered != nil {
8989
return sp.rendered
9090
}
91+
sp.rendered = sp.TempSchema()
92+
return sp.rendered
93+
}
94+
95+
func (sp *SchemaProxy) TempSchema() *Schema {
9196
schema := new(Schema)
9297
utils.CheckForMergeNodes(sp.vn)
9398
err := schema.Build(sp.ctx, sp.vn, sp.idx)
@@ -96,8 +101,6 @@ func (sp *SchemaProxy) Schema() *Schema {
96101
return nil
97102
}
98103
schema.ParentProxy = sp // https://github.com/pb33f/libopenapi/issues/29
99-
sp.rendered = schema
100-
101104
// for all the nodes added, copy them over to the schema
102105
if sp.NodeMap != nil {
103106
sp.NodeMap.Nodes.Range(func(key, value any) bool {

0 commit comments

Comments
 (0)