Skip to content

feat: add new schema builder methods which allow GC to collect built schemas #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions datamodel/high/base/schema_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@
return schema, er
}

func (sp *SchemaProxy) BuildTempSchema() (*Schema, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add docs to this method? Just so folks know what it is and why it is there.

if sp.rendered != nil {
return sp.rendered, nil

Check warning on line 169 in datamodel/high/base/schema_proxy.go

View check run for this annotation

Codecov / codecov/patch

datamodel/high/base/schema_proxy.go#L167-L169

Added lines #L167 - L169 were not covered by tests
}
if sp.schema == nil {
return nil, nil

Check warning on line 172 in datamodel/high/base/schema_proxy.go

View check run for this annotation

Codecov / codecov/patch

datamodel/high/base/schema_proxy.go#L171-L172

Added lines #L171 - L172 were not covered by tests
}
s := sp.schema.Value.TempSchema()
if s == nil {
return nil, sp.schema.Value.GetBuildError()

Check warning on line 176 in datamodel/high/base/schema_proxy.go

View check run for this annotation

Codecov / codecov/patch

datamodel/high/base/schema_proxy.go#L174-L176

Added lines #L174 - L176 were not covered by tests
}
sch := NewSchema(s)
sch.ParentProxy = sp
return sch, nil

Check warning on line 180 in datamodel/high/base/schema_proxy.go

View check run for this annotation

Codecov / codecov/patch

datamodel/high/base/schema_proxy.go#L178-L180

Added lines #L178 - L180 were not covered by tests
}

// GetBuildError returns any error that was thrown when calling Schema()
func (sp *SchemaProxy) GetBuildError() error {
return sp.buildError
Expand Down
7 changes: 5 additions & 2 deletions datamodel/low/base/schema_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +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 {
sp.rendered = sp.TempSchema()
return sp.rendered
}

func (sp *SchemaProxy) TempSchema() *Schema {
if sp.rendered != nil {
return sp.rendered
}
Expand All @@ -96,8 +101,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 {
Expand Down
Loading