From 71233f4eb6854e820c7949144e86afa4d7981b22 Mon Sep 17 00:00:00 2001 From: Alexander Stein Date: Wed, 9 Nov 2022 20:54:19 -0500 Subject: [PATCH] Fix JSON Schema generation for usnistgov/metaschema#240 and add tests. --- .../json-schema-gen/json-schema-gen.xspec | 157 +++++++++++ .../json-value-testing-mini-jsonschema.json | 121 +++++++++ ...value-testing-mini-metaschema-COMPOSED.xml | 244 ++++++++++++++++++ .../json-value-testing-mini-metaschema.xml | 187 ++++++++++++++ .../schema-gen/make-json-schema-metamap.xsl | 40 +-- 5 files changed, 733 insertions(+), 16 deletions(-) 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.json create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema-COMPOSED.xml create mode 100644 test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml 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..cabd29c44 --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec @@ -0,0 +1,157 @@ + + + + + + + + + + Unconstrained + A field whose value is constrained only by its nominal datatype, 'token'. + #field_oscal-value-testing-mini_unconstrained + object + + + Some Flag + Some flag some flag some flag. + #/definitions/StringDatatype + + + #/definitions/TokenDatatype + + + + token-value + + false + + + + + + + + + Constrained closed + Because allow-other is 'no' an enumeration can be given in the JSON Schema. + #field_oscal-value-testing-mini_constrained-closed + object + + + Some Flag + Some flag some flag some flag. + #/definitions/StringDatatype + + + + + #/definitions/TokenDatatype + + + + one + two + three + four + + + + + + + token-value + + false + + + + + + + + + Constrained open + Because allow-other is 'yes' no enumeration can be given in the JSON Schema. + #field_oscal-value-testing-mini_constrained-open + object + + + Some Flag + Some flag some flag some flag. + #/definitions/StringDatatype + + + #/definitions/TokenDatatype + + + + token-value + + false + + + + + + + + + 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. + #field_oscal-value-testing-mini_constrained-narrow + object + + + Some Flag + Some flag some flag some flag. + #/definitions/StringDatatype + + + #/definitions/TokenDatatype + + + + token-value + + false + + + + + + + + + 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. + #field_oscal-value-testing-mini_constrained-sortof + object + + + Some Flag + Some flag some flag some flag. + #/definitions/StringDatatype + + + #/definitions/TokenDatatype + + + + token-value + + false + + + + + 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..88d74fdab --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-jsonschema.json @@ -0,0 +1,121 @@ + + { "$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 }, + "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-COMPOSED.xml b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema-COMPOSED.xml new file mode 100644 index 000000000..6f0e831fe --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema-COMPOSED.xml @@ -0,0 +1,244 @@ + + + Seeing assembly#oscal-value-testing-mini:root, field#oscal-value-testing-mini:unconstrained, field#oscal-value-testing-mini:constrained-open, field#oscal-value-testing-mini:constrained-closed, field#oscal-value-testing-mini:constrained-narrow, field#oscal-value-testing-mini:constrained-sortof + 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/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..f6f3fa30f --- /dev/null +++ b/test-suite/metaschema-xspec/json-schema-gen/json-value-testing-mini-metaschema.xml @@ -0,0 +1,187 @@ + + + + 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/toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl b/toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl index adf166264..a49102056 100644 --- a/toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl +++ b/toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl @@ -31,19 +31,13 @@ - - - - + + + + @@ -169,8 +163,7 @@ - - + @@ -200,8 +193,6 @@ - - @@ -256,7 +247,7 @@ - + @@ -376,7 +367,24 @@ - string + + + + + + + + + + + + + + + + + +