Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align metaschema-xslt with metaschema core #50

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/converter-gen/mvn-converters-xpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Usage: ${BASE_COMMAND:-$(basename "${BASH_SOURCE[0]}")} METASCHEMA_XML OUTPUT_DI
Produces XML-to-JSON and JSON-to-XML conversion transformations (XSLTs) from Metaschema XML source, using XML Calabash invoked from Maven.
Please install Maven first.

Additional arguments for XML Calabash should be specified in the `key=value` format.
Additional arguments for XML Calabash should be specified in the "key=value" format.
EOF
}

Expand All @@ -31,9 +31,9 @@ ADDITIONAL_ARGS=$(shift 3; echo "${*// /\\ }")

PIPELINE="${SCRIPT_DIR}/METASCHEMA-ALL-CONVERTERS.xpl"

XMLTOJSON_CONVERTER_FILE="${OUTPUT_DIR}/${SCHEMA_NAME}-xml-to-json.xsl"
XMLTOJSON_CONVERTER_FILE="${OUTPUT_DIR}/${SCHEMA_NAME}_xml-to-json-converter.xsl"

JSONTOXML_CONVERTER_FILE="${OUTPUT_DIR}/${SCHEMA_NAME}-json-to-xml.xsl"
JSONTOXML_CONVERTER_FILE="${OUTPUT_DIR}/${SCHEMA_NAME}_json-to-xml-converter.xsl"

CALABASH_ARGS="-iMETASCHEMA=\"$METASCHEMA_XML\" \
-oINT_0_echo-input=/dev/null \
Expand Down
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