Skip to content

Commit 90cfec6

Browse files
authored
feat: [OData V4] TypeDefinition Support (#644)
1 parent 2fdd8c5 commit 90cfec6

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

datamodel/odata-v4/odata-v4-generator/src/main/java/com/sap/cloud/sdk/datamodel/odatav4/generator/EdmUtils.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@ static Multiplicity convertMultiplicity( final EdmTyped edmTyped )
2020

2121
static TypeKind convertTypeKind( final EdmTypeKind typeKind )
2222
{
23-
switch( typeKind ) {
24-
case PRIMITIVE:
25-
return TypeKind.PRIMITIVE;
26-
case COMPLEX:
27-
return TypeKind.COMPLEX;
28-
case ENTITY:
29-
return TypeKind.ENTITY;
30-
case ENUM:
31-
return TypeKind.ENUM;
32-
default:
33-
throw new ODataGeneratorException("Encountered unknown type kind: " + typeKind);
34-
}
23+
return switch( typeKind ) {
24+
case PRIMITIVE, DEFINITION -> TypeKind.PRIMITIVE;
25+
case COMPLEX -> TypeKind.COMPLEX;
26+
case ENTITY -> TypeKind.ENTITY;
27+
case ENUM -> TypeKind.ENUM;
28+
default -> throw new ODataGeneratorException("Encountered unknown type kind: " + typeKind);
29+
};
3530
}
3631
}

datamodel/odata-v4/odata-v4-generator/src/test/resources/oDataGeneratorIntegrationTest/actionsAndFunctionsTest/input/actionsAndFunctions.edmx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<Function Name="FunctionWithNewResultType">
6565
<ReturnType Type="API_ACTIONS_FUNCTIONS_TEST_CASE.NewComplexResult"/>
6666
</Function>
67+
<TypeDefinition Name="MyStringTypeDef" UnderlyingType="Edm.String"/>
68+
<TypeDefinition Name="MyNumberTypeDef" UnderlyingType="Edm.Int32"/>
69+
<Function Name="FunctionWithTypeDef">
70+
<Parameter Name="FunctionParameter" Type="API_ACTIONS_FUNCTIONS_TEST_CASE.MyStringTypeDef"/>
71+
<ReturnType Type="API_ACTIONS_FUNCTIONS_TEST_CASE.MyNumberTypeDef"/>
72+
</Function>
6773
<EntityContainer Name="API_ACTIONS_FUNCTIONS_TEST_CASE_Entities" IsDefaultEntityContainer="true">
6874
<EntitySet Name="SimplePersons" EntityType="API_ACTIONS_FUNCTIONS_TEST_CASE.SimplePerson"/>
6975
<FunctionImport Name="GetPersonWithMostFriends"
@@ -72,6 +78,8 @@
7278
Function="API_ACTIONS_FUNCTIONS_TEST_CASE.FunctionWithUnassociatedEntityParameter"/>
7379
<FunctionImport Name="FunctionWithNewResultType"
7480
Function="API_ACTIONS_FUNCTIONS_TEST_CASE.FunctionWithNewResultType"/>
81+
<FunctionImport Name="FunctionWithTypeDef"
82+
Function="API_ACTIONS_FUNCTIONS_TEST_CASE.FunctionWithTypeDef"/>
7583
<ActionImport Name="UnboundAction"
7684
Action="API_ACTIONS_FUNCTIONS_TEST_CASE.UnboundAction"/>
7785
<ActionImport Name="NoArgAction"

datamodel/odata-v4/odata-v4-generator/src/test/resources/oDataGeneratorIntegrationTest/actionsAndFunctionsTest/output/testcomparison/services/ActionsAndFunctionsService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package testcomparison.services;
66

77
import javax.annotation.Nonnull;
8+
import javax.annotation.Nullable;
89
import com.sap.cloud.sdk.datamodel.odatav4.core.BatchRequestBuilder;
910
import com.sap.cloud.sdk.datamodel.odatav4.core.CountRequestBuilder;
1011
import com.sap.cloud.sdk.datamodel.odatav4.core.CreateRequestBuilder;
@@ -139,6 +140,19 @@ DeleteRequestBuilder<SimplePerson> deleteSimplePerson(
139140
@Nonnull
140141
SingleValueFunctionRequestBuilder<NewComplexResult> functionWithNewResultType();
141142

143+
/**
144+
* <p>Creates a request builder for the <b>FunctionWithTypeDef</b> OData function.</p>
145+
*
146+
* @param functionParameter
147+
* Constraints: Nullable<p>Original parameter name from the Odata EDM: <b>FunctionParameter</b></p>
148+
* @return
149+
* A request builder object that will execute the <b>FunctionWithTypeDef</b> OData function with the provided parameters. To perform execution, call the {@link com.sap.cloud.sdk.datamodel.odatav4.core.SingleValueFunctionRequestBuilder#execute execute} method on the request builder object.
150+
*/
151+
@Nonnull
152+
SingleValueFunctionRequestBuilder<Integer> functionWithTypeDef(
153+
@Nullable
154+
final String functionParameter);
155+
142156
/**
143157
* <p>Creates a request builder for the <b>NoArgAction</b> OData action.</p>
144158
*

datamodel/odata-v4/odata-v4-generator/src/test/resources/oDataGeneratorIntegrationTest/actionsAndFunctionsTest/output/testcomparison/services/DefaultActionsAndFunctionsService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package testcomparison.services;
66

77
import java.util.HashMap;
8+
import java.util.LinkedHashMap;
89
import java.util.Map;
910
import javax.annotation.Nonnull;
11+
import javax.annotation.Nullable;
1012
import com.sap.cloud.sdk.datamodel.odatav4.core.BatchRequestBuilder;
1113
import com.sap.cloud.sdk.datamodel.odatav4.core.CountRequestBuilder;
1214
import com.sap.cloud.sdk.datamodel.odatav4.core.CreateRequestBuilder;
@@ -125,6 +127,16 @@ public SingleValueFunctionRequestBuilder<NewComplexResult> functionWithNewResult
125127
return new SingleValueFunctionRequestBuilder<NewComplexResult>(servicePath, "FunctionWithNewResultType", NewComplexResult.class);
126128
}
127129

130+
@Override
131+
@Nonnull
132+
public SingleValueFunctionRequestBuilder<Integer> functionWithTypeDef(
133+
@Nullable
134+
final String functionParameter) {
135+
final LinkedHashMap<String, Object> parameters = new LinkedHashMap<String, Object>();
136+
parameters.put("FunctionParameter", functionParameter);
137+
return new SingleValueFunctionRequestBuilder<Integer>(servicePath, "FunctionWithTypeDef", parameters, Integer.class);
138+
}
139+
128140
@Override
129141
@Nonnull
130142
public SingleValueActionRequestBuilder<Void> noArgAction() {

release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
### ✨ New Functionality
1414

15-
-
15+
- Add support for `TypeDefinition` entries in OData V4 EDMX files.
1616

1717
### 📈 Improvements
1818

0 commit comments

Comments
 (0)