From 0c6d0fa660da009733d7f0336d26544fa575a588 Mon Sep 17 00:00:00 2001 From: Wendell Piez Date: Thu, 13 Oct 2022 16:56:26 -0400 Subject: [PATCH] Start at modeling out tests for JSON Schema provision of enumerated value constraints (where possible) #240 --- .../json-schema-gen/json-schema-gen.xspec | 23 +++ ...lue-testing-mini-jsonschema-CORRECTED.json | 116 +++++++++++ ...ue-testing-mini-jsonschema-CORRECTED2.json | 112 +++++++++++ .../json-value-testing-mini-jsonschema.json | 126 ++++++++++++ .../json-value-testing-mini-metaschema.xml | 186 ++++++++++++++++++ .../json-schema-gen/testing01-valid.json | 24 +++ .../json-schema-gen/testing02-valid.json | 8 + .../json-schema-gen/testing03-valid.json | 24 +++ .../json-schema-gen/testing04-INVALID.json | 8 + .../json-schema-gen/testing05-valid.json | 24 +++ .../json-schema-gen/testing06-INVALID.json | 12 ++ 11 files changed, 663 insertions(+) create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED2.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml create mode 100644 test-suite/metaschema-xspec/json-schema-gen/testing01-valid.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/testing02-valid.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/testing03-valid.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/testing04-INVALID.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/testing05-valid.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/testing06-INVALID.json diff --git a/test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec b/test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec new file mode 100644 index 000000000..3a61c2e9f --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec @@ -0,0 +1,23 @@ + + + + + + + + + + + diff --git a/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED.json b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED.json new file mode 100644 index 000000000..1b2175745 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED.json @@ -0,0 +1,116 @@ + { "$schema" : "http://json-schema.org/draft-07/schema#", + "$id" : "http://csrc.nist.gov/ns/oscal/0.1/oscal-value-testing-mini-schema.json", + "$comment" : "JSON value testing mini metaschema: JSON Schema", + "type" : "object", + "definitions" : + { "oscal-value-testing-mini-oscal-value-testing-mini:root" : + { "title" : "Root", + "description" : "Root root root.", + "$id" : "#assembly_oscal-value-testing-mini_root", + "type" : "object", + "properties" : + { "unconstrained" : + { "$ref" : "#field_oscal-value-testing-mini_unconstrained" }, + "constrained-open" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-open" }, + "constrained-closed" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-closed" }, + "constrained-narrow" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-narrow" }, + "constrained-sortof" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-sortof" } }, + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:unconstrained" : + { "title" : "Unconstrained", + "description" : "A field whose value is constrained only by its nominal datatype, 'token'.", + "$id" : "#field_oscal-value-testing-mini_unconstrained", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-open" : + { "title" : "Constrained open", + "description" : "Because allow-other is 'yes' no enumeration can be given in the JSON Schema.", + "$id" : "#field_oscal-value-testing-mini_constrained-open", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-closed" : + { "title" : "Constrained closed", + "description" : "Because allow-other is 'no' an enumeration can be given in the JSON Schema.", + "$id" : "#field_oscal-value-testing-mini_constrained-closed", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string", + "enum" : + [ "one", + "two", + "three", + "four" ] } }, + "required" : + [ "token-value" ], + "additionalProperties" : false + }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-narrow" : + { "title" : "Constrained narrow", + "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.", + "$id" : "#field_oscal-value-testing-mini_constrained-narrow", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-sortof" : + { "title" : "Constrained, sort of", + "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.", + "$id" : "#field_oscal-value-testing-mini_constrained-sortof", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "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_oscal-value-testing-mini_root" } }, + "required" : + [ "root" ], + "additionalProperties" : false, + "maxProperties" : 1 } \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED2.json b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED2.json new file mode 100644 index 000000000..03ec73487 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema-CORRECTED2.json @@ -0,0 +1,112 @@ + { "$schema" : "http://json-schema.org/draft-07/schema#", + "$id" : "http://csrc.nist.gov/ns/oscal/0.1/oscal-value-testing-mini-schema.json", + "$comment" : "JSON value testing mini metaschema: JSON Schema", + "type" : "object", + "definitions" : + { "oscal-value-testing-mini-oscal-value-testing-mini:root" : + { "title" : "Root", + "description" : "Root root root.", + "$id" : "#assembly_oscal-value-testing-mini_root", + "type" : "object", + "properties" : + { "unconstrained" : + { "$ref" : "#field_oscal-value-testing-mini_unconstrained" }, + "constrained-open" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-open" }, + "constrained-closed" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-closed" }, + "constrained-narrow" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-narrow" }, + "constrained-sortof" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-sortof" } }, + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:unconstrained" : + { "title" : "Unconstrained", + "description" : "A field whose value is constrained only by its nominal datatype, 'token'.", + "$id" : "#field_oscal-value-testing-mini_unconstrained", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "$ref" : "#/definitions/TokenDatatype" + } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-open" : + { "title" : "Constrained open", + "description" : "Because allow-other is 'yes' no enumeration can be given in the JSON Schema.", + "$id" : "#field_oscal-value-testing-mini_constrained-open", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "$ref" : "#/definitions/TokenDatatype" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-closed" : + { "title" : "Constrained closed", + "description" : "Because allow-other is 'no' an enumeration can be given in the JSON Schema.", + "$id" : "#field_oscal-value-testing-mini_constrained-closed", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "$ref" : "#/definitions/TokenDatatype" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false + }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-narrow" : + { "title" : "Constrained narrow", + "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.", + "$id" : "#field_oscal-value-testing-mini_constrained-narrow", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "$ref" : "#/definitions/TokenDatatype" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-sortof" : + { "title" : "Constrained, sort of", + "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.", + "$id" : "#field_oscal-value-testing-mini_constrained-sortof", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "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_oscal-value-testing-mini_root" } }, + "required" : + [ "root" ], + "additionalProperties" : false, + "maxProperties" : 1 } \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema.json b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema.json new file mode 100644 index 000000000..424d2cfa5 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema.json @@ -0,0 +1,126 @@ + + { "$schema" : "http://json-schema.org/draft-07/schema#", + "$id" : "http://csrc.nist.gov/ns/oscal/0.1/oscal-value-testing-mini-schema.json", + "$comment" : "JSON value testing mini metaschema: JSON Schema", + "type" : "object", + "definitions" : + { "oscal-value-testing-mini-oscal-value-testing-mini:root" : + { "title" : "Root", + "description" : "Root root root.", + "$id" : "#assembly_oscal-value-testing-mini_root", + "type" : "object", + "properties" : + { "unconstrained" : + { "$ref" : "#field_oscal-value-testing-mini_unconstrained" }, + "constrained-open" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-open" }, + "constrained-closed" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-closed" }, + "constrained-narrow" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-narrow" }, + "constrained-sortof" : + { "$ref" : "#field_oscal-value-testing-mini_constrained-sortof" } }, + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:unconstrained" : + { "title" : "Unconstrained", + "description" : "A field whose value is constrained only by its nominal datatype, 'token'.", + "$id" : "#field_oscal-value-testing-mini_unconstrained", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-open" : + { "title" : "Constrained open", + "description" : "Because allow-other is 'yes' no enumeration can be given in the JSON Schema.", + "$id" : "#field_oscal-value-testing-mini_constrained-open", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-closed" : + { "title" : "Constrained closed", + "description" : "Because allow-other is 'no' an enumeration can be given in the JSON Schema.", + "$id" : "#field_oscal-value-testing-mini_constrained-closed", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false, + "enum" : + [ "one", + "two", + "three", + "four" ] }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-narrow" : + { "title" : "Constrained narrow", + "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.", + "$id" : "#field_oscal-value-testing-mini_constrained-narrow", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false, + "enum" : + [ "one", + "two", + "three", + "four" ] }, + "oscal-value-testing-mini-oscal-value-testing-mini:constrained-sortof" : + { "title" : "Constrained, sort of", + "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.", + "$id" : "#field_oscal-value-testing-mini_constrained-sortof", + "type" : "object", + "properties" : + { "some" : + { "title" : "Some Flag", + "description" : "Some flag some flag some flag.", + "$ref" : "#/definitions/StringDatatype" }, + "token-value" : + { "type" : "string" } }, + "required" : + [ "token-value" ], + "additionalProperties" : false, + "enum" : + [ "one", + "two", + "three", + "four" ] }, + "StringDatatype" : + { "type" : "string", + "pattern" : "^\\S(.*\\S)?$" }, + "TokenDatatype" : + { "type" : "string", + "pattern" : "^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$" } }, + "properties" : + { "root" : + { "$ref" : "#assembly_oscal-value-testing-mini_root" } }, + "required" : + [ "root" ], + "additionalProperties" : false, + "maxProperties" : 1 } \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml new file mode 100644 index 000000000..420d11183 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml @@ -0,0 +1,186 @@ + + + + JSON value testing mini metaschema + 0.1 + oscal-value-testing-mini + http://csrc.nist.gov/ns/oscal/1.0 + http://csrc.nist.gov/ns/oscal + + + + + Root + Root root root. + root + + + + + + + + + + + + + + + + + Unconstrained + A field whose value is constrained only by its nominal datatype, 'token'. + token-value + + Some Flag + Some flag some flag some flag. + + + + + + Constrained open + Because allow-other is 'yes' no enumeration can be given in the JSON Schema. + token-value + + Some Flag + Some flag some flag some flag. + + + + + + + Constrained closed + Because allow-other is 'no' an enumeration can be given in the JSON Schema. + token-value + + Some Flag + Some flag some flag some flag. + + + + + + + + + + + + + + Constrained narrow + 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. + token-value + + Some Flag + Some flag some flag some flag. + + + + + + + + + + + + + + Constrained, sort of + 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. + token-value + + Some Flag + Some flag some flag some flag. + + + + + + + + + + + + + + diff --git a/test-suite/metaschema-xspec/json-schema-gen/testing01-valid.json b/test-suite/metaschema-xspec/json-schema-gen/testing01-valid.json new file mode 100644 index 000000000..764870fa2 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/testing01-valid.json @@ -0,0 +1,24 @@ +{ + "root": { + "unconstrained": { + "some": "a", + "token-value": "any" + }, + "constrained-open": { + "some": "b", + "token-value": "one" + }, + "constrained-closed": { + "some": "c", + "token-value": "two" + }, + "constrained-narrow": { + "some": "d", + "token-value": "three" + }, + "constrained-sortof": { + "some": "e", + "token-value": "four" + } + } +} \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/testing02-valid.json b/test-suite/metaschema-xspec/json-schema-gen/testing02-valid.json new file mode 100644 index 000000000..188047ffc --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/testing02-valid.json @@ -0,0 +1,8 @@ +{ + "root": { + "unconstrained": { + "some": "a", + "token-value": "anything" + } + } +} \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/testing03-valid.json b/test-suite/metaschema-xspec/json-schema-gen/testing03-valid.json new file mode 100644 index 000000000..a69802130 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/testing03-valid.json @@ -0,0 +1,24 @@ +{ + "root": { + "unconstrained": { + "some": "a", + "token-value": "any" + }, + "constrained-open": { + "some": "b", + "token-value": "one" + }, + "constrained-closed": { + "some": "c", + "token-value": "three" + }, + "constrained-narrow": { + "some": "d", + "token-value": "three" + }, + "constrained-sortof": { + "some": "e", + "token-value": "four" + } + } +} \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/testing04-INVALID.json b/test-suite/metaschema-xspec/json-schema-gen/testing04-INVALID.json new file mode 100644 index 000000000..c19e4829e --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/testing04-INVALID.json @@ -0,0 +1,8 @@ +{ + "root": { + "constrained-closed": { + "some": "c", + "token-value": "FIVE" + } + } +} \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/testing05-valid.json b/test-suite/metaschema-xspec/json-schema-gen/testing05-valid.json new file mode 100644 index 000000000..5e0fc39f5 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/testing05-valid.json @@ -0,0 +1,24 @@ +{ + "root": { + "unconstrained": { + "some": "a", + "token-value": "any" + }, + "constrained-open": { + "some": "b", + "token-value": "old" + }, + "constrained-closed": { + "some": "c", + "token-value": "three" + }, + "constrained-narrow": { + "some": "d", + "token-value": "value" + }, + "constrained-sortof": { + "some": "e", + "token-value": "works" + } + } +} \ No newline at end of file diff --git a/test-suite/metaschema-xspec/json-schema-gen/testing06-INVALID.json b/test-suite/metaschema-xspec/json-schema-gen/testing06-INVALID.json new file mode 100644 index 000000000..b43f7a3f5 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/testing06-INVALID.json @@ -0,0 +1,12 @@ +{ + "root": { + "unconstrained": { + "some": "a", + "token-value": "any OLD" + }, + "constrained-open": { + "some": "b", + "token-value": "STRING value" + } + } +} \ No newline at end of file