Skip to content

Commit

Permalink
Allow $schema in XSLT-generated JSON schemas
Browse files Browse the repository at this point in the history
For usnistgov#383, allow $schema so JSON schemas that are
emitted by the XSLT-M4 implementation allow downstream consumers to
optionally bind schema references into a document instances and not
immediately invalidate the schema.
  • Loading branch information
aj-stein-nist committed Jun 26, 2023
1 parent 13cde79 commit 9629356
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@

<string key="type">object</string>
<map key="definitions">
<map key="json-schema-directive">
<string key="title">Schema Directive</string>
<string key="description">A JSON Schema directive to bind a specific schema to its document instance.</string>
<string key="$id">#json-schema-directive</string>
<string key="$ref">#/definitions/URIReferenceDatatype</string>
</map>
<xsl:apply-templates select="define-assembly | define-field"/>

<xsl:variable name="all-used-types" select="//@as-type => distinct-values()"/>
<xsl:variable name="schema-directive-type" select="'uri-reference'"/>
<xsl:variable name="all-used-types" select="(//@as-type, $schema-directive-type) => distinct-values()"/>
<xsl:variable name="used-atomic-types" select="$datatype-map[@as-type = $all-used-types]"/>
<xsl:variable name="invoked-atomic-types" select="$used-atomic-types/key('datatypes-by-name',string(.),$datatypes)"/>
<xsl:variable name="referenced-types" select="$invoked-atomic-types//*:string[@key='$ref']/substring-after(.,'#/definitions/') ! key('datatypes-by-name',string(.),$datatypes)"/>
Expand Down Expand Up @@ -75,6 +82,9 @@

<xsl:template match="define-assembly" mode="root-requirement">
<map key="properties">
<map key="$schema">
<string key="$ref">#json-schema-directive</string>
</map>
<map key="{root-name}">
<xsl:apply-templates select="." mode="make-ref"/>
</map>
Expand Down

0 comments on commit 9629356

Please sign in to comment.