Skip to content

Commit

Permalink
Added back legacy data types removed in usnistgov#561 and usnistgov#562
Browse files Browse the repository at this point in the history
… to restore use of these types, which are used in OSCAL. Refactored module constraints to fix Metapath errors. Removed keyword checks in names added by usnistgov#542, which is not needed, since these names are allowed.
  • Loading branch information
david-waltermire committed Jul 24, 2024
1 parent 5ec4066 commit 7df6b6b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
54 changes: 34 additions & 20 deletions schema/metaschema/metaschema-module-constraints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
<description>Ensures that the current and all imported modules have a unique short name.</description>
<key-field target="@short-name"/>
</index>
<expect id="module-top-level-version-required" target=".[not(@abstract) or @abstract='yes']" test="@version">
<formal-name>Require Version for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have a version specified.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have a version.</message>
<expect id="module-top-level-version-required" level="WARNING"
target=".[not(@abstract) or @abstract='no']"
test="schema-version">
<formal-name>Require Schema Version for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have a schema version specified.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have a schema version.</message>
</expect>
<expect id="module-top-level-root-required" target=".[not(@abstract) or @abstract='yes']" test="define-assembly/root-name">
<expect id="module-top-level-root-required" level="WARNING"
target=".[not(@abstract) or @abstract='no']"
test="$all-imports/define-assembly/root-name">
<formal-name>Require Root Assembly for Top-Level Modules</formal-name>
<description>A top-level module, a module that is not marked as @abstract='yes', must have at least one assembly with a root-name.</description>
<message>Unless marked as @abstract='yes', a Metaschema module (or an imported module) should have at least one assembly with a root-name.</message>
Expand All @@ -32,22 +36,32 @@
<description>Ensures that all declared namespace entries have a unique prefix.</description>
<key-field target="@prefix"/>
</is-unique>
<expect id="module-import-href-available" target="import" test="doc-available(resolve-uri(@href))">
<formal-name>Import is Resolvable</formal-name>
<description>Ensure each import has a resolvable @href.</description>
<message>Unable to access a Metaschema module at '{{ resolve-uri(@href) }}'.</message>
</expect>
<expect id="module-import-href-is-module" target="import" test="doc(resolve-uri(@href))/METASCHEMA ! exists(.)">
<formal-name>Import is a Metaschema module</formal-name>
<description>Ensure each import is a Metaschema module.</description>
<message>Unable the resource at '{{ resolve-uri(@href) }}' is not a Metaschema module.</message>
</expect>
</constraints>
</context>
<context>
<metapath target="/METASCHEMA"/>
<metapath target="/metaschema-meta-constraints"/>
<metapath target="/metaschema-module-constraints"/>
<constraints>
<let var="deprecated-type-map" expression="map { 'base64Binary':'base64','dateTime':'date-time','dateTime-with-timezone':'date-time-with-timezone','email':'email-address','nonNegativeInteger':'non-negative-integer','positiveInteger':'positive-integer' }"/>
<expect id="metaschema-deprecated-types"
target=".//matches/@datatype|.//(define-field|define-flag)/@as-type"
test="not(.=('base64Binary','dateTime','dateTime-with-timezone','email','nonNegativeInteger','positiveInteger'))">
<formal-name>Avoid Deprecated Data Type Use</formal-name>
<description>Ensure that the data type specified is not one of the legacy Metaschema data types which have been deprecated (i.e. base64Binary, dateTime, dateTime-with-timezone, email, nonNegativeInteger, positiveInteger).</description>
<message>Use of the type '{ . }' is deprecated. Use '{ $deprecated-type-map(.)}' instead.</message>
</expect>
</constraints>
<context>
<metapath target="import"/>
<constraints>
<expect id="module-import-href-available" target="." test="document-available(resolve-uri(import/@href))">
<formal-name>Import is Resolvable</formal-name>
<description>Ensure each import has a resolvable @href.</description>
<message>Unable to access a Metaschema module at '{{ resolve-uri(@href) }}'.</message>
</expect>
<expect id="module-import-href-is-module" target="." test="doc(resolve-uri(import/@href))/METASCHEMA ! exists(.)">
<formal-name>Import is Resolvable</formal-name>
<description>Ensure each import is a Metaschema module.</description>
<message>Unable the resource at '{{ resolve-uri(@href) }}' is not a Metaschema module.</message>
</expect>
</constraints>
</context>
</context>
<context>
<metapath target="/metaschema-meta-constraints"/>
Expand Down
26 changes: 13 additions & 13 deletions schema/metaschema/metaschema-module-metaschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@
</define-assembly>
</choice-group>
</model>
<constraint>
<let var="keywords" expression="'ancestor', 'ancestor-or-self', 'and', 'as', 'attribute', 'cast', 'castable', 'child', 'comment', 'descendant', 'descendant-or-self', 'div', 'document-node', 'element', 'else', 'empty-sequence', 'eq', 'every', 'except', 'following', 'following-sibling', 'for', 'function', 'ge', 'gt', 'idiv', 'if', 'in', 'instance', 'intersect', 'is', 'item', 'le', 'let', 'lt', 'mod', 'namespace', 'namespace-node', 'ne', 'node', 'of', 'or', 'parent', 'preceding', 'preceding-sibling', 'processing-instruction', 'return', 'satisfies', 'schema-attribute', 'schema-element', 'self', 'some', 'text', 'then', 'to', 'treat', 'union'"/>
</constraint>
</define-assembly>

<define-assembly name="metapath-namespace">
Expand Down Expand Up @@ -642,11 +639,6 @@
<define-flag name="definition-name" as-type="token">
<formal-name>Definition Name</formal-name>
<use-name>name</use-name>
<constraint>
<expect level="WARNING" test="not(.=$keywords)">
<message>Names cannot be non-delimiting terminal symbols in Metapath syntax.</message>
</expect>
</constraint>
</define-flag>

<define-flag name="definition-reference" as-type="token">
Expand Down Expand Up @@ -702,6 +694,12 @@
<enum value="uri"/>
<enum value="uri-reference"/>
<enum value="uuid"/>
<enum value="base64Binary" deprecated="1.0.0"/>
<enum value="dateTime" deprecated="1.0.0"/>
<enum value="dateTime-with-timezone" deprecated="1.0.0"/>
<enum value="email" deprecated="1.0.0"/>
<enum value="nonNegativeInteger" deprecated="1.0.0"/>
<enum value="positiveInteger" deprecated="1.0.0"/>
</allowed-values>
</constraint>
</define-flag>
Expand Down Expand Up @@ -731,6 +729,13 @@
<enum value="uri"/>
<enum value="uri-reference"/>
<enum value="uuid"/>

<enum value="base64Binary" deprecated="1.0.0"/>
<enum value="dateTime" deprecated="1.0.0"/>
<enum value="dateTime-with-timezone" deprecated="1.0.0"/>
<enum value="email" deprecated="1.0.0"/>
<enum value="nonNegativeInteger" deprecated="1.0.0"/>
<enum value="positiveInteger" deprecated="1.0.0"/>
</allowed-values>
</constraint>
</define-flag>
Expand Down Expand Up @@ -804,11 +809,6 @@
<description>Allows the name of the definition to be overridden.</description>
<json-value-key>name</json-value-key>
<flag ref="alt-name-index"/>
<constraint>
<expect level="WARNING" target="." test="not(.=$keywords)">
<message>Names cannot be non-delimiting terminal symbols in Metapath syntax.</message>
</expect>
</constraint>
</define-field>

<define-flag name="alt-name-index" as-type="non-negative-integer">
Expand Down
8 changes: 8 additions & 0 deletions schema/xml/metaschema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,14 @@
<xs:enumeration value="uri"/>
<xs:enumeration value="uri-reference"/>
<xs:enumeration value="uuid"/>

<!-- deprecated names to remove -->
<xs:enumeration value="base64Binary"/>
<xs:enumeration value="dateTime"/>
<xs:enumeration value="dateTime-with-timezone"/>
<xs:enumeration value="email"/>
<xs:enumeration value="nonNegativeInteger"/>
<xs:enumeration value="positiveInteger"/>
</xs:restriction>
</xs:simpleType>

Expand Down

0 comments on commit 7df6b6b

Please sign in to comment.