Skip to content

Commit

Permalink
Added support for Metaschema module imports in meta constraints that …
Browse files Browse the repository at this point in the history
…will allow for more flexible organization of constraints in multiple files. Fixed metapaths in module constraints.
  • Loading branch information
david-waltermire committed Jul 24, 2024
1 parent 85e4a72 commit 9c17646
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
14 changes: 7 additions & 7 deletions schema/metaschema/metaschema-module-constraints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<context>
<metapath target="/METASCHEMA"/>
<constraints>
<let var="all-imports" expression="recurse-depth('doc(resolve-uri(import/@href))/METASCHEMA')"/>
<let var="all-imports" expression="recurse-depth('for $import in ./import return doc(resolve-uri($import/@href))/METASCHEMA')"/>
<index id="module-short-name-unique" target="(.|$all-imports)" name="metaschema-metadata-short-name-index">
<formal-name>Index Module Short Names</formal-name>
<description>Ensures that the current and all imported modules have a unique short name.</description>
Expand All @@ -20,18 +20,18 @@
</expect>
<expect id="module-top-level-root-required" level="WARNING"
target=".[not(@abstract) or @abstract='no']"
test="$all-imports/define-assembly/root-name">
test="exists($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>
</expect>
<is-unique id="module-namespace-unique-entry" target="namespace">
<is-unique id="module-namespace-unique-entry" target="namespace-binding">
<formal-name>Require Unique Namespace Entries</formal-name>
<description>Ensures that all declared namespace entries are unique.</description>
<key-field target="@prefix"/>
<key-field target="@uri"/>
</is-unique>
<is-unique id="module-namespace-unique-prefix" target="namespace">
<is-unique id="module-namespace-unique-prefix" target="namespace-binding">
<formal-name>Require Unique Namespace Entry Prefixes</formal-name>
<description>Ensures that all declared namespace entries have a unique prefix.</description>
<key-field target="@prefix"/>
Expand All @@ -54,7 +54,7 @@
<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"
<expect id="metaschema-deprecated-types" level="WARNING"
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>
Expand All @@ -66,13 +66,13 @@
<context>
<metapath target="/metaschema-meta-constraints"/>
<constraints>
<is-unique id="meta-constraints-namespace-unique-entry" target="namespace">
<is-unique id="meta-constraints-namespace-unique-entry" target="namespace-binding">
<formal-name>Require Unique Namespace Entries</formal-name>
<description>Ensures that all declared namespace entries are unique.</description>
<key-field target="@prefix"/>
<key-field target="@uri"/>
</is-unique>
<is-unique id="meta-constraints-namespace-unique-prefix" target="namespace">
<is-unique id="meta-constraints-namespace-unique-prefix" target="namespace-binding">
<formal-name>Require Unique Namespace Entry Prefixes</formal-name>
<description>Ensures that all declared namespace entries have a unique prefix.</description>
<key-field target="@prefix"/>
Expand Down
8 changes: 8 additions & 0 deletions schema/metaschema/metaschema-module-metaschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,14 @@
<description>Defines constraint rules to be applied to an existing set of Metaschema module-based models.</description>
<root-name>metaschema-meta-constraints</root-name>
<model>
<define-assembly name="import" max-occurs="unbounded">
<description>Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.</description>
<group-as name="imports" in-json="ARRAY"/>
<define-flag name="href" as-type="uri-reference" required="yes">
<description>A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition.</description>
</define-flag>
</define-assembly>

<assembly ref="metapath-namespace" max-occurs="unbounded">
<group-as name="namespace-bindings" />
</assembly>
Expand Down
20 changes: 10 additions & 10 deletions schema/metaschema/sarif-module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</assembly>
</model>
<constraint>
<expect target="." test="@ruleIndex &gt;= -1">
<expect target="." test="@ruleIndex >= -1">
<message>The value '{ . }' is not greater than or equal to '-1'.</message>
</expect>
<!-- TODO: unique relatedLocations -->
Expand Down Expand Up @@ -264,7 +264,7 @@
</define-field>
</model>
<constraint>
<expect target="." test="@id|text">
<expect target="." test="exists(@id|text)">
<message>At least one id or text must be provided.</message>
</expect>
</constraint>
Expand All @@ -281,7 +281,7 @@
<formal-name>Index</formal-name>
<description>The index within the run artifacts array of the artifact object associated with the artifact location.</description>
<constraint>
<expect target="." test="@id &gt;= -1">
<expect target="." test="@id >= -1">
<message>The index '{ . }' is not greater than or equal to '-1'.</message>
</expect>
</constraint>
Expand Down Expand Up @@ -315,7 +315,7 @@
</assembly>
</model>
<constraint>
<expect target="." test="@id &gt;= -1">
<expect target="." test="@id >= -1">
<message>The id '{ . }' is not greater than or equal to '-1'.</message>
</expect>
<!-- TODO: unique relatedLocations -->
Expand Down Expand Up @@ -344,7 +344,7 @@
</assembly>
</model>
<constraint>
<expect target="." test="address|artifactLocation">
<expect target="." test="exists(address|artifactLocation)">
<message>At least one address or artifactLocation must be provided.</message>
</expect>
</constraint>
Expand All @@ -361,7 +361,7 @@
<formal-name>Index</formal-name>
<description>The index within the logical locations array.</description>
<constraint>
<expect target="." test="@id &gt;= -1">
<expect target="." test="@id >= -1">
<message>The index '{ . }' is not greater than or equal to '-1'.</message>
</expect>
</constraint>
Expand All @@ -378,7 +378,7 @@
<formal-name>Parent Index</formal-name>
<description>Identifies the index of the immediate parent of the construct in which the result was detected. For example, this property might point to a logical location that represents the namespace that holds a type.</description>
<constraint>
<expect target="." test="@id &gt;= -1">
<expect target="." test="@id >= -1">
<message>The index '{ . }' is not greater than or equal to '-1'.</message>
</expect>
</constraint>
Expand Down Expand Up @@ -417,7 +417,7 @@
<formal-name>Character Offset</formal-name>
<description>The zero-based offset from the beginning of the artifact of the first character in the region.</description>
<constraint>
<expect target="." test="@id &gt;= -1">
<expect target="." test="@id >= -1">
<message>The offset '{ . }' is not greater than or equal to '-1'.</message>
</expect>
</constraint>
Expand All @@ -432,7 +432,7 @@
<formal-name>Byte Offset</formal-name>
<description>The zero-based offset from the beginning of the artifact of the first byte in the region</description>
<constraint>
<expect target="." test="@id &gt;= -1">
<expect target="." test="@id >= -1">
<message>The offset '{ . }' is not greater than or equal to '-1'.</message>
</expect>
</constraint>
Expand All @@ -449,7 +449,7 @@
</assembly>
</model>
<constraint>
<expect target="." test="startLine|charOffset|byteOffset">
<expect target="." test="exists(startLine|charOffset|byteOffset)">
<message>At least a startLine, charOffset, or byteOffset must be provided.</message>
</expect>
</constraint>
Expand Down

0 comments on commit 9c17646

Please sign in to comment.