Skip to content

Commit

Permalink
Align with upstream commits for anyOf issue and $schema property
Browse files Browse the repository at this point in the history
Upstream commits:
13cde791af0dc8682f7dd1532e36205ce968e20d and a36f579e1e30abb2263895242cdbd2cf4bd29513

Co-authored-by: Kyle Laker <[email protected]>
Co-authored-by: Alexander Stein <[email protected]>
  • Loading branch information
3 people committed Jul 24, 2023
1 parent 1faea47 commit 8e148dc
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/schema-gen/JSON-schema/make-json-schema-metamap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,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 All @@ -70,7 +77,6 @@
<xsl:template match="/METASCHEMA" mode="require-a-root">
<xsl:apply-templates select="define-assembly[exists(root-name)]" mode="root-requirement"/>
<boolean key="additionalProperties">false</boolean>
<number key="maxProperties">1</number>
</xsl:template>


Expand All @@ -80,14 +86,16 @@
<map>
<xsl:apply-templates select="." mode="root-requirement"/>
<boolean key="additionalProperties">false</boolean>
<number key="maxProperties">1</number>
</map>
</xsl:for-each>
</array>
</xsl:template>

<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 Expand Up @@ -207,7 +215,17 @@
<xsl:apply-templates select="$decl/constraint/allowed-values"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="exists($enumerations)">
<xsl:when test="exists($enumerations) and $decl/constraint/allowed-values/@allow-other = 'yes' and (constraint/allowed-values/@target = '.' or empty(constraint/allowed-values/@target))">
<array key="anyOf">
<map>
<xsl:apply-templates select="." mode="object-type"/>
</map>
<map>
<xsl:sequence select="$enumerations"/>
</map>
</array>
</xsl:when>
<xsl:when test="exists($enumerations) and (constraint/allowed-values/@target = '.' or empty(constraint/allowed-values/@target))">
<array key="allOf">
<map>
<xsl:apply-templates select="." mode="object-type"/>
Expand Down

0 comments on commit 8e148dc

Please sign in to comment.