Skip to content

Commit 22c2a1e

Browse files
Merge pull request #342 from VigneshSubramania91/insert-update-restrictions
insert and update restrictions
2 parents 902ede4 + dd19ff7 commit 22c2a1e

File tree

1 file changed

+85
-6
lines changed

1 file changed

+85
-6
lines changed

tools/V4-CSDL-to-OpenAPI.xsl

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,15 +1559,78 @@
15591559
</xsl:variable>
15601560
<xsl:variable name="required">
15611561
<xsl:if test="$suffix='-create'">
1562-
<!-- non-computed key properties are required, as are properties marked with Common.FieldControl=Mandatory -->
1563-
<xsl:for-each select="$structuredType/edm:Property[
1564-
(@Name=../edm:Key/edm:PropertyRef/@Name and not(@Name=$read-only or @Name=$computed or concat($qualifiedName,'/',@Name) = $computed-ext or concat($aliasQualifiedName,'/',@Name) = $computed-ext))
1565-
or concat($qualifiedName,'/',@Name)=$mandatory or concat($aliasQualifiedName,'/',@Name)=$mandatory]">
1562+
<!-- gather the RTFs for insert restrictions -->
1563+
<xsl:variable name="insert-restrictions">
1564+
<xsl:apply-templates select="$structuredType" mode="capabilities">
1565+
<xsl:with-param name="term" select="'InsertRestrictions'" />
1566+
</xsl:apply-templates>
1567+
</xsl:variable>
1568+
1569+
<!--non-computed key properties are required, as are properties marked with Common.FieldControl=Mandatory
1570+
and Capabilities.InsertRestrictions/ RequiredProperties -->
1571+
1572+
<xsl:for-each
1573+
select="
1574+
$structuredType/edm:Property[
1575+
(
1576+
@Name = ../edm:Key/edm:PropertyRef/@Name
1577+
and not(
1578+
@Name = $read-only
1579+
or @Name = $computed
1580+
or concat($qualifiedName, '/', @Name) = $computed-ext
1581+
or concat($aliasQualifiedName, '/', @Name) = $computed-ext
1582+
)
1583+
)
1584+
or concat($qualifiedName, '/', @Name) = $mandatory
1585+
or concat($aliasQualifiedName, '/', @Name) = $mandatory
1586+
or @Name = (
1587+
//edm:Annotation
1588+
[ contains($insert-restrictions, concat(' ', generate-id(), ' ')) ]
1589+
/edm:Record
1590+
/edm:PropertyValue[@Property = 'RequiredProperties']
1591+
/edm:Collection
1592+
/edm:PropertyPath
1593+
)
1594+
1595+
]">
1596+
<xsl:if test="position()>1">
1597+
<xsl:text>,</xsl:text>
1598+
</xsl:if>
1599+
<xsl:text>"</xsl:text>
1600+
<xsl:value-of
1601+
select="@Name" />
1602+
<xsl:text>"</xsl:text>
1603+
</xsl:for-each>
1604+
</xsl:if>
1605+
1606+
1607+
<xsl:if test="$suffix = '-update'">
1608+
<!-- gather the RTFs for update restrictions -->
1609+
<xsl:variable name="update-restrictions">
1610+
<xsl:apply-templates select="$structuredType" mode="capabilities">
1611+
<xsl:with-param name="term" select="'UpdateRestrictions'" />
1612+
</xsl:apply-templates>
1613+
</xsl:variable>
1614+
<!-- Capabilities.UpdateRestrictions/ RequiredProperties -->
1615+
<xsl:for-each
1616+
select="
1617+
$structuredType/edm:Property[
1618+
@Name = (
1619+
//edm:Annotation
1620+
[ contains($update-restrictions, concat(' ', generate-id(), ' ')) ]
1621+
/edm:Record
1622+
/edm:PropertyValue[@Property = 'RequiredProperties']
1623+
/edm:Collection
1624+
/edm:PropertyPath
1625+
)
1626+
]
1627+
">
15661628
<xsl:if test="position()>1">
15671629
<xsl:text>,</xsl:text>
15681630
</xsl:if>
15691631
<xsl:text>"</xsl:text>
1570-
<xsl:value-of select="@Name" />
1632+
<xsl:value-of
1633+
select="@Name" />
15711634
<xsl:text>"</xsl:text>
15721635
</xsl:for-each>
15731636
</xsl:if>
@@ -2737,7 +2800,23 @@
27372800
</xsl:otherwise>
27382801
</xsl:choose>
27392802
</xsl:template>
2740-
2803+
<xsl:template match="edm:EntityType" mode="capabilities">
2804+
<xsl:param name="term" />
2805+
<xsl:for-each select="//edm:EntitySet[
2806+
@EntityType=concat(current()/../@Namespace,'.',current()/@Name) or
2807+
@EntityType=concat(current()/../@Alias,'.',current()/@Name)]">
2808+
<xsl:variable name="target-path" select="concat(../../@Namespace,'.',../@Name,'/',@Name)" />
2809+
<xsl:variable name="target-path-aliased" select="concat(../../@Alias,'.',../@Name,'/',@Name)" />
2810+
<xsl:variable name="annos" select="key('externalAnnotations',$target-path)|key('externalAnnotations',$target-path-aliased)|." />
2811+
<xsl:for-each select="$annos/edm:Annotation[not(@Qualifier) and
2812+
@Term=concat($capabilitiesNamespace,'.',$term) or
2813+
@Term=concat($capabilitiesAlias,'.',$term)]">
2814+
<xsl:text> </xsl:text>
2815+
<xsl:value-of select="generate-id()" />
2816+
<xsl:text> </xsl:text>
2817+
</xsl:for-each>
2818+
</xsl:for-each>
2819+
</xsl:template>
27412820
<xsl:template match="edm:EntitySet">
27422821
<xsl:variable name="target-path" select="concat(../../@Namespace,'.',../@Name,'/',@Name)" />
27432822
<xsl:variable name="target-path-aliased" select="concat(../../@Alias,'.',../@Name,'/',@Name)" />

0 commit comments

Comments
 (0)