-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change XSLT JSON Schema gen to allow $schema directive (#384)
* Allow $schema in XSLT-generated JSON schemas For #383, allow $schema so JSON schemas that are emitted by the XSLT-M4 implementation allow downstream consumers to optionally bind schema references into a document instances and not immediately invalidate the schema. * Remove maxProperties for #385. * Update pre-existing and new tests for #383. Do not just compare the XML-based syntax tree of whole JSON schemas. * Update .gitignore per @wendellpiez feedback. * Add code comment per @wendellpiez feedback. Explain why we test with contains() and not matching the full field name in the updated XSpec tests and try to reduce flakiness.
- Loading branch information
1 parent
13cde79
commit a36f579
Showing
13 changed files
with
225 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ node_modules/ | |
# Ignore go files | ||
/build/vendor/ | ||
|
||
# Ignore XSpec reports and temp directories | ||
xspec/ | ||
*report.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test-suite/metaschema-xspec/json-schema-gen/schema_directive_imported1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/css" href="metaschema-author.css"?> | ||
<METASCHEMA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../../../schema/xml/metaschema.xsd" | ||
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0" abstract="no"> | ||
<schema-name>JSON value testing mini metaschema</schema-name> | ||
<schema-version>0.1</schema-version> | ||
<short-name>schema-directive-imported1</short-name> | ||
<namespace>http://csrc.nist.gov/ns/metaschema-tests/1.0</namespace> | ||
<json-base-uri>http://csrc.nist.gov/ns/metaschema-tests</json-base-uri> | ||
<import href="schema_directive_imported.xml"/> | ||
<define-assembly name="root1"> | ||
<formal-name>Root</formal-name> | ||
<description>Example root to test for schema directive in the imported module.</description> | ||
<root-name>root1</root-name> | ||
</define-assembly> | ||
</METASCHEMA> |
17 changes: 17 additions & 0 deletions
17
test-suite/metaschema-xspec/json-schema-gen/schema_directive_imported2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/css" href="metaschema-author.css"?> | ||
<METASCHEMA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../../../schema/xml/metaschema.xsd" | ||
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0" abstract="no"> | ||
<schema-name>JSON value testing mini metaschema</schema-name> | ||
<schema-version>0.1</schema-version> | ||
<short-name>schema-directive-imported2</short-name> | ||
<namespace>http://csrc.nist.gov/ns/metaschema-tests/1.0</namespace> | ||
<json-base-uri>http://csrc.nist.gov/ns/metaschema-tests</json-base-uri> | ||
<import href="schema_directive_imported.xml"/> | ||
<define-assembly name="root2"> | ||
<formal-name>Root</formal-name> | ||
<description>Example root to test for schema directive in the imported module.</description> | ||
<root-name>root2</root-name> | ||
</define-assembly> | ||
</METASCHEMA> |
63 changes: 63 additions & 0 deletions
63
test-suite/metaschema-xspec/json-schema-gen/schema_directive_importing.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "http://csrc.nist.gov/ns/metaschema-tests/0.1/schema-directive-no-imports-schema.json", | ||
"$comment": "JSON value testing mini metaschema: JSON Schema", | ||
"type": "object", | ||
"definitions": { | ||
"json-schema-directive": { | ||
"title": "Schema Directive", | ||
"description": "A JSON Schema directive to bind a specific schema to its document instance.", | ||
"$id": "#json-schema-directive", | ||
"$ref": "#/definitions/URIReferenceDatatype" | ||
}, | ||
"schema-directive-no-imports-schema-directive-imported1:root1": { | ||
"title": "Root", | ||
"description": "Example root to test for schema directive in the imported module.", | ||
"$id": "#assembly_schema-directive-imported1_root1", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"schema-directive-no-imports-schema-directive-imported2:root2": { | ||
"title": "Root", | ||
"description": "Example root to test for schema directive in the imported module.", | ||
"$id": "#assembly_schema-directive-imported2_root2", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"URIReferenceDatatype": { | ||
"description": "A URI Reference, either a URI or a relative-reference, formatted according to section 4.1 of RFC3986.", | ||
"type": "string", | ||
"format": "uri-reference" | ||
} | ||
}, | ||
"oneOf": [ | ||
{ | ||
"properties": { | ||
"$schema": { | ||
"$ref": "#json-schema-directive" | ||
}, | ||
"root1": { | ||
"$ref": "#assembly_schema-directive-imported1_root1" | ||
} | ||
}, | ||
"required": [ | ||
"root1" | ||
], | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"properties": { | ||
"$schema": { | ||
"$ref": "#json-schema-directive" | ||
}, | ||
"root2": { | ||
"$ref": "#assembly_schema-directive-imported2_root2" | ||
} | ||
}, | ||
"required": [ | ||
"root2" | ||
], | ||
"additionalProperties": false | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
test-suite/metaschema-xspec/json-schema-gen/schema_directive_importing.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/css" href="metaschema-author.css"?> | ||
<METASCHEMA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../../../schema/xml/metaschema.xsd" | ||
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0" abstract="no"> | ||
<schema-name>JSON value testing mini metaschema</schema-name> | ||
<schema-version>0.1</schema-version> | ||
<short-name>schema-directive-no-imports</short-name> | ||
<namespace>http://csrc.nist.gov/ns/metaschema-tests/1.0</namespace> | ||
<json-base-uri>http://csrc.nist.gov/ns/metaschema-tests</json-base-uri> | ||
<import href="schema_directive_imported1.xml"/> | ||
<import href="schema_directive_imported2.xml"/> | ||
</METASCHEMA> |
4 changes: 4 additions & 0 deletions
4
test-suite/metaschema-xspec/json-schema-gen/schema_directive_importing_PASS1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "schema_directive_importing.json", | ||
"root1": {} | ||
} |
3 changes: 3 additions & 0 deletions
3
test-suite/metaschema-xspec/json-schema-gen/schema_directive_importing_PASS2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"root2": {} | ||
} |
38 changes: 38 additions & 0 deletions
38
test-suite/metaschema-xspec/json-schema-gen/schema_directive_no-imports.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "http://csrc.nist.gov/ns/metaschema-tests/0.1/schema-directive-no-imports-schema.json", | ||
"$comment": "JSON value testing mini metaschema: JSON Schema", | ||
"type": "object", | ||
"definitions": { | ||
"json-schema-directive": { | ||
"title": "Schema Directive", | ||
"description": "A JSON Schema directive to bind a specific schema to its document instance.", | ||
"$id": "#json-schema-directive", | ||
"$ref": "#/definitions/URIReferenceDatatype" | ||
}, | ||
"schema-directive-no-imports-schema-directive-no-imports:root": { | ||
"title": "Root", | ||
"description": "Example root to test for schema directive in simple module.", | ||
"$id": "#assembly_schema-directive-no-imports_root", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"URIReferenceDatatype": { | ||
"description": "A URI Reference, either a URI or a relative-reference, formatted according to section 4.1 of RFC3986.", | ||
"type": "string", | ||
"format": "uri-reference" | ||
} | ||
}, | ||
"properties": { | ||
"$schema": { | ||
"$ref": "#json-schema-directive" | ||
}, | ||
"root": { | ||
"$ref": "#assembly_schema-directive-no-imports_root" | ||
} | ||
}, | ||
"required": [ | ||
"root" | ||
], | ||
"additionalProperties": false | ||
} |
16 changes: 16 additions & 0 deletions
16
test-suite/metaschema-xspec/json-schema-gen/schema_directive_no-imports.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/css" href="metaschema-author.css"?> | ||
<METASCHEMA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../../../schema/xml/metaschema.xsd" | ||
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0" abstract="no"> | ||
<schema-name>JSON value testing mini metaschema</schema-name> | ||
<schema-version>0.1</schema-version> | ||
<short-name>schema-directive-no-imports</short-name> | ||
<namespace>http://csrc.nist.gov/ns/metaschema-tests/1.0</namespace> | ||
<json-base-uri>http://csrc.nist.gov/ns/metaschema-tests</json-base-uri> | ||
<define-assembly name="root"> | ||
<formal-name>Root</formal-name> | ||
<description>Example root to test for schema directive in simple module.</description> | ||
<root-name>root</root-name> | ||
</define-assembly> | ||
</METASCHEMA> |
4 changes: 4 additions & 0 deletions
4
test-suite/metaschema-xspec/json-schema-gen/schema_directive_no-imports_PASS1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "schema_directive_no-imports.json", | ||
"root": {} | ||
} |
3 changes: 3 additions & 0 deletions
3
test-suite/metaschema-xspec/json-schema-gen/schema_directive_no-imports_PASS2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"root": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters