-
Notifications
You must be signed in to change notification settings - Fork 199
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ import ( | |
"iter" | ||
"maps" | ||
"math" | ||
"net/url" | ||
"reflect" | ||
"regexp" | ||
"slices" | ||
|
@@ -130,37 +129,13 @@ type Schema struct { | |
// Extra allows for additional keywords beyond those specified. | ||
Extra map[string]any `json:"-"` | ||
|
||
// computed fields | ||
|
||
// This schema's base schema. | ||
// If the schema is the root or has an ID, its base is itself. | ||
// Otherwise, its base is the innermost enclosing schema whose base | ||
// is itself. | ||
// Intuitively, a base schema is one that can be referred to with a | ||
// fragmentless URI. | ||
base *Schema | ||
|
||
// The URI for the schema, if it is the root or has an ID. | ||
// Otherwise nil. | ||
// Invariants: | ||
// s.base.uri != nil. | ||
// s.base == s <=> s.uri != nil | ||
uri *url.URL | ||
// These fields are independent of arguments to Schema.Resolved, | ||
|
||
// though they are computed there. | ||
|
||
// The JSON Pointer path from the root schema to here. | ||
// Used in errors. | ||
path string | ||
|
||
// The schema to which Ref refers. | ||
resolvedRef *Schema | ||
|
||
// If the schema has a dynamic ref, exactly one of the next two fields | ||
// will be non-zero after successful resolution. | ||
// The schema to which the dynamic ref refers when it acts lexically. | ||
resolvedDynamicRef *Schema | ||
// The anchor to look up on the stack when the dynamic ref acts dynamically. | ||
dynamicRefAnchor string | ||
|
||
// Map from anchors to subschemas. | ||
anchors map[string]anchorInfo | ||
|
||
|
@@ -186,27 +161,22 @@ type anchorInfo struct { | |
|
||
// String returns a short description of the schema. | ||
func (s *Schema) String() string { | ||
if s.uri != nil { | ||
if u := s.uri.String(); u != "" { | ||
return u | ||
} | ||
} | ||
if a := cmp.Or(s.Anchor, s.DynamicAnchor); a != "" { | ||
return fmt.Sprintf("%q, anchor %s", s.base.uri.String(), a) | ||
return fmt.Sprintf("anchor %s", a) | ||
} | ||
if s.path != "" { | ||
return s.path | ||
} | ||
return "<anonymous schema>" | ||
} | ||
|
||
// ResolvedRef returns the Schema to which this schema's $ref keyword | ||
// refers, or nil if it doesn't have a $ref. | ||
// It returns nil if this schema has not been resolved, meaning that | ||
// [Schema.Resolve] was called on it or one of its ancestors. | ||
func (s *Schema) ResolvedRef() *Schema { | ||
return s.resolvedRef | ||
} | ||
// // ResolvedRef returns the Schema to which this schema's $ref keyword | ||
jba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// // refers, or nil if it doesn't have a $ref. | ||
// // It returns nil if this schema has not been resolved, meaning that | ||
// // [Schema.Resolve] was called on it or one of its ancestors. | ||
// func (s *Schema) ResolvedRef() *Schema { | ||
// return s.resolvedRef | ||
// } | ||
|
||
func (s *Schema) basicChecks() error { | ||
if s.Type != "" && s.Types != nil { | ||
|
Uh oh!
There was an error while loading. Please reload this page.