-
Notifications
You must be signed in to change notification settings - Fork 46
jsonschema: make schema state independent of resolve arguments #85
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
base: main
Are you sure you want to change the base?
Conversation
jsonschema/schema.go
Outdated
// s.base.uri != nil. | ||
// s.base == s <=> s.uri != nil | ||
uri *url.URL | ||
// These fields are independent of arguments to Schema.Resolved, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how there can be any computed fields in a Schema if it is to be stateless, and a valid operand of many independent calls to Resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unexported fields are the outputs of functions on the other fields. They are cached computations.
For example, pattern
is always the result of compiling Pattern
.
I am assuming a Schema is not changed after Resolve, as documented.
(How to thread-protect the setting of these cached fields will be the topic of another PR.)
However, thinking about this, path
is not in fact a function of the schema, but its ancestors as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved everything into resolvedInfo.
I am trying to take advantage of the fact that a GitHub PR consists of multiple commits, by structuring the work like a stack of CLs. Of the two new commits, the first makes this change, and the second is just a rename. You can view them separately via the "Changes from..." dropdown on the "Files changed" tab.
Move schema state that depends on resolution into the Resolved struct.
The remaining unexported schema fields are dependent only on the schema itself and its sub-schemas.
Now a schema can be resolved multiple times, as itself or as part of other schemas.
Fixes #84.