jsonschema: resolve anchors
Change-Id: Ibe7d8df0a46d3e3a8b5d0651b1113a54e756c7df Reviewed-on: https://go-review.googlesource.com/c/tools/+/669998 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
0a79e67c62
commit
5cc4e6ea54
1 changed files with 34 additions and 8 deletions
|
|
@ -122,8 +122,7 @@ func (s *Schema) checkLocal(report func(error)) {
|
|||
// See https://json-schema.org/draft/2020-12/json-schema-core#section-8.2, section
|
||||
// 8.2.1.
|
||||
|
||||
// TODO(jba): anchors (section 8.2.2)
|
||||
// TODO(jba): dynamicAnchors (ditto)
|
||||
// TODO(jba): dynamicAnchors (§8.2.2)
|
||||
//
|
||||
// Every schema has a base URI and a parent base URI.
|
||||
//
|
||||
|
|
@ -180,6 +179,18 @@ func resolveURIs(root *Schema, baseURI *url.URL) (map[string]*Schema, error) {
|
|||
base = s // needed for anchors
|
||||
}
|
||||
|
||||
// Anchors are URI fragments that are scoped to their base.
|
||||
// We treat them as keys in a map stored within the schema.
|
||||
if s.Anchor != "" {
|
||||
if base.anchors[s.Anchor] != nil {
|
||||
return fmt.Errorf("duplicate anchor %q in %s", s.Anchor, base.baseURI)
|
||||
}
|
||||
if base.anchors == nil {
|
||||
base.anchors = map[string]*Schema{}
|
||||
}
|
||||
base.anchors[s.Anchor] = s
|
||||
}
|
||||
|
||||
for c := range s.children() {
|
||||
if err := resolve(c, base); err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in a new issue