Skip to content

Commit 31db28e

Browse files
author
Peter Amstutz
committed
Merge branch 'master' into type_dsl. Add test for typeDSL.
Conflicts: schema_salad/metaschema/metaschema.yml schema_salad/ref_resolver.py
2 parents 8072bf5 + 116d9e4 commit 31db28e

File tree

4 files changed

+242
-80
lines changed

4 files changed

+242
-80
lines changed

schema_salad/main.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,16 @@ def main(argsl=None): # type: (List[str]) -> int
9898
if not urlparse.urlparse(schema_uri)[0]:
9999
schema_uri = "file://" + os.path.abspath(schema_uri)
100100
schema_raw_doc = metaschema_loader.fetch(schema_uri)
101-
schema_doc, schema_metadata = metaschema_loader.resolve_all(
102-
schema_raw_doc, schema_uri)
101+
102+
try:
103+
schema_doc, schema_metadata = metaschema_loader.resolve_all(
104+
schema_raw_doc, schema_uri)
105+
except (validate.ValidationException) as e:
106+
_logger.error("Schema `%s` failed link checking:\n%s",
107+
args.schema, e, exc_info=(e if args.debug else False))
108+
_logger.debug("Index is %s", metaschema_loader.idx.keys())
109+
_logger.debug("Vocabulary is %s", metaschema_loader.vocab.keys())
110+
return 1
103111

104112
# Optionally print the schema after ref resolution
105113
if not args.document and args.print_pre:
@@ -110,16 +118,6 @@ def main(argsl=None): # type: (List[str]) -> int
110118
print(json.dumps(metaschema_loader.idx.keys(), indent=4))
111119
return 0
112120

113-
# Validate links in the schema document
114-
try:
115-
metaschema_loader.validate_links(schema_doc)
116-
except (validate.ValidationException) as e:
117-
_logger.error("Schema `%s` failed link checking:\n%s",
118-
args.schema, e, exc_info=(e if args.debug else False))
119-
_logger.debug("Index is %s", metaschema_loader.idx.keys())
120-
_logger.debug("Vocabulary is %s", metaschema_loader.vocab.keys())
121-
return 1
122-
123121
# Validate the schema document against the metaschema
124122
try:
125123
schema.validate_doc(metaschema_names, schema_doc,
@@ -196,16 +194,6 @@ def main(argsl=None): # type: (List[str]) -> int
196194
print(json.dumps(document_loader.idx.keys(), indent=4))
197195
return 0
198196

199-
# Validate links in the target document
200-
try:
201-
document_loader.validate_links(document)
202-
except (validate.ValidationException) as e:
203-
_logger.error("Document `%s` failed link checking:\n%s",
204-
args.document, e, exc_info=(e if args.debug else False))
205-
_logger.debug("Index is %s", json.dumps(
206-
document_loader.idx.keys(), indent=4))
207-
return 1
208-
209197
# Validate the schema document against the metaschema
210198
try:
211199
schema.validate_doc(avsc_names, document,

schema_salad/metaschema/metaschema.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,29 @@ $graph:
139139
the item is transformed to a JSON object with the key assigned to the
140140
field specified by `mapSubject` and the value assigned to the field
141141
specified by `mapPredicate`.
142+
- name: refScope
143+
type:
144+
- "null"
145+
- int
146+
doc: |
147+
If the field contains a relative reference, it must be resolved by
148+
searching for valid document references in each successive parent scope
149+
in the document fragment. For example, a reference of `foo` in the
150+
context `#foo/bar/baz` will first check for the existence of
151+
`#foo/bar/baz/foo`, followed by `#foo/bar/foo`, then `#foo/foo` and
152+
then finally `#foo`. The first valid URI in the search order shall be
153+
used as the fully resolved value of the identifier. The value of the
154+
refScope field is the specified number of levels from the containing
155+
identifer scope before starting the search, so if `refScope: 2` then
156+
"baz" and "bar" must be stripped to get the base `#foo` and search
157+
`#foo/foo` and the `#foo`. The last scope searched must be the top
158+
level scope before determining if the identifier cannot be resolved.
142159
- name: typeDSL
143160
type: ["null", boolean]
144161
doc: |
145162
Field must be expanded based on the the Schema Salad type DSL.
146163
164+
147165
- name: SpecializeDef
148166
type: record
149167
fields:
@@ -274,6 +292,7 @@ $graph:
274292
jsonldPredicate:
275293
_id: "sld:type"
276294
_type: "@vocab"
295+
typeDSL: true
277296
doc: |
278297
The field type
279298
@@ -305,7 +324,7 @@ $graph:
305324
jsonldPredicate:
306325
_id: "sld:type"
307326
_type: "@vocab"
308-
327+
typeDSL: true
309328
- name: "fields"
310329
type:
311330
- "null"
@@ -370,7 +389,7 @@ $graph:
370389
jsonldPredicate:
371390
_id: "sld:type"
372391
_type: "@vocab"
373-
392+
typeDSL: true
374393
- name: "symbols"
375394
type:
376395
- type: "array"
@@ -415,7 +434,7 @@ $graph:
415434
jsonldPredicate:
416435
_id: "sld:type"
417436
_type: "@vocab"
418-
437+
typeDSL: true
419438
- name: items
420439
type:
421440
- "#PrimitiveType"
@@ -454,3 +473,4 @@ $graph:
454473
jsonldPredicate:
455474
_id: "sld:type"
456475
_type: "@vocab"
476+
typeDSL: true

0 commit comments

Comments
 (0)