Skip to content

Commit 9e1dc2e

Browse files
OpenAPI: Added AI SDK Constructors (#629)
1 parent 2f02494 commit 9e1dc2e

File tree

9 files changed

+1601
-3
lines changed

9 files changed

+1601
-3
lines changed

datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/resttemplate/api.mustache

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import javax.annotation.Nonnull;
3030
import javax.annotation.Nullable;
3131
import com.google.common.annotations.Beta;
3232

33-
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
33+
{{^aiSdkConstructor}}import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
34+
{{/aiSdkConstructor}}
35+
{{#aiSdkConstructor}}import com.sap.ai.sdk.core.AiCoreService;
36+
import com.sap.ai.sdk.core.AiCoreDestination;
37+
{{/aiSdkConstructor}}
3438

3539
/**
3640
* {{appName}} in version {{version}}.
@@ -40,6 +44,7 @@ import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
4044
@Beta{{/isReleased}}
4145
{{#operations}}
4246
public class {{classname}} extends AbstractOpenApiService {
47+
{{^aiSdkConstructor}}
4348
/**
4449
* Instantiates this API class to invoke operations on the {{appName}}.
4550
*
@@ -61,6 +66,27 @@ public class {{classname}} extends AbstractOpenApiService {
6166
{
6267
super(apiClient);
6368
}
69+
{{/aiSdkConstructor}}
70+
{{#aiSdkConstructor}}
71+
72+
/**
73+
* Instantiates this API class to invoke operations on the {{appName}}
74+
*/
75+
public {{classname}}()
76+
{
77+
super(new AiCoreService().client());
78+
}
79+
80+
/**
81+
* Instantiates this API class to invoke operations on the {{appName}}
82+
*
83+
* @param aiCoreDestination The configured connectivity instance to AI Core
84+
*/
85+
public {{classname}}( @Nonnull final AiCoreDestination aiCoreDestination )
86+
{
87+
super(aiCoreDestination.client());
88+
}
89+
{{/aiSdkConstructor}}
6490

6591
{{#operation}}{{#hasOptionalParams}}
6692
/**

datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorIntegrationTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ class DataModelGeneratorIntegrationTest
3030
@AllArgsConstructor
3131
private enum TestCase
3232
{
33+
API_CLASS_FOR_AI_SDK(
34+
"api-class-for-ai-sdk",
35+
"sodastore.json",
36+
"com.sap.cloud.sdk.services.builder.api",
37+
"com.sap.cloud.sdk.services.builder.model",
38+
ApiMaturity.RELEASED,
39+
true,
40+
6,
41+
null,
42+
null,
43+
null,
44+
"true"),
3345
API_CLASS_VENDOR_EXTENSION_YAML(
3446
"api-class-vendor-extension-yaml",
3547
"sodastore.yaml",
@@ -72,7 +84,8 @@ private enum TestCase
7284
6,
7385
"builder",
7486
"build",
75-
"private");
87+
"private",
88+
null),;
7689

7790
final String testCaseName;
7891
final String inputSpecFileName;
@@ -84,6 +97,7 @@ private enum TestCase
8497
String methodBuilder = null;
8598
String methodBuild = null;
8699
String constructorVisibility = null;
100+
String aiSdkConstructor = null;
87101
}
88102

89103
@ParameterizedTest
@@ -115,6 +129,7 @@ void integrationTests( final TestCase testCase, @TempDir final Path path )
115129
.additionalProperty("pojoBuilderMethodName", testCase.methodBuilder)
116130
.additionalProperty("pojoBuildMethodName", testCase.methodBuild)
117131
.additionalProperty("pojoConstructorVisibility", testCase.constructorVisibility)
132+
.additionalProperty("aiSdkConstructor", testCase.aiSdkConstructor)
118133
.build();
119134

120135
final Try<GenerationResult> maybeGenerationResult =
@@ -135,7 +150,7 @@ void generateDataModelForComparison( final TestCase testCase )
135150
final Path outputDirectory = getComparisonDirectory(testCase);
136151

137152
assertThat(inputDirectory).exists().isReadable().isDirectory();
138-
assertThat(inputDirectory).exists().isReadable().isDirectory();
153+
assertThat(outputDirectory).exists().isReadable().isDirectory();
139154

140155
final GenerationConfiguration generationConfiguration =
141156
GenerationConfiguration
@@ -152,6 +167,7 @@ void generateDataModelForComparison( final TestCase testCase )
152167
.additionalProperty("pojoBuilderMethodName", testCase.methodBuilder)
153168
.additionalProperty("pojoBuildMethodName", testCase.methodBuild)
154169
.additionalProperty("pojoConstructorVisibility", testCase.constructorVisibility)
170+
.additionalProperty("aiSdkConstructor", testCase.aiSdkConstructor)
155171
.build();
156172

157173
new DataModelGenerator().generateDataModel(generationConfiguration);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Soda Store API",
5+
"version": "1.0.0",
6+
"description": "API for managing sodas in a soda store"
7+
},
8+
"paths": {
9+
"/sodas": {
10+
"get": {
11+
"summary": "Get a list of all sodas",
12+
"x-sap-cloud-sdk-api-name": "AwesomeSodas",
13+
"operationId": "getSodas",
14+
"responses": {
15+
"200": {
16+
"description": "A list of sodas",
17+
"content": {
18+
"application/json": {
19+
"schema": {
20+
"type": "array",
21+
"items": {
22+
"$ref": "#/components/schemas/Soda"
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
29+
},
30+
"post": {
31+
"summary": "Add a new soda to the store",
32+
"x-sap-cloud-sdk-api-name": "AwesomeSoda",
33+
"operationId": "addSoda",
34+
"requestBody": {
35+
"required": true,
36+
"content": {
37+
"application/json": {
38+
"schema": {
39+
"$ref": "#/components/schemas/NewSoda"
40+
}
41+
}
42+
}
43+
},
44+
"responses": {
45+
"201": {
46+
"description": "The newly added soda",
47+
"content": {
48+
"application/json": {
49+
"schema": {
50+
"$ref": "#/components/schemas/Soda"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
},
58+
"/sodas/{sodaId}": {
59+
"get": {
60+
"summary": "Get details of a specific soda",
61+
"operationId": "getSodaById",
62+
"parameters": [
63+
{
64+
"name": "sodaId",
65+
"in": "path",
66+
"description": "ID of the soda to retrieve",
67+
"required": true,
68+
"schema": {
69+
"type": "integer",
70+
"format": "int64"
71+
}
72+
}
73+
],
74+
"responses": {
75+
"200": {
76+
"description": "The requested soda",
77+
"content": {
78+
"application/json": {
79+
"schema": {
80+
"$ref": "#/components/schemas/Soda"
81+
}
82+
}
83+
}
84+
},
85+
"404": {
86+
"description": "Soda not found"
87+
}
88+
}
89+
},
90+
"put": {
91+
"summary": "Update details of a specific soda",
92+
"operationId": "updateSodaById",
93+
"parameters": [
94+
{
95+
"name": "sodaId",
96+
"in": "path",
97+
"description": "ID of the soda to update",
98+
"required": true,
99+
"schema": {
100+
"type": "integer",
101+
"format": "int64"
102+
}
103+
}
104+
],
105+
"requestBody": {
106+
"required": true,
107+
"content": {
108+
"application/json": {
109+
"schema": {
110+
"$ref": "#/components/schemas/UpdateSoda"
111+
}
112+
}
113+
}
114+
},
115+
"responses": {
116+
"200": {
117+
"description": "The updated soda",
118+
"content": {
119+
"application/json": {
120+
"schema": {
121+
"$ref": "#/components/schemas/Soda"
122+
}
123+
}
124+
}
125+
},
126+
"404": {
127+
"description": "Soda not found"
128+
}
129+
}
130+
},
131+
"delete": {
132+
"summary": "Delete a specific soda from the store",
133+
"operationId": "deleteSodaById",
134+
"parameters": [
135+
{
136+
"name": "sodaId",
137+
"in": "path",
138+
"description": "ID of the soda to delete",
139+
"required": true,
140+
"schema": {
141+
"type": "integer",
142+
"format": "int64"
143+
}
144+
}
145+
],
146+
"responses": {
147+
"204": {
148+
"description": "Soda successfully deleted"
149+
},
150+
"404": {
151+
"description": "Soda not found"
152+
}
153+
}
154+
}
155+
}
156+
},
157+
"components": {
158+
"schemas": {
159+
"Soda": {
160+
"type": "object",
161+
"properties": {
162+
"id": {
163+
"type": "integer",
164+
"format": "int64"
165+
},
166+
"name": {
167+
"type": "string"
168+
},
169+
"brand": {
170+
"type": "string"
171+
},
172+
"flavor": {
173+
"type": "string"
174+
},
175+
"price": {
176+
"type": "number",
177+
"format": "float"
178+
}
179+
},
180+
"required": ["name", "brand", "flavor", "price"]
181+
},
182+
"NewSoda": {
183+
"type": "object",
184+
"properties": {
185+
"name": {
186+
"type": "string"
187+
},
188+
"brand": {
189+
"type": "string"
190+
},
191+
"zero": {
192+
"type": "boolean"
193+
},
194+
"since": {
195+
"type": "string",
196+
"format": "date"
197+
},
198+
"flavor": {
199+
"type": "string"
200+
},
201+
"price": {
202+
"type": "number",
203+
"format": "float"
204+
}
205+
},
206+
"required": ["name", "brand", "flavor", "price"]
207+
},
208+
"UpdateSoda": {
209+
"type": "object",
210+
"properties": {
211+
"name": {
212+
"type": "string"
213+
},
214+
"zero": {
215+
"type": "boolean"
216+
},
217+
"since": {
218+
"type": "string",
219+
"format": "date"
220+
},
221+
"brand": {
222+
"type": "string"
223+
},
224+
"flavor": {
225+
"type": "string"
226+
},
227+
"price": {
228+
"type": "number",
229+
"format": "float"
230+
}
231+
}
232+
}
233+
}
234+
}
235+
}

0 commit comments

Comments
 (0)