Skip to content

Commit

Permalink
Transform generates suggestive anyOf for allow-other='yes'.
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-stein-nist committed Jan 6, 2023
1 parent 7970db8 commit de0a6bd
Showing 1 changed file with 12 additions and 121 deletions.
133 changes: 12 additions & 121 deletions toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
<xsl:key name="field-definition-by-name" match="METASCHEMA/define-field" use="@_key-name"/>
<xsl:key name="flag-definition-by-name" match="METASCHEMA/define-flag" use="@_key-name"/>

<!--Keys for retrieving datatypes:
<xsl:key name="typename-for-syntax"
-->

<!--Produces composed metaschema (imports resolved)-->
<xsl:import href="../nist-metaschema-COMPOSE.xsl"/>
<xsl:variable name="composed-metaschema" select="/"/>

Expand Down Expand Up @@ -241,9 +236,6 @@

<xsl:template match="remarks | example"/>

<!-- No restriction is introduced when allow others is 'yes' -->
<xsl:template match="allowed-values[@allow-other='yes']"/>

<!--<xsl:template match="allowed-values"/>-->
<xsl:template match="allowed-values">
<array key="enum">
Expand Down Expand Up @@ -301,24 +293,6 @@
</boolean>
</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="*" mode="text-property"/>

<xsl:template match="define-field" mode="text-property">
Expand Down Expand Up @@ -371,6 +345,16 @@
<xsl:apply-templates select="." mode="object-type"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="constraint/allowed-values/@allow-other = 'yes' and (constraint/allowed-values/@target = '.' or empty(constraint/allowed-values/@target))">
<array key="anyOf">
<map>
<xsl:sequence select="$nominal-object-type"/>
</map>
<map>
<xsl:apply-templates select="constraint/allowed-values"/>
</map>
</array>
</xsl:when>
<xsl:when test="constraint/allowed-values/@allow-other = 'no' and (constraint/allowed-values/@target = '.' or empty(constraint/allowed-values/@target))">
<array key="allOf">
<map>
Expand All @@ -388,44 +372,6 @@
</map>
</xsl:if>
</xsl:template>

<!-- A collapsible field is represented as an object containing
a string or an array of strings
turned off for now until we reinstate collapsing into conversion scripts (2020-09-21) -->
<!--<xsl:template match="define-field[@collapsible='yes']" mode="properties">
<!-\-<xsl:variable name="json-key-flag" select="json-key/@flag-ref"/>
<xsl:apply-templates mode="declaration" select="flag[not(@ref = $json-key-flag)], define-flag[not(@name = $json-key-flag)]"/>-\->
<xsl:apply-templates mode="define" select="flag | define-flag"/>
<xsl:variable name="this-key" as="xs:string?">
<xsl:apply-templates select="." mode="value-key"/>
</xsl:variable>
<xsl:if test="matches($this-key, '\S')">
<map key="{$this-key}">
<array key="anyOf">
<map><string key="type">string</string></map>
<map>
<string key="type">array</string>
<map key="items">
<string key="type">string</string>
</map>
<number key="minItems">1</number><!-\- See Issue #536 -\->
</map>
</array>
</map>
</xsl:if>
</xsl:template>-->

<!--<xsl:template priority="2" mode="property-name" match="assembly">
<xsl:apply-templates mode="#current" select="key('assembly-definition-by-name',@_key-ref)"/>
</xsl:template>
<xsl:template priority="2" mode="property-name" match="field">
<xsl:apply-templates mode="#current" select="key('field-definition-by-name',@_key-ref)"/>
</xsl:template>
<xsl:template priority="2" mode="property-name" match="flag">
<xsl:apply-templates mode="#current" select="key('flag-definition-by-name',@_key-ref)"/>
</xsl:template>-->

<xsl:template priority="2" mode="property-name" match="define-field | define-assembly | define-flag | assembly | field | flag" expand-text="true">
<string>{ @_in-json-name }</string>
Expand All @@ -440,7 +386,6 @@

<!--A flag declared as a key or value key gets no declaration since it
will not show up in the JSON as a separate property -->

<xsl:template mode="define" priority="5" match="define-flag[@name=../(json-value-key-flag|json-key)/@flag-ref] |
flag[@ref=../(json-value-key-flag|json-key)/@flag-ref]"/>

Expand Down Expand Up @@ -683,73 +628,19 @@

<xsl:variable name="datatypes" expand-text="false">
<xsl:copy-of xpath-default-namespace="http://www.w3.org/2005/xpath-functions" select="( unparsed-text($json-datatypes-path) => json-to-xml() )/map/map[@key='definitions']/map"/>

<!-- Some old datatype names are preserved for backward compatibility -->
<!-- see ../../../schema/xml/metaschema.xsd line 1052 inside /*/xs:simpleType[@name='SimpleDatatypesType']> -->

<!--<map key="decimal"><!-\- DecimalDatatype -\->
<string key="type">number</string>
<!-\-<string key="pattern">^(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)$</string>-\->
</map>
<map key="date"><!-\- DateDatatype -\->
<string key="type">string</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"><!-- DateTimeDatatype -->
<string key="type">string</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))T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})?$</string>
</map>
<!--<map key="date-with-timezone"><!-\- DateWithTimezoneDatatype -\->
<string key="type">string</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"><!-- DateTimeWithTimezoneDatatype -->
<map key="dateTime-with-timezone">
<string key="type">string</string>
<string key="format">date-time</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))T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$</string>
</map>
<map key="email"><!-- EmailAddressDatatype -->
<map key="email">
<string key="type">string</string>
<string key="format">email</string>
<string key="pattern">^.+@.+$</string>
</map>
<!--<map key="ip-v4-address"><!-\- IPV4AddressDatatype -\->
<string key="type">string</string>
<string key="format">ipv4</string>
<string key="pattern">^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]).){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$</string>
</map>
<map key="ip-v6-address"><!-\- IPV6AddressDatatype -\->
<string key="type">string</string>
<string key="format">ipv6</string>
<string key="pattern">^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|[fF][eE]80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::([fF]{4}(:0{1,4}){0,1}:){0,1}((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]).){3,3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]).){3,3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]))$</string>
</map>
<map key="hostname"><!-\- HostnameDatatype -\->
<string key="$ref">#/definitions/StringDatatype</string>
<string key="format">idn-hostname</string>
</map>
<map key="uri"><!-\- URIDatatype -\->
<string key="type">string</string>
<string key="format">uri</string>
<string key="pattern">^[a-zA-Z][a-zA-Z0-9+\-.]+:.+$</string>
</map>
<map key="uri-reference"><!-\- URIReferenceDatatype -\->
<string key="type">string</string>
<string key="format">uri-reference</string>
</map>
<map key="uuid"><!-\- UUIDDatatype -\->
<string key="type">string</string>
<string key="description">A type 4 ('random' or 'pseudorandom') or type 5 UUID per RFC 4122.</string>
<string key="pattern">^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$</string>
</map>
<map xmlns="http://www.w3.org/2005/xpath-functions" key="token"><!-\- TokenDatatype -\->
<string key="type">string</string>
<string key="pattern">^(\p{L}|_)(\p{L}|\p{N}|[.\-_])*$</string>
</map>
<map key="string">
<string key="type">string</string>
<string key="pattern">^\S(.*\S)?$</string>
</map>-->
</xsl:variable>

</xsl:stylesheet>

0 comments on commit de0a6bd

Please sign in to comment.