Skip to content

Commit

Permalink
Try to compose metaschema inline with togglable param.
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-stein-nist committed Jan 17, 2023
1 parent 69b2ed3 commit f9571d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
stylesheet="../../../toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl"
run-as="external" xmlns:ov="http://csrc.nist.gov/ns/oscal/test/variable">

<!--<x:param name="compose-metaschema-first">true()</x:param>-->

<x:scenario label="When generating a JSON schema from composed Metaschema definitions">
<x:scenario label="if it has a defined field with no constraint and no allowed-values">
<x:context href="json-value-testing-mini-metaschema-COMPOSED.xml"
<x:context href="json-value-testing-mini-metaschema.xml"
select="/*/m:define-field[@name='unconstrained']"/>
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions">
<map key="oscal-value-testing-mini-oscal-value-testing-mini:unconstrained">
Expand All @@ -35,7 +37,7 @@
</x:scenario>

<x:scenario label="if it has a defined field with a constraint, allowed-values, strict enforcement of allow-other='no' and explicit target of '.'">
<x:context href="json-value-testing-mini-metaschema-COMPOSED.xml"
<x:context href="json-value-testing-mini-metaschema.xml"
select="/*/m:define-field[@name='constrained-closed']"/>
<x:expect label="the resulting JSON Schema should have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions">
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-closed">
Expand Down Expand Up @@ -74,7 +76,7 @@
</x:scenario>

<x:scenario label="if it has a defined field with a constraint, allowed-values, no explicit target, and permissive enforcement of allow-other='yes'">
<x:context href="json-value-testing-mini-metaschema-COMPOSED.xml"
<x:context href="json-value-testing-mini-metaschema.xml"
select="/*/m:define-field[@name='constrained-open']"/>
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions">
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-open">
Expand Down Expand Up @@ -113,7 +115,7 @@
</x:scenario>

<x:scenario label="if it has a defined field with a constraint, allowed-values, strict enforcement of allow-other='no' and explicit target other than '.'">
<x:context href="json-value-testing-mini-metaschema-COMPOSED.xml"
<x:context href="json-value-testing-mini-metaschema.xml"
select="/*/m:define-field[@name='constrained-narrow']"/>
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions">
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-narrow">
Expand All @@ -140,7 +142,7 @@
</x:scenario>

<x:scenario label="if it has a defined field with a constraint, allowed-values, permissive enforcement of allow-other='yes' and explicit target other than '.'">
<x:context href="json-value-testing-mini-metaschema-COMPOSED.xml"
<x:context href="json-value-testing-mini-metaschema.xml"
select="/*/m:define-field[@name='constrained-sortof']"/>
<x:expect label="the resulting JSON Schema should not have an enum to enforce it." xmlns="http://www.w3.org/2005/xpath-functions">
<map key="oscal-value-testing-mini-oscal-value-testing-mini:constrained-sortof">
Expand Down
20 changes: 18 additions & 2 deletions toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math"
xmlns:nm="http://csrc.nist.gov/ns/metaschema"
version="3.0" xmlns="http://www.w3.org/2005/xpath-functions"
xpath-default-namespace="http://csrc.nist.gov/ns/oscal/metaschema/1.0" expand-text="true">

Expand All @@ -15,9 +16,23 @@
<xsl:strip-space elements="METASCHEMA define-assembly define-field model"/>

<xsl:output indent="yes" method="xml"/>


<!-- This parameter controls whether this transform will compose the source metaschema as part of running this
stylesheet in standalone mode for debugging. In the CI and CD pipelines for production, this is unusual and
not desired, so this parameter is not enabled by default and set to false(). For unit testing and local debug
scenarios, you will want this so you do not save intermediate "composed" metaschemas needed for JSON Schema
generation, so with Oxygen, Saxon on the CLI, or Saxon via API you would set this to `true()`. -->
<xsl:param name="compose-metaschema-first" select="true()"/>

<xsl:template match="/" priority="2">
<xsl:apply-templates/>
<xsl:choose>
<xsl:when test="$compose-metaschema-first = true()">
<xsl:sequence select="nm:compose-metaschema(/)"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:variable name="home" select="/"/>
Expand All @@ -31,6 +46,7 @@
<xsl:key name="flag-definition-by-name" match="METASCHEMA/define-flag" use="@_key-name"/>

<xsl:import href="../nist-metaschema-COMPOSE.xsl"/>

<xsl:variable name="composed-metaschema" select="/"/>

<xsl:template match="/METASCHEMA" expand-text="true">
Expand Down

0 comments on commit f9571d6

Please sign in to comment.