Skip to content

Commit

Permalink
Overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Apr 18, 2024
1 parent 0834067 commit f6b2bf5
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
1 change: 0 additions & 1 deletion tools/V4-CSDL-to-OpenAPI.xsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" xmlns:edm="http://docs.oasis-open.org/odata/ns/edm"
xmlns:p0="http://docs.oasis-open.org/odata/ns/edm/non-final-segments"
xmlns:p1="http://docs.oasis-open.org/odata/ns/edm/final-segment"
xmlns:p2="http://docs.oasis-open.org/odata/ns/edm/termcast-segment">

Expand Down
93 changes: 88 additions & 5 deletions tools/resolve-paths.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:p0="http://docs.oasis-open.org/odata/ns/edm/non-final-segments"
xmlns:p1="http://docs.oasis-open.org/odata/ns/edm/final-segment"
xmlns:p2="http://docs.oasis-open.org/odata/ns/edm/termcast-segment"
xmlns:p3="http://docs.oasis-open.org/odata/ns/edm/after-termcast-segment"
exclude-result-prefixes="edm">
<xsl:strip-space elements="*" />
<xsl:output doctype-system="csdl-ext.dtd" method="xml"
Expand Down Expand Up @@ -395,10 +396,13 @@
<xsl:call-template name="name">
<xsl:with-param name="qname" select="$term" />
</xsl:call-template>
<xsl:if test="contains($final-segment,'/')">
<xsl:value-of select="concat('/',$final-segment)" />
</xsl:if>
</xsl:attribute>
<xsl:if test="contains($final-segment,'/')">
<xsl:attribute name="p3:{name()}">
<xsl:value-of
select="substring-after($final-segment,'/')" />
</xsl:attribute>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="p1:{name()}">
Expand Down Expand Up @@ -427,10 +431,31 @@
select="substring-before(substring-after($q,'Collection('),')')" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="contains($q,'(')" />
<xsl:when test="starts-with($q,'@')">
<xsl:value-of select="$p" />
</xsl:when>
<xsl:when test="contains($q,'(')">
<xsl:variable name="namespace">
<xsl:call-template name="namespace">
<xsl:with-param name="qname"
select="substring-before($q,'(')" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="name">
<xsl:call-template name="name">
<xsl:with-param name="qname"
select="substring-before($q,'(')" />
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates
select="//edm:Schema[@Alias=$namespace or @Namespace=$namespace]
/*[@Name=$name]"
mode="path-overload">
<xsl:with-param name="parameters"
select="substring-before(substring-after($q,'('),')')" />
<xsl:with-param name="p" select="$p" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="contains($q,'.')">
<xsl:variable name="namespace">
<xsl:call-template name="namespace">
Expand Down Expand Up @@ -487,14 +512,72 @@
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="*[@Name=$q]"
<xsl:apply-templates select="*[@Name=$q][1]"
mode="path-remainder">
<xsl:with-param name="p" select="$p" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="@*|*" mode="path-overload" />

<xsl:template match="edm:Action | edm:Function"
mode="path-overload">
<xsl:param name="parameters" />
<xsl:param name="parameter-count" select="1" />
<xsl:param name="p" />
<xsl:choose>
<xsl:when
test="$parameters='' and count(edm:Parameter)=$parameter-count - 1">
<xsl:apply-templates select="."
mode="path-remainder">
<xsl:with-param name="p" select="$p" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$parameters!=''">
<xsl:variable name="param-namespace">
<xsl:call-template name="namespace">
<xsl:with-param name="qname"
select="substring-before(concat($parameters,','),',')" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="param-name">
<xsl:call-template name="name">
<xsl:with-param name="qname"
select="substring-before(concat($parameters,','),',')" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="type-namespace">
<xsl:call-template name="namespace">
<xsl:with-param name="qname"
select="edm:Parameter[$parameter-count]/@Type" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="type-name">
<xsl:call-template name="name">
<xsl:with-param name="qname"
select="edm:Parameter[$parameter-count]/@Type" />
</xsl:call-template>
</xsl:variable>
<xsl:if
test="$param-name=$type-name and (
$param-namespace='Edm' and $type-namespace='Edm' or
//edm:Schema[@Alias=$param-namespace or @Namespace=$param-namespace]/@Namespace=
//edm:Schema[@Alias=$type-namespace or @Namespace=$type-namespace]/@Namespace)">
<xsl:apply-templates select="."
mode="path-overload">
<xsl:with-param name="parameters"
select="substring-after($parameters,',')" />
<xsl:with-param name="parameter-count"
select="$parameter-count + 1" />
<xsl:with-param name="p" select="$p" />
</xsl:apply-templates>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="*" mode="path-remainder">
<xsl:param name="p" />
<xsl:choose>
Expand Down

0 comments on commit f6b2bf5

Please sign in to comment.