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

Key fields not required #316

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 9 additions & 12 deletions tools/V4-CSDL-to-OpenAPI.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
<xsl:variable name="coreAcceptableMediaTypesAliased" select="concat($coreAlias,'.AcceptableMediaTypes')" />
<xsl:variable name="coreComputed" select="concat($coreNamespace,'.Computed')" />
<xsl:variable name="coreComputedAliased" select="concat($coreAlias,'.Computed')" />
<xsl:variable name="coreComputedDefaultValue" select="concat($coreNamespace,'.ComputedDefaultValue')" />
<xsl:variable name="coreComputedDefaultValueAliased" select="concat($coreAlias,'.ComputedDefaultValue')" />
<xsl:variable name="coreDefaultNamespace" select="concat($coreNamespace,'.DefaultNamespace')" />
<xsl:variable name="coreDefaultNamespaceAliased" select="concat($coreAlias,'.DefaultNamespace')" />
<xsl:variable name="coreDescription" select="concat($coreNamespace,'.Description')" />
Expand Down Expand Up @@ -177,10 +179,6 @@

<xsl:variable name="commonNamespace" select="'com.sap.vocabularies.Common.v1'" />
<xsl:variable name="commonAlias" select="/edmx:Edmx/edmx:Reference/edmx:Include[@Namespace=$commonNamespace]/@Alias" />
<xsl:variable name="commonFieldControl" select="concat($commonNamespace,'.FieldControl')" />
<xsl:variable name="commonFieldControlAliased" select="concat($commonAlias,'.FieldControl')" />
<xsl:variable name="commonFieldControlMandatory" select="concat($commonNamespace,'.FieldControlType/Mandatory')" />
<xsl:variable name="commonFieldControlMandatoryAliased" select="concat($commonAlias,'.FieldControlType/Mandatory')" />
<xsl:variable name="commonLabel" select="concat($commonNamespace,'.Label')" />
<xsl:variable name="commonLabelAliased" select="concat($commonAlias,'.Label')" />
<xsl:variable name="commonQuickInfo" select="concat($commonNamespace,'.QuickInfo')" />
Expand Down Expand Up @@ -1493,6 +1491,9 @@
<xsl:variable name="computed" select="$structuredType/edm:Property[edm:Annotation[@Term=$coreComputed or @Term=$coreComputedAliased]]/@Name" />
<xsl:variable name="computed-ext" select="(key('externalPropertyAnnotations',$qualifiedName)|key('externalPropertyAnnotations',$aliasQualifiedName))
[edm:Annotation[@Term=$coreComputed or @Term=$coreComputedAliased]]/@Target" />
<xsl:variable name="computeddefaultvalue" select="$structuredType/edm:Property[edm:Annotation[@Term=$coreComputedDefaultValue or @Term=$coreComputedDefaultValueAliased]]/@Name" />
<xsl:variable name="computeddefaultvalue-ext" select="(key('externalPropertyAnnotations',$qualifiedName)|key('externalPropertyAnnotations',$aliasQualifiedName))
[edm:Annotation[@Term=$coreComputedDefaultValue or @Term=$coreComputedDefaultValueAliased]]/@Target" />

<xsl:variable name="immutable" select="$structuredType/edm:Property[edm:Annotation[@Term=$coreImmutable or @Term=$coreImmutableAliased]]/@Name" />
<xsl:variable name="immutable-ext" select="(key('externalPropertyAnnotations',$qualifiedName)|key('externalPropertyAnnotations',$aliasQualifiedName))
Expand All @@ -1503,11 +1504,6 @@
/edm:EnumMember[.=$corePermissionRead or .=$corePermissionReadAliased]]/@Name" />
<!-- TODO: also nested annotations -->
<!-- TODO: also edm:EnumMember -->
<xsl:variable name="mandatory" select="(key('externalPropertyAnnotations',$qualifiedName)|key('externalPropertyAnnotations',$aliasQualifiedName))
[edm:Annotation[(@Term=$commonFieldControl or @Term=$commonFieldControlAliased)
and (@EnumMember=$commonFieldControlMandatory or @EnumMember=$commonFieldControlMandatoryAliased)]]/@Target" />
<!-- TODO: also nested annotations -->
<!-- TODO: also edm:EnumMember -->
<xsl:variable name="navprop-read-only" select="(key('externalPropertyAnnotations',$qualifiedName)|key('externalPropertyAnnotations',$aliasQualifiedName))
[edm:Annotation[(@Term=$corePermissions or @Term=$corePermissionsAliased)
and (@EnumMember=$corePermissionRead or @EnumMember=$corePermissionReadAliased)]]/@Target" />
Expand Down Expand Up @@ -1556,10 +1552,11 @@
</xsl:variable>
<xsl:variable name="required">
<xsl:if test="$suffix='-create'">
<!-- non-computed key properties are required, as are properties marked with Common.FieldControl=Mandatory -->
<!-- non-computed key properties are required -->
<xsl:for-each select="$structuredType/edm:Property[
(@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))
or concat($qualifiedName,'/',@Name)=$mandatory or concat($aliasQualifiedName,'/',@Name)=$mandatory]">
@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
or @Name=$computeddefaultvalue or concat($qualifiedName,'/',@Name) = $computeddefaultvalue-ext or concat($aliasQualifiedName,'/',@Name) = $computeddefaultvalue-ext)]">
<xsl:if test="position()>1">
<xsl:text>,</xsl:text>
</xsl:if>
Expand Down
4 changes: 1 addition & 3 deletions tools/tests/annotations.openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3134,9 +3134,7 @@
}
},
"required": [
"ID",
"PatternExt",
"AllowedValuesExt"
"ID"
],
"title": "SinglePartKey (for create)"
},
Expand Down
4 changes: 1 addition & 3 deletions tools/tests/annotations.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2783,9 +2783,7 @@
}
},
"required": [
"ID",
"PatternExt",
"AllowedValuesExt"
"ID"
],
"title": "SinglePartKey (for create)"
},
Expand Down
3 changes: 0 additions & 3 deletions tools/tests/csdl-16.1.openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2043,9 +2043,6 @@
]
}
},
"required": [
"ID"
],
"title": "Product (for create)"
},
"ODataDemo.Product-update": {
Expand Down
3 changes: 0 additions & 3 deletions tools/tests/csdl-16.1.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1796,9 +1796,6 @@
"$ref": "#/definitions/ODataDemo.Supplier-create"
}
},
"required": [
"ID"
],
"title": "Product (for create)"
},
"ODataDemo.Product-update": {
Expand Down
4 changes: 3 additions & 1 deletion tools/tests/csdl-16.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Edm.String" Nullable="false" />
<Property Name="ID" Type="Edm.String" Nullable="false">
<Annotation Term="Org.OData.Core.V1.ComputedDefaultValue" />
</Property>
<Property Name="Description" Type="Edm.String">
<Annotation Term="Core.IsLanguageDependent" />
</Property>
Expand Down