Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation refactor plus sprint22 metaschema #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 68 additions & 12 deletions build/metaschema/json/json-schema-metamap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<xsl:template match="/METASCHEMA" expand-text="true">
<map>
<string key="$schema">http://json-schema.org/draft-07/schema#</string>
<string key="$id">http://csrc.nist.gov/ns/oscal/{ $composed-metaschema/METASCHEMA/schema-version }/{ short-name }-schema.json</string>
<string key="$id">{ $composed-metaschema/METASCHEMA/namespace }-schema.json</string>
<xsl:for-each select="schema-name">
<string key="$comment">{ . }: JSON Schema</string>
</xsl:for-each>
Expand Down Expand Up @@ -66,6 +66,39 @@
</map>
</xsl:template>

<!-- Template entry point skipping the Metaschema composition step -->
<xsl:template mode="debug" match="/METASCHEMA" expand-text="true">
<map>
<string key="$schema">http://json-schema.org/draft-07/schema#</string>
<string key="$id">{ namespace }-schema.json</string>
<xsl:for-each select="schema-name">
<string key="$comment">{ . }: JSON Schema</string>
</xsl:for-each>

<xsl:apply-templates select="schema-version"/>
<string key="type">object</string>
<map key="definitions">
<xsl:apply-templates select="*"/>

<!--<map key="prose">
<xsl:call-template name="string-or-array-of-strings"/>
</map>-->
</map>
<map key="properties">
<!--<xsl:apply-templates mode="properties"/>-->
<map key="{@root}">
<string key="$ref">#/definitions/{ @root }</string>
</map>
</map>
<!--<map key="propertyNames">
<array key="enum">
<string>
<xsl:apply-templates mode="property-names"/></string>
</array>
</map>-->
</map>
</xsl:template>

<!--<xsl:template name="string-or-array-of-strings">
<array key="anyOf">
<map>
Expand Down Expand Up @@ -127,8 +160,16 @@
</xsl:template>

<xsl:template name="required-properties">
<!-- A value string is never required even on elements not empty -->
<xsl:variable name="requirements" as="element()*">
<!-- A value string is always required except on empty fields -->
<xsl:variable name="value-property">
<xsl:apply-templates select="self::define-field" mode="value-key"/>
</xsl:variable>
<xsl:for-each select="$value-property[matches(.,'\S')]">
<string>
<xsl:apply-templates/>
</string>
</xsl:for-each>
<xsl:apply-templates mode="property-name"
select="flag[@required = 'yes'][not((@name|@ref) = ../(json-key | json-value-key)/@flag-name)] |
model//*[@min-occurs &gt; 0]"/>
Expand Down Expand Up @@ -220,18 +261,18 @@
</string>
</xsl:template>

<xsl:template match="flag[exists(@name)]" mode="property-name">
<!--<xsl:template match="flag[exists(@name)]" mode="property-name">
<string>
<xsl:value-of select="@name"/>
</string>
</xsl:template>
</xsl:template>-->

<!-- Not yet implemented -->
<xsl:template match="any" mode="property-name"/>

<xsl:template match="prose" mode="property-name">
<!--<xsl:template match="prose" mode="property-name">
<string>prose</string>
</xsl:template>
</xsl:template>-->

<xsl:template match="model | choice" priority="2" mode="property-name">
<xsl:apply-templates mode="#current"/>
Expand All @@ -245,8 +286,6 @@
<xsl:if test="matches($this-key, '\S')">
<map key="{$this-key}">
<string key="type">string</string>
<!--
<xsl:call-template name="string-or-array-of-strings"/>-->
</map>
</xsl:if>
</xsl:template>
Expand Down Expand Up @@ -314,7 +353,7 @@
match="assembly[empty(@max-occurs) or number(@max-occurs) = 1 ] |
field[empty(@max-occurs) or number(@max-occurs)= 1 ]">
<map key="{@ref}">
<xsl:apply-templates select="key('definition-by-name', @ref)" mode="object-type"/>
<!--<xsl:apply-templates select="key('definition-by-name', @ref)" mode="object-type"/>-->
<string key="$ref">#/definitions/{ @ref }</string>
</map>
</xsl:template>
Expand Down Expand Up @@ -376,6 +415,23 @@
<string key="type">string</string>
</xsl:template>

<xsl:template name="string-or-array-of-strings">
<array key="oneOf">
<map>
<string key="type">string</string>
</map>
<map>
<string key="type">array</string>
<array key="items">
<map>
<string key="type">string</string>
</map>
</array>
<string key="minItems">2</string>
</map>
</array>
</xsl:template>

<xsl:template match="field | flag" priority="3" mode="object-type">
<xsl:choose>
<xsl:when test="exists(@as-type)">
Expand All @@ -397,7 +453,7 @@

<xsl:template priority="2" match="*[@as-type='integer']" mode="object-type">
<string key="type">integer</string>
<number key="multipleOf">1.0</number>
<!--<number key="multipleOf">1.0</number>-->
</xsl:template>

<xsl:template priority="2" match="*[@as-type='positiveInteger']" mode="object-type">
Expand Down Expand Up @@ -434,9 +490,9 @@
<xsl:variable name="datatypes" expand-text="false">
<map key="date-with-timezone">
<string key="type">string</string>
<string key="format">date</string>
<!--<string key="format">date</string>-->
<!--The xs:date with a required timezone.-->
<!--<string key="pattern">.+[:Z].*</string>-->
<string key="pattern">((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)|(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))|(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))|(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))(Z|[+-][0-9]{2}:[0-9]{2})</string>
</map>
<map key="dateTime-with-timezone">
<string key="type">string</string>
Expand Down
6 changes: 6 additions & 0 deletions build/metaschema/json/pull-datatypes.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<xsl:strip-space elements="*"/>

<xsl:preserve-space elements="documentation"/>

<!-- Utility XSLT -->
<!-- converts XSD from ../xml/oscal-datatypes.xsd into JSON Schema notation-->

<xsl:template match="schema">
Expand Down Expand Up @@ -68,4 +70,8 @@
<xsl:template match="pattern">
<string key="pattern">{ @value }</string>
</xsl:template>

<!--<xsl:template match="simpleType[@name=$known-types]" mode="cast-type">
<string key="pattern">((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)|(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))|(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))|(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))(Z|[+-][0-9]{2}:[0-9]{2})</string>
</xsl:template>-->
</xsl:stylesheet>
14 changes: 8 additions & 6 deletions build/metaschema/lib/metaschema-check.sch
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<xsl:key name="definition-by-name" match="m:define-assembly | m:define-field | m:define-flag" use="@name"/>
<xsl:key name="invocation-by-ref" match="m:assembly[exists(@ref)] | m:field[exists(@ref)] | m:flag[exists(@ref)]" use="@ref"/>
<xsl:key name="flags-by-name" match="m:define-flag | m:flag[@name]" use="@name"/>


<sch:ns uri="http://csrc.nist.gov/ns/oscal/metaschema/1.0" prefix="m"/>

Expand All @@ -41,10 +43,11 @@
<sch:assert test="exists(m:formal-name)">formal-name missing from <sch:name/></sch:assert>
<sch:assert test="exists(m:description)">description missing from <sch:name/></sch:assert>
<sch:assert test="empty(self::m:define-assembly) or exists(m:model)">model missing from <sch:name/></sch:assert>
<sch:assert test="empty(@address) or m:flag/@name=@address">Definition set to address by '<sch:value-of select="@address"/>', but no flag with that name is declared.</sch:assert>
<sch:assert test="not(@as-type='boolean') or empty(m:flag)">Property defined as boolean may not have flags.</sch:assert>
<sch:assert test="not(key('invocation-by-ref',@name)/m:group-as/@json-behavior='BY_KEY') or exists(m:json-key)"><sch:value-of select="substring-after(local-name(),
'define-')"/> is assigned a json key, but no 'json-key' is given</sch:assert>
<sch:report test="@name=('RICHTEXT','STRVALUE','PROSE')">Names "STRVALUE", "RICHTEXT" or "PROSE" (reserved names)</sch:report>

</sch:rule>

<sch:rule context="m:json-key">
Expand Down Expand Up @@ -84,12 +87,10 @@
<sch:assert test="empty(@ref) or exists($decl)" role="warning">No definition found for '<sch:value-of select="@ref"/>' <sch:value-of select="local-name()"/></sch:assert>
<sch:assert test="empty(@ref) or empty($decl) or empty(@datatype) or (@datatype = $decl/@datatype)" role="warning">Flag data type doesn't match: the definition has '<sch:value-of select="$decl/@datatype"/>'</sch:assert>
<sch:report test="@name=('RICHTEXT','STRVALUE','PROSE')">Flag should not be named "STRVALUE", "RICHTEXT" or "PROSE" (reserved names)</sch:report>
<sch:report test="@as-type != key('flags-by-name',@name,$composed-metaschema)/@as-type">Flag is declared with datatype '<sch:value-of select="@as-type"/>' while other flags with that name show datatype
<sch:value-of select="string-join(((key('flags-by-name',@name) except .)/@as-type ! ('''' || . || '''')),', ')"/></sch:report>
</sch:rule>

<sch:rule context="m:prose">
<sch:assert test="count(../m:prose) eq 1">Prose may not appear in more than once in a model</sch:assert>
</sch:rule>

<!-- 'choice' is not subjected to rules for other elements inside 'model' -->
<sch:rule context="m:choice"/>

Expand Down Expand Up @@ -118,7 +119,8 @@
<sqf:add target="group-as" node-type="element"><group-as name="{ $group-name }"/></sqf:add>

</sqf:fix>-->

<sch:assert test="not(@as-type='markup-multiline') or not(preceding-sibling/*/@as-type='markup-multiline')">Only one field may be marked
as 'markup-multiline' (without xml wrapping) within a model.</sch:assert>
</sch:rule>

<sch:rule context="m:group-as">
Expand Down
8 changes: 4 additions & 4 deletions build/metaschema/lib/metaschema-docs-util.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ function switch_view(who,flag) {
<!--<pre style="float:left">
<xsl:value-of select="serialize($pruned-tree, $serialization-settings/* )"/>
</pre>-->
<!--<pre>
<pre>
<xsl:value-of select="serialize($surrogate-tree, $serialization-settings/* )"/>
</pre>-->
</pre>


<xsl:variable name="html-rendering">
<xsl:apply-templates mode="html-render" select="$surrogate-tree"/>
</xsl:variable>
<div class="OM-map" style="float:left; width:40%">
<!--<div class="OM-map" style="float:left; width:40%">
<xsl:copy-of select="$html-rendering"/>
</div>
</div>-->
<div class="OM-map" style="float:right; width:40%">
<xsl:apply-templates select="$html-rendering/*" mode="elaborate"/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions build/metaschema/lib/metaschema-jsondocs-jekyll-uswds.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
<xsl:variable name="alt-schema" select="replace($metaschema-code,'-json$','-xml')"/>
<div style="float:right">
<a href="/OSCAL/docs/schemas/{ $alt-schema }/#{ $alt-schema }_{ @name}">
<button class="button-xml-on">XML</button>
<button class="button-xml-on">Switch to XML</button>
</a>
<button class="button-json-off" disabled="disabled">JSON</button>
<!--<button class="button-json-off" disabled="disabled">JSON</button>-->
</div>
</xsl:template>

Expand Down Expand Up @@ -339,7 +339,7 @@
<li>
<xsl:apply-templates mode="link-here" select="key('definitions',@ref)"/>
<xsl:if test="empty(@ref)">
<xsl:apply-templates select="@name"/>
<a id="{../@name}-{@name}"><xsl:apply-templates select="@name"/></a><xsl:apply-templates select="@name"/>
</xsl:if>
<xsl:text> property </xsl:text>
<xsl:apply-templates select="@as-type"/>
Expand Down
1 change: 0 additions & 1 deletion build/metaschema/lib/metaschema-jsonobject-map.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

<!--<xsl:variable name="home" select="/"/>-->


<!--<xsl:template name="jekyll-template">
<xsl:text>-\-\-&#xA;</xsl:text>
<xsl:text>title: Schema map test&#xA;</xsl:text>
Expand Down
7 changes: 3 additions & 4 deletions build/metaschema/lib/metaschema-xmldocs-jekyll-uswds.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@
<xsl:template name="cross-links">
<xsl:variable name="alt-schema" select="replace($metaschema-code,'-xml$','-json')"/>
<div style="float:right">
<button disabled="disabled" class="button-xml-off">XML</button>
<!--<button disabled="disabled" class="button-xml-off">XML</button>-->
<a href="/OSCAL/docs/schemas/{ $alt-schema }/#{ $alt-schema }_{ @name}">
<button class="button-json-on">JSON</button>
<button class="button-json-on">Switch to JSON</button>
</a>
</div>
</xsl:template>
Expand Down Expand Up @@ -232,8 +232,7 @@
<li>
<xsl:apply-templates mode="link-here" select="key('definitions',@ref)"/>
<xsl:if test="empty(@ref)">
<xsl:apply-templates select="@name"/>
</xsl:if>
<a id="{../@name}-{@name}"><xsl:apply-templates select="@name"/></a><xsl:apply-templates select="@name"/>
<xsl:text> attribute </xsl:text>
<xsl:apply-templates select="@required"/>
<xsl:if test="empty(@required)"> (<i>optional</i>)</xsl:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@
"title": "Plain text",
"description": "plain text, no markup",
"$id": "#/definitions/field-flag-plaintext",
"type": "object",
"properties": {
"length": {
"title": "Length",
"description": "The length.",
"type": "integer",
"minimum": 1
"minimum": 1,
"multipleOf": 1.0
},
"STRVALUE": {
"type": "string"
}
}
"STRVALUE": {"type": "string"}
},
"required": ["STRVALUE"],
"additionalProperties": false
},
"field-richtext": {
"title": "Rich text",
Expand All @@ -59,56 +61,46 @@
"title": "Rich text",
"description": "Rich text supports markup",
"$id": "#/definitions/field-flag-richtext",
"type": "object",
"properties": {
"length": {
"title": "Length",
"description": "The length.",
"type": "integer",
"multipleOf": 1.0,
"minimum": 1
},
"RICHTEXT": {
"type": "string"
}
}
"RICHTEXT": {"type": "string"}
},
"required": ["RICHTEXT"],
"additionalProperties": false
},
"field-prose": {
"title": "Prose",
"description": "Prose permits multiple paragraphs, lists, tables etc.",
"$id": "#/definitions/field-prose",
"oneOf": [
{"type": "string"},
{
"type": "array",
"items": {"type": "string"},
"minItems": 2
}
]
"type": "string"
},
"field-flag-prose": {
"title": "Prose",
"description": "Prose permits multiple paragraphs, lists, tables etc.",
"$id": "#/definitions/field-flag-prose",
"type" : "object",
"properties": {
"length": {
"title": "Length",
"description": "The length.",
"type": "integer",
"multipleOf": 1.0,
"minimum": 1
},
"PROSE": {
"oneOf": [
{"type": "string"},
{
"type": "array",
"items": {"type": "string"},
"minItems": 2
}
]
}
}
"PROSE": {"type": "string"}
},
"required": ["PROSE"],
"additionalProperties": false
}
},
"properties": {
"parent": {"$ref": "#/definitions/parent"}
}
}
}
Loading