Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jba
Copy link
Contributor

@jba jba commented Jul 2, 2025

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.

@jba jba requested a review from findleyr July 2, 2025 13:49
@jba
Copy link
Contributor Author

jba commented Jul 2, 2025

@findleyr: @adonovan should review. Having trouble getting his username to show up.

// s.base.uri != nil.
// s.base == s <=> s.uri != nil
uri *url.URL
// These fields are independent of arguments to Schema.Resolved,
Copy link

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@jba jba requested a review from adonovan July 4, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jsonschema: remove Schema resolution fields
2 participants