Skip to content

Commit

Permalink
Edm.DateTime becomes Core.LocalDateTime if it is not marked as a Date
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl committed Oct 30, 2023
1 parent 588e7c3 commit 194cb4e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 40 deletions.
98 changes: 62 additions & 36 deletions tools/V2-to-V4-CSDL.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,12 @@
select="../../edm2:Association[@Name=$assoc]/edm2:End[@Role=$torole]/@Multiplicity|../../edm3:Association[@Name=$assoc]/edm3:End[@Role=$torole]/@Multiplicity" />
<xsl:attribute name="Type">
<xsl:choose>
<xsl:when test="$mult='*'"><xsl:value-of select="concat('Collection(',$type,')')" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$type" /></xsl:otherwise>
<xsl:when test="$mult='*'">
<xsl:value-of select="concat('Collection(',$type,')')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$type" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$mult='1'">
Expand Down Expand Up @@ -325,7 +329,7 @@
<ReferentialConstraint>
<xsl:attribute name="Property">
<xsl:value-of
select="../../edm2:Dependent/edm2:PropertyRef[$index]/@Name|../../edm3:Dependent/edm2:PropertyRef[$index]/@Name" />
select="../../edm2:Dependent/edm2:PropertyRef[$index]/@Name|../../edm3:Dependent/edm2:PropertyRef[$index]/@Name" />
</xsl:attribute>
<xsl:attribute name="ReferencedProperty">
<xsl:value-of select="@Name" />
Expand Down Expand Up @@ -408,7 +412,7 @@

<!-- TODO: un-hack -->
<xsl:if test="$entityType/@sap:semantics = 'parameters'">
<Annotation Term="sap.parameters"/>
<Annotation Term="sap.parameters" />
</xsl:if>
</EntitySet>
</xsl:template>
Expand All @@ -426,9 +430,9 @@
<xsl:if test="string($stuff)">
<Annotation>
<xsl:attribute name="Term">
<xsl:value-of select="$Capabilities" />
<xsl:text>.NavigationRestrictions</xsl:text>
</xsl:attribute>
<xsl:value-of select="$Capabilities" />
<xsl:text>.NavigationRestrictions</xsl:text>
</xsl:attribute>
<Record>
<PropertyValue Property="RestrictedProperties">
<Collection>
Expand All @@ -452,7 +456,7 @@
<Record>
<PropertyValue Property="NavigationProperty">
<xsl:attribute name="NavigationPropertyPath">
<xsl:value-of select="$navprop/@Name" />
<xsl:value-of select="$navprop/@Name" />
</xsl:attribute>
</PropertyValue>
<PropertyValue Property="ReadRestrictions">
Expand All @@ -479,9 +483,13 @@
<xsl:variable name="typename" select="$navprop/../@Name" />
<xsl:variable name="type" select="concat($namespace,'.',$typename)" />
<NavigationPropertyBinding>
<xsl:attribute name="Target"><xsl:value-of select="$set" /></xsl:attribute>
<xsl:attribute name="Target">
<xsl:value-of select="$set" />
</xsl:attribute>
<xsl:attribute name="Path">
<xsl:if test="not($type=$entitytype)"><xsl:value-of select="concat($type,'/')" /></xsl:if>
<xsl:if test="not($type=$entitytype)">
<xsl:value-of select="concat($type,'/')" />
</xsl:if>
<xsl:value-of select="$navprop/@Name" />
</xsl:attribute>
<xsl:apply-templates />
Expand All @@ -496,7 +504,9 @@
<FunctionImport>
<xsl:copy-of select="@Name|@EntitySet" />
<xsl:attribute name="Function">
<xsl:value-of select="../../@Namespace" />.<xsl:value-of select="@Name" />
<xsl:value-of select="../../@Namespace" />
<xsl:text>.</xsl:text>
<xsl:value-of select="@Name" />
</xsl:attribute>
<xsl:if test="not(*[local-name()='Parameter'])">
<xsl:attribute name="IncludeInServiceDocument">true</xsl:attribute>
Expand All @@ -508,7 +518,9 @@
<ActionImport>
<xsl:copy-of select="@Name|@EntitySet" />
<xsl:attribute name="Action">
<xsl:value-of select="../../@Namespace" />.<xsl:value-of select="@Name" />
<xsl:value-of select="../../@Namespace" />
<xsl:text>.</xsl:text>
<xsl:value-of select="@Name" />
</xsl:attribute>
<xsl:apply-templates select="@sap:*" />
</ActionImport>
Expand All @@ -523,12 +535,16 @@
<Function>
<xsl:copy-of select="@Name|@EntitySetPath|@IsComposable" />
<xsl:if test="@IsBindable">
<xsl:attribute name="IsBound"><xsl:value-of select="@IsBindable" /></xsl:attribute>
<xsl:attribute name="IsBound">
<xsl:value-of select="@IsBindable" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates />
<xsl:if test="@ReturnType">
<ReturnType>
<xsl:attribute name="Type"><xsl:value-of select="@ReturnType" /></xsl:attribute>
<xsl:attribute name="Type">
<xsl:value-of select="@ReturnType" />
</xsl:attribute>
<xsl:attribute name="Nullable">false</xsl:attribute>
</ReturnType>
</xsl:if>
Expand All @@ -538,12 +554,16 @@
<Action>
<xsl:copy-of select="@Name|@EntitySetPath" />
<xsl:if test="@IsBindable">
<xsl:attribute name="IsBound"><xsl:value-of select="@IsBindable" /></xsl:attribute>
<xsl:attribute name="IsBound">
<xsl:value-of select="@IsBindable" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates />
<xsl:if test="@ReturnType">
<ReturnType>
<xsl:attribute name="Type"><xsl:value-of select="@ReturnType" /></xsl:attribute>
<xsl:attribute name="Type">
<xsl:value-of select="@ReturnType" />
</xsl:attribute>
<xsl:attribute name="Nullable">false</xsl:attribute>
</ReturnType>
</xsl:if>
Expand Down Expand Up @@ -599,16 +619,16 @@
<xsl:if test=".!=''">
<Annotation>
<xsl:attribute name="Term">
<xsl:value-of select="$Core" />
<xsl:text>.LongDescription</xsl:text>
</xsl:attribute>
<xsl:value-of select="$Core" />
<xsl:text>.LongDescription</xsl:text>
</xsl:attribute>
<String>
<xsl:call-template name="replace-all">
<xsl:with-param name="string" select="." />
<xsl:with-param name="old" select="'&#x0A;'" />
<xsl:with-param name="new" select="' &#x0A;'" />
</xsl:call-template>
</String>
<xsl:call-template name="replace-all">
<xsl:with-param name="string" select="." />
<xsl:with-param name="old" select="'&#x0A;'" />
<xsl:with-param name="new" select="' &#x0A;'" />
</xsl:call-template>
</String>
</Annotation>
</xsl:if>
</xsl:template>
Expand All @@ -627,7 +647,9 @@

<xsl:template match="edm3:TypeAnnotation">
<Annotation>
<xsl:attribute name="Term"><xsl:value-of select="@Term" /></xsl:attribute>
<xsl:attribute name="Term">
<xsl:value-of select="@Term" />
</xsl:attribute>
<Record>
<xsl:apply-templates select="node()" />
</Record>
Expand Down Expand Up @@ -669,15 +691,19 @@
</xsl:template>

<xsl:template match="@Type|@UnderlyingType">
<xsl:attribute name="{name()}">
<xsl:attribute name="{name()}">
<xsl:choose>
<xsl:when test=".='Time' or .='Edm.Time'">Edm.TimeOfDay</xsl:when>
<xsl:when test=".='Float' or .='Edm.Float'">Edm.Single</xsl:when>
<!-- TODO: better heuristics for parameters -->
<xsl:when test="(.='DateTime' or .='Edm.DateTime') and (../@sap:display-format='Date' or local-name(..)='Parameter')">Edm.Date</xsl:when>
<xsl:when test=".='DateTime' or .='Edm.DateTime'">Edm.DateTimeOffset</xsl:when>
<xsl:when test="contains(.,'.')"><xsl:value-of select="." /></xsl:when>
<xsl:otherwise><xsl:value-of select="concat('Edm.',.)" /></xsl:otherwise>
<xsl:when test=".='DateTime' or .='Edm.DateTime'">Core.LocalDateTime</xsl:when>
<xsl:when test="contains(.,'.')">
<xsl:value-of select="." />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('Edm.',.)" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
Expand Down Expand Up @@ -1063,8 +1089,8 @@
<xsl:if test="$excluded-properties">
<xsl:element name="PropertyValue">
<xsl:attribute name="Property">
<xsl:value-of select="concat('Non',$capability,'ableProperties')" />
</xsl:attribute>
<xsl:value-of select="concat('Non',$capability,'ableProperties')" />
</xsl:attribute>
<Collection>
<xsl:apply-templates select="$excluded-properties" mode="restriction" />
</Collection>
Expand Down Expand Up @@ -1123,9 +1149,9 @@
<xsl:if test=".='false'">
<Annotation>
<xsl:attribute name="Term">
<xsl:value-of select="$UI" />
<xsl:text>.Hidden</xsl:text>
</xsl:attribute>
<xsl:value-of select="$UI" />
<xsl:text>.Hidden</xsl:text>
</xsl:attribute>
</Annotation>
</xsl:if>
</xsl:template>
Expand Down Expand Up @@ -1269,4 +1295,4 @@
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
</xsl:stylesheet>
8 changes: 4 additions & 4 deletions tools/V4-CSDL-to-OpenAPI.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@
TODO: evaluate Partner to just have one arrow
[FeaturedProduct]<0..1-0..1>[Advertisement]
-->
<xsl:if test="$qualifier!='Edm' or local-name='NavigationProperty'">
<xsl:if test="($qualifier!='Edm' and $qualifier!='Core') or local-name='NavigationProperty'">
<xsl:text>,[</xsl:text>
<xsl:value-of select="../@Name" />
<xsl:text>]</xsl:text>
Expand Down Expand Up @@ -2084,7 +2084,7 @@
<xsl:text>,"example":"01234567-89ab-cdef-0123-456789abcdef"</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="$singleType='Edm.DateTimeOffset'">
<xsl:when test="$singleType='Edm.DateTimeOffset' or $singleType='Core.LocalDateTime'">
<xsl:call-template name="nullableType">
<xsl:with-param name="type" select="'string'" />
<xsl:with-param name="nullable" select="$nullable" />
Expand Down Expand Up @@ -3848,7 +3848,7 @@
<xsl:when test="$odata-version='2.0' and $type='Edm.Binary'">
<xsl:text>binary'</xsl:text>
</xsl:when>
<xsl:when test="$odata-version='2.0' and $type='Edm.Date'">
<xsl:when test="$odata-version='2.0' and ($type='Edm.Date' or $type='Core.LocalDateTime')">
<xsl:text>datetime'</xsl:text>
</xsl:when>
<xsl:when test="$odata-version='2.0' and $type='Edm.DateTimeOffset'">
Expand Down Expand Up @@ -3878,7 +3878,7 @@
<xsl:template name="pathValueSuffix">
<xsl:param name="type" />
<xsl:choose>
<xsl:when test="$odata-version='2.0' and ($type='Edm.Binary' or $type='Edm.Date' or $type='Edm.DateTimeOffset' or $type='Edm.Guid' or $type='Edm.TimeOfDay')">
<xsl:when test="$odata-version='2.0' and ($type='Edm.Binary' or $type='Edm.Date' or $type='Core.LocalDateTime' or $type='Edm.DateTimeOffset' or $type='Edm.Guid' or $type='Edm.TimeOfDay')">
<xsl:text>'</xsl:text>
</xsl:when>
<xsl:when test="$type='Edm.Int64' or $type='Edm.Int32' or $type='Edm.Int16' or $type='Edm.SByte' or $type='Edm.Byte'
Expand Down

0 comments on commit 194cb4e

Please sign in to comment.