Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Dec 11, 2024
1 parent 22ec250 commit aefcc7b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
41 changes: 8 additions & 33 deletions tools/V4-CSDL-to-OpenAPI.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,20 @@
<xsl:variable name="coreLongDescription" select="concat($coreNamespace,'.LongDescription')" />
<xsl:variable name="coreLongDescriptionAliased" select="concat($coreAlias,'.LongDescription')" />

<xsl:variable name="authorizationNamespace" select="'Org.OData.Authorization.V1'" />
<xsl:variable name="authorizationAlias" select="/edmx:Edmx/edmx:Reference/edmx:Include[@Namespace=$authorizationNamespace]/@Alias" />
<xsl:variable name="authorizationSecuritySchemes" select="concat($authorizationNamespace,'.SecuritySchemes')" />
<xsl:variable name="authorizationSecuritySchemesAliased" select="concat($authorizationAlias,'.SecuritySchemes')" />

<xsl:variable name="capabilitiesNamespace" select="'Org.OData.Capabilities.V1'" />
<xsl:variable name="capabilitiesAlias" select="/edmx:Edmx/edmx:Reference/edmx:Include[@Namespace=$capabilitiesNamespace]/@Alias" />
<xsl:variable name="capabilitiesCountRestrictions" select="concat($capabilitiesNamespace,'.CountRestrictions')" />
<xsl:variable name="capabilitiesCountRestrictionsAliased" select="concat($capabilitiesAlias,'.CountRestrictions')" />
<xsl:variable name="capabilitiesDeleteRestrictions" select="concat($capabilitiesNamespace,'.DeleteRestrictions')" />
<xsl:variable name="capabilitiesDeleteRestrictionsAliased" select="concat($capabilitiesAlias,'.DeleteRestrictions')" />
<xsl:variable name="capabilitiesExpandRestrictions" select="concat($capabilitiesNamespace,'.ExpandRestrictions')" />
<xsl:variable name="capabilitiesExpandRestrictionsAliased" select="concat($capabilitiesAlias,'.ExpandRestrictions')" />
<xsl:variable name="capabilitiesFilterRestrictions" select="concat($capabilitiesNamespace,'.FilterRestrictions')" />
<xsl:variable name="capabilitiesFilterRestrictionsAliased" select="concat($capabilitiesAlias,'.FilterRestrictions')" />
<xsl:variable name="capabilitiesInsertRestrictions" select="concat($capabilitiesNamespace,'.InsertRestrictions')" />
<xsl:variable name="capabilitiesInsertRestrictionsAliased" select="concat($capabilitiesAlias,'.InsertRestrictions')" />
<xsl:variable name="capabilitiesNavigationRestrictions" select="concat($capabilitiesNamespace,'.NavigationRestrictions')" />
<xsl:variable name="capabilitiesNavigationRestrictionsAliased" select="concat($capabilitiesAlias,'.NavigationRestrictions')" />
<xsl:variable name="capabilitiesReadRestrictions" select="concat($capabilitiesNamespace,'.ReadRestrictions')" />
<xsl:variable name="capabilitiesReadRestrictionsAliased" select="concat($capabilitiesAlias,'.ReadRestrictions')" />
<xsl:variable name="capabilitiesSearchRestrictions" select="concat($capabilitiesNamespace,'.SearchRestrictions')" />
<xsl:variable name="capabilitiesSearchRestrictionsAliased" select="concat($capabilitiesAlias,'.SearchRestrictions')" />
<xsl:variable name="capabilitiesSelectSupport" select="concat($capabilitiesNamespace,'.SelectSupport')" />
<xsl:variable name="capabilitiesSelectSupportAliased" select="concat($capabilitiesAlias,'.SelectSupport')" />
<xsl:variable name="capabilitiesSortRestrictions" select="concat($capabilitiesNamespace,'.SortRestrictions')" />
<xsl:variable name="capabilitiesSortRestrictionsAliased" select="concat($capabilitiesAlias,'.SortRestrictions')" />
<xsl:variable name="capabilitiesUpdateRestrictions" select="concat($capabilitiesNamespace,'.UpdateRestrictions')" />
<xsl:variable name="capabilitiesUpdateRestrictionsAliased" select="concat($capabilitiesAlias,'.UpdateRestrictions')" />
<xsl:variable name="capabilitiesSkipSupported" select="concat($capabilitiesNamespace,'.SkipSupported')" />
<xsl:variable name="capabilitiesSkipSupportedAliased" select="concat($capabilitiesAlias,'.SkipSupported')" />
<xsl:variable name="capabilitiesTopSupported" select="concat($capabilitiesNamespace,'.TopSupported')" />
Expand Down Expand Up @@ -595,7 +580,7 @@
</xsl:call-template>
<xsl:text>}</xsl:text>
</xsl:when>
<xsl:when test="//edm:Annotation[@Term=$capabilitiesSearchRestrictions or @Term=$capabilitiesSearchRestrictionsAliased]/edm:Record/edm:PropertyValue[@Property='Searchable' and @Bool='true']">
<xsl:when test="//edm:Annotation[@p2:Term='Org.OData.Capabilities.V1.SearchRestrictions']/edm:Record/edm:PropertyValue[@Property='Searchable' and @Bool='true']">
<xsl:text>,"search":{"name":"search","in":"query","description":"Search items by search phrases</xsl:text>
<xsl:text>, see [Searching](https://wiki.scn.sap.com/wiki/display/EmTech/SAP+Annotations+for+OData+Version+2.0#SAPAnnotationsforODataVersion2.0-Query_Option_searchQueryOptionsearch)",</xsl:text>
<xsl:call-template name="parameter-type">
Expand Down Expand Up @@ -631,13 +616,8 @@
</xsl:template>

<xsl:template name="security-schemes">
<xsl:variable name="target" select="/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer" />
<xsl:variable name="target-path" select="concat($target/../@Namespace,'.',$target/@Name)" />
<xsl:variable name="target-path-aliased" select="concat($target/../@Alias,'.',$target/@Name)" />
<xsl:variable name="annos" select="key('externalAnnotations',$target-path)|key('externalAnnotations',$target-path-aliased)|$target" />
<xsl:variable name="term" select="concat($authorizationNamespace,'.Authorizations')" />
<xsl:variable name="termAliased" select="concat($authorizationAlias,'.Authorizations')" />
<xsl:variable name="anno" select="$annos/edm:Annotation[@Term=$term or @Term=$termAliased]" />
<xsl:variable name="anno" select="//edm:Annotation[@target=/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer/@id and
@p2:Term='Org.OData.Authorization.V1.Authorizations']" />
<xsl:if test="$anno">
<xsl:text>,"</xsl:text>
<xsl:choose>
Expand Down Expand Up @@ -866,11 +846,8 @@
</xsl:template>

<xsl:template name="security">
<xsl:variable name="target" select="/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer" />
<xsl:variable name="target-path" select="concat($target/../@Namespace,'.',$target/@Name)" />
<xsl:variable name="target-path-aliased" select="concat($target/../@Alias,'.',$target/@Name)" />
<xsl:variable name="annos" select="key('externalAnnotations',$target-path)|key('externalAnnotations',$target-path-aliased)|$target" />
<xsl:variable name="anno" select="$annos/edm:Annotation[@Term=$authorizationSecuritySchemes or @Term=$authorizationSecuritySchemesAliased]" />
<xsl:variable name="anno" select="//edm:Annotation[@target=/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer/@id and
@p2:Term='Org.OData.Authorization.V1.SecuritySchemes']" />
<xsl:if test="$anno">
<xsl:text>,"security":[</xsl:text>
<xsl:for-each select="$anno/edm:Collection/edm:Record">
Expand Down Expand Up @@ -2803,11 +2780,9 @@

<xsl:template name="filter-RequiredProperties">
<xsl:param name="target" select="." />
<xsl:variable name="target-path" select="concat($target/../../@Namespace,'.',$target/../@Name,'/',$target/@Name)" />
<xsl:variable name="target-path-aliased" select="concat($target/../../@Alias,'.',$target/../@Name,'/',$target/@Name)" />
<xsl:variable name="annos" select="key('externalAnnotations',$target-path)|key('externalAnnotations',$target-path-aliased)|$target" />
<xsl:variable name="filter-restrictions" select="$annos/edm:Annotation[@Term=$capabilitiesFilterRestrictions or @Term=$capabilitiesFilterRestrictionsAliased]" />
<xsl:variable name="required-properties" select="$filter-restrictions/edm:Record/edm:PropertyValue[@Property='RequiredProperties']/edm:Collection/edm:PropertyPath" />
<xsl:variable name="required-properties" select="//edm:Annotation[@target=$target/@id and
@p2:Term='Org.OData.Capabilities.V1.FilterRestrictions']
/edm:Record/edm:PropertyValue[@Property='RequiredProperties']/edm:Collection/edm:PropertyPath" />
<xsl:for-each select="$required-properties">
<xsl:if test="position()=1">
<xsl:text>\n\nRequired filter properties:</xsl:text>
Expand Down
59 changes: 49 additions & 10 deletions tools/resolve-paths.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@
<xsl:value-of select="generate-id()" />
</xsl:attribute>
<xsl:variable name="target">
<xsl:apply-templates
select="ancestor::edm:Schema" mode="path">
<xsl:apply-templates select="/" mode="path">
<xsl:with-param name="p" select="../@Target" />
</xsl:apply-templates>
</xsl:variable>
Expand Down Expand Up @@ -236,8 +235,7 @@
edm:Annotations/edm:Annotation//edm:ModelElementPath"
mode="ids" priority="1">
<xsl:variable name="target">
<xsl:apply-templates
select="ancestor::edm:Schema" mode="path">
<xsl:apply-templates select="/" mode="path">
<xsl:with-param name="p"
select="ancestor::edm:Annotations/@Target" />
</xsl:apply-templates>
Expand Down Expand Up @@ -387,7 +385,7 @@
<!-- Paths relative to a property of a structured type -->
<xsl:template
match="edm:NavigationPropertyBinding/@Path |
edm:ReferentialConstraint/@Property"
edm:ReferentialConstraint/@ReferencedProperty"
mode="ids">
<xsl:apply-templates select="." mode="eval-path">
<xsl:with-param name="relative-to" select="../.." />
Expand All @@ -398,7 +396,7 @@
<xsl:template
match="edm:PropertyRef/@Name |
edm:NavigationPropertyBinding/@Target |
edm:ReferentialConstraint/@ReferencedProperty"
edm:ReferentialConstraint/@Property"
mode="ids">
<xsl:apply-templates select="." mode="eval-path">
<xsl:with-param name="relative-to" select="../../.." />
Expand Down Expand Up @@ -446,12 +444,19 @@
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:when test="not(self::*) and $relative='' and contains(.,'.')">
<xsl:copy-of select="." />
<xsl:if
test="not(starts-with(.,'Edm.') or starts-with(.,'Collection(Edm.'))">
<xsl:apply-templates select="."
mode="invalid" />
<xsl:attribute name="p2:{name()}">
<xsl:call-template name="p2-attribute">
<xsl:with-param name="qname" select="." />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="invalid" />
<xsl:call-template name="copy-ids" />
</xsl:otherwise>
</xsl:choose>
Expand Down Expand Up @@ -620,7 +625,41 @@

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

<xsl:template match="edm:Action | edm:Function"
<xsl:template match="edm:Action"
mode="path-overload">
<xsl:param name="parameters" />
<xsl:param name="p" />
<xsl:choose>
<xsl:when
test="$parameters='' and not(@IsBound='true')">
<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">
<xsl:call-template name="normalize-type">
<xsl:with-param name="type" select="$parameters" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="type">
<xsl:call-template name="normalize-type">
<xsl:with-param name="type"
select="edm:Parameter[1]/@Type" />
</xsl:call-template>
</xsl:variable>
<xsl:if test="$param=$type">
<xsl:apply-templates select="."
mode="path-remainder">
<xsl:with-param name="p" select="$p" />
</xsl:apply-templates>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="edm:Function"
mode="path-overload">
<xsl:param name="parameters" />
<xsl:param name="parameter-count" select="1" />
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/annotations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
<Record>
<PropertyValue Property="NonSortableProperties">
<Collection>
<PropertyPath>One</PropertyPath>
<PropertyPath>AllMany/One</PropertyPath>
</Collection>
</PropertyValue>
</Record>
Expand Down

0 comments on commit aefcc7b

Please sign in to comment.