Skip to content

Commit

Permalink
Use anyOf when @allow-other = 'yes' in JSON Schema
Browse files Browse the repository at this point in the history
When there is a type and an enumeration in JSON Schema, using `allOf`
means that a value must satisfy _both_ types. This is appropriate when
`@allow-other = 'no'` because it effectively limits the permitted values
to the enumeration; however, when `@allow-other = 'yes'`, that
limitation means that you are not able to use 'locally defined' values.
In this case, `anyOf` is preferable, this allows values in the
enumeration and otherwise any value that matches the schema for the
type.

A check is added explicitly for `@allow-other = 'yes'` as
`@allow-other = 'no'` is the default and matches the existing behavior.
  • Loading branch information
laurelmay committed May 3, 2023
1 parent 7008554 commit 6fb8a74
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@
<xsl:apply-templates select="$decl/constraint/allowed-values"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="exists($enumerations) and $decl/constraint/allowed-values/@allow-other = 'yes'">
<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)">
<array key="allOf">
<map>
Expand Down

0 comments on commit 6fb8a74

Please sign in to comment.