-
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.
Adapt test suite approach per PR feedback.
- Loading branch information
1 parent
31093a8
commit b6e5f89
Showing
12 changed files
with
513 additions
and
259 deletions.
There are no files selected for viewing
165 changes: 16 additions & 149 deletions
165
test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec
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 |
---|---|---|
@@ -1,171 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- autogenerated 2021-12-14T16:02:57.305-05:00 following model in example-set.xspec--> | ||
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" | ||
xmlns:m="http://csrc.nist.gov/ns/oscal/metaschema/1.0" | ||
xmlns:j="http://www.w3.org/2005/xpath-functions" | ||
stylesheet="../../../toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl" | ||
run-as="external" xmlns:ov="http://csrc.nist.gov/ns/oscal/test/variable"> | ||
|
||
<!--<x:param name="compose-metaschema-first">true()</x:param>--> | ||
stylesheet="../../../toolchains/xslt-M4/nist-metaschema-MAKE-JSON-SCHEMA.xsl" run-as="external"> | ||
|
||
<x:scenario label="When generating a JSON schema from composed Metaschema definitions"> | ||
<x:scenario label="if it has a defined field with no constraint and no allowed-values"> | ||
<x:context href="json-value-testing-mini-metaschema.xml" | ||
select="/*/m:define-field[@name='unconstrained']"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions"> | ||
<map key="oscal-value-testing-mini-oscal-value-testing-mini:unconstrained"> | ||
<string key="title">Unconstrained</string> | ||
<string key="description">A field whose value is constrained only by its nominal datatype, 'token'.</string> | ||
<string key="$id">#field_oscal-value-testing-mini_unconstrained</string> | ||
<string key="type">object</string> | ||
<map key="properties"> | ||
<map key="some"> | ||
<string key="title">Some Flag</string> | ||
<string key="description">Some flag some flag some flag.</string> | ||
<string key="$ref">#/definitions/StringDatatype</string> | ||
</map> | ||
<map key="token-value"> | ||
<string key="$ref">#/definitions/TokenDatatype</string> | ||
</map> | ||
</map> | ||
<array key="required"> | ||
<string>token-value</string> | ||
</array> | ||
<boolean key="additionalProperties">false</boolean> | ||
</map> | ||
</x:expect> | ||
<x:context href="json-value_unconstrained_metaschema.xml"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." | ||
test="$x:result => j:json-to-xml()" select="'../json-value_unconstrained.json' => j:unparsed-text() => j:json-to-xml()"/> | ||
</x:scenario> | ||
|
||
<x:scenario label="if it has a defined field with a constraint, allowed-values, strict enforcement of allow-other='no' and explicit target of '.'"> | ||
<x:context href="json-value-testing-mini-metaschema.xml" | ||
select="/*/m:define-field[@name='constrained-closed']"/> | ||
<x:expect label="the resulting JSON Schema should have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions"> | ||
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-closed"> | ||
<string key="title">Constrained closed</string> | ||
<string key="description">Because allow-other is 'no' an enumeration can be given in the JSON Schema.</string> | ||
<string key="$id">#field_oscal-value-testing-mini_constrained-closed</string> | ||
<string key="type">object</string> | ||
<map key="properties"> | ||
<map key="some"> | ||
<string key="title">Some Flag</string> | ||
<string key="description">Some flag some flag some flag.</string> | ||
<string key="$ref">#/definitions/StringDatatype</string> | ||
</map> | ||
<map key="token-value"> | ||
<array key="allOf"> | ||
<map> | ||
<string key="$ref">#/definitions/TokenDatatype</string> | ||
</map> | ||
<map> | ||
<array key="enum"> | ||
<string>one</string> | ||
<string>two</string> | ||
<string>three</string> | ||
<string>four</string> | ||
</array> | ||
</map> | ||
</array> | ||
</map> | ||
</map> | ||
<array key="required"> | ||
<string>token-value</string> | ||
</array> | ||
<boolean key="additionalProperties">false</boolean> | ||
</map> | ||
</x:expect> | ||
<x:context href="json-value_constrained-closed_metaschema.xml"/> | ||
<x:expect label="the resulting JSON Schema should have an enum to enforce it." | ||
test="$x:result => j:json-to-xml()" select="'../json-value_constrained-closed.json' => j:unparsed-text() => j:json-to-xml()"/> | ||
</x:scenario> | ||
|
||
<x:scenario label="if it has a defined field with a constraint, allowed-values, no explicit target, and permissive enforcement of allow-other='yes'"> | ||
<x:context href="json-value-testing-mini-metaschema.xml" | ||
select="/*/m:define-field[@name='constrained-open']"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions"> | ||
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-open"> | ||
<string key="title">Constrained open</string> | ||
<string key="description">Because allow-other is 'yes' no enumeration can be given in the JSON Schema.</string> | ||
<string key="$id">#field_oscal-value-testing-mini_constrained-open</string> | ||
<string key="type">object</string> | ||
<map key="properties"> | ||
<map key="some"> | ||
<string key="title">Some Flag</string> | ||
<string key="description">Some flag some flag some flag.</string> | ||
<string key="$ref">#/definitions/StringDatatype</string> | ||
</map> | ||
<map key="token-value"> | ||
<array key="anyOf"> | ||
<map> | ||
<string key="$ref">#/definitions/TokenDatatype</string> | ||
</map> | ||
<map> | ||
<array key="enum"> | ||
<string>one</string> | ||
<string>two</string> | ||
<string>three</string> | ||
<string>four</string> | ||
</array> | ||
</map> | ||
</array> | ||
</map> | ||
</map> | ||
<array key="required"> | ||
<string>token-value</string> | ||
</array> | ||
<boolean key="additionalProperties">false</boolean> | ||
</map> | ||
</x:expect> | ||
<x:context href="json-value_constrained-open_metaschema.xml"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." | ||
test="$x:result => j:json-to-xml()" select="'../json-value_constrained-open.json' => j:unparsed-text() => j:json-to-xml()"/> | ||
</x:scenario> | ||
|
||
<x:scenario label="if it has a defined field with a constraint, allowed-values, strict enforcement of allow-other='no' and explicit target other than '.'"> | ||
<x:context href="json-value-testing-mini-metaschema.xml" | ||
select="/*/m:define-field[@name='constrained-narrow']"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions"> | ||
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-narrow"> | ||
<string key="title">Constrained narrow</string> | ||
<string key="description">Although allow-other is 'no' an enumeration can't be given in the JSON Schema since it targets a qualified set (only a subset) of the elements in scope.</string> | ||
<string key="$id">#field_oscal-value-testing-mini_constrained-narrow</string> | ||
<string key="type">object</string> | ||
<map key="properties"> | ||
<map key="some"> | ||
<string key="title">Some Flag</string> | ||
<string key="description">Some flag some flag some flag.</string> | ||
<string key="$ref">#/definitions/StringDatatype</string> | ||
</map> | ||
<map key="token-value"> | ||
<string key="$ref">#/definitions/TokenDatatype</string> | ||
</map> | ||
</map> | ||
<array key="required"> | ||
<string>token-value</string> | ||
</array> | ||
<boolean key="additionalProperties">false</boolean> | ||
</map> | ||
</x:expect> | ||
<x:context href="json-value_constrained-narrow_metaschema.xml"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." | ||
test="$x:result => j:json-to-xml()" select="'../json-value_constrained-narrow.json' => j:unparsed-text() => j:json-to-xml()"/> | ||
</x:scenario> | ||
|
||
<x:scenario label="if it has a defined field with a constraint, allowed-values, permissive enforcement of allow-other='yes' and explicit target other than '.'"> | ||
<x:context href="json-value-testing-mini-metaschema.xml" | ||
select="/*/m:define-field[@name='constrained-sortof']"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions"> | ||
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-sortof"> | ||
<string key="title">Constrained, sort of</string> | ||
<string key="description">Although allow-other is 'no' an enumeration can't be given in the JSON Schema since it targets a qualified set (only a subset) of the elements in scope.</string> | ||
<string key="$id">#field_oscal-value-testing-mini_constrained-sortof</string> | ||
<string key="type">object</string> | ||
<map key="properties"> | ||
<map key="some"> | ||
<string key="title">Some Flag</string> | ||
<string key="description">Some flag some flag some flag.</string> | ||
<string key="$ref">#/definitions/StringDatatype</string> | ||
</map> | ||
<map key="token-value"> | ||
<string key="$ref">#/definitions/TokenDatatype</string> | ||
</map> | ||
</map> | ||
<array key="required"> | ||
<string>token-value</string> | ||
</array> | ||
<boolean key="additionalProperties">false</boolean> | ||
</map> | ||
</x:expect> | ||
<x:context href="json-value_constrained-sortof_metaschema.xml"/> | ||
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." | ||
test="$x:result => j:json-to-xml()" select="'../json-value_constrained-sortof.json' => j:unparsed-text() => j:json-to-xml()"/> | ||
</x:scenario> | ||
</x:scenario> | ||
</x:description> |
110 changes: 0 additions & 110 deletions
110
test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-closed.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,70 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "http://csrc.nist.gov/ns/metaschema-tests/0.1/json-schema-value-test-constrained-closed-schema.json", | ||
"$comment": "JSON value testing mini metaschema: JSON Schema", | ||
"type": "object", | ||
"definitions": { | ||
"json-schema-value-test-constrained-closed-json-schema-value-test-constrained-closed:root": { | ||
"title": "Root", | ||
"description": "Root root root.", | ||
"$id": "#assembly_json-schema-value-test-constrained-closed_root", | ||
"type": "object", | ||
"properties": { | ||
"constrained-closed": { | ||
"$ref": "#field_json-schema-value-test-constrained-closed_constrained-closed" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"json-schema-value-test-constrained-closed-json-schema-value-test-constrained-closed:constrained-closed": { | ||
"title": "Constrained closed", | ||
"description": "Because allow-other is 'no' an enumeration can be given in the JSON Schema.", | ||
"$id": "#field_json-schema-value-test-constrained-closed_constrained-closed", | ||
"type": "object", | ||
"properties": { | ||
"some": { | ||
"title": "Some Flag", | ||
"description": "Some flag some flag some flag.", | ||
"$ref": "#/definitions/StringDatatype" | ||
}, | ||
"token-value": { | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/TokenDatatype" | ||
}, | ||
{ | ||
"enum": [ | ||
"one", | ||
"two", | ||
"three", | ||
"four" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"token-value" | ||
], | ||
"additionalProperties": false | ||
}, | ||
"StringDatatype": { | ||
"type": "string", | ||
"pattern": "^\\S(.*\\S)?$" | ||
}, | ||
"TokenDatatype": { | ||
"type": "string", | ||
"pattern": "^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$" | ||
} | ||
}, | ||
"properties": { | ||
"root": { | ||
"$ref": "#assembly_json-schema-value-test-constrained-closed_root" | ||
} | ||
}, | ||
"required": [ | ||
"root" | ||
], | ||
"additionalProperties": false, | ||
"maxProperties": 1 | ||
} |
Oops, something went wrong.