Skip to content

Commit 3b92a72

Browse files
dependabot[bot]CharlesDuboisSAPbot-sdk-js
authored
Better constructor for generated clients (Cloud SDK 5.14.0 update) (#148)
* chore: [DevOps] bump the production-minor-patch group with 3 updates Bumps the production-minor-patch group with 3 updates: com.sap.cloud.sdk:sdk-bom, com.sap.cloud.sdk.datamodel:openapi-generator-maven-plugin and [com.puppycrawl.tools:checkstyle](https://github.com/checkstyle/checkstyle). Updates `com.sap.cloud.sdk:sdk-bom` from 5.13.0 to 5.14.0 Updates `com.sap.cloud.sdk.datamodel:openapi-generator-maven-plugin` from 5.13.0 to 5.14.0 Updates `com.puppycrawl.tools:checkstyle` from 10.20.0 to 10.20.1 - [Release notes](https://github.com/checkstyle/checkstyle/releases) - [Commits](checkstyle/checkstyle@checkstyle-10.20.0...checkstyle-10.20.1) --- updated-dependencies: - dependency-name: com.sap.cloud.sdk:sdk-bom dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-minor-patch - dependency-name: com.sap.cloud.sdk.datamodel:openapi-generator-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor dependency-group: production-minor-patch - dependency-name: com.puppycrawl.tools:checkstyle dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-minor-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Used aiSdkConstructor * Formatting * Formatting --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: I538344 <[email protected]> Co-authored-by: SAP Cloud SDK Bot <[email protected]>
1 parent 0c4d933 commit 3b92a72

File tree

249 files changed

+485
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+485
-424
lines changed

.pipeline/pmd.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes">
2828
<priority>3</priority>
2929
</rule>
30-
<rule ref="category/java/errorprone.xml/NonCaseLabelInSwitchStatement">
30+
<rule ref="category/java/errorprone.xml/NonCaseLabelInSwitch">
3131
<priority>3</priority>
3232
</rule>
3333
<rule ref="category/java/bestpractices.xml/PreserveStackTrace">

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ After restarting your application, you should see an "aicore" entry in the `VCAP
177177

178178
```java
179179
Destination destination = DestinationAccessor.getDestination("my-aicore");
180-
AiCoreService client = new AiCoreService().withDestination(destination);
180+
AiCoreService aiCoreService = new AiCoreService().withDestination(destination);
181+
DeploymentApi client = new DeploymentApi(aiCoreService);
181182
```
182183

183184
</details>
@@ -253,14 +254,7 @@ For more detailed information and advanced usage, please refer to the following:
253254

254255
### _"How to add a custom header to AI Core requests?"_
255256

256-
To add a header to AI Core requests, use the following code:
257-
258-
```java
259-
ApiClient client = new AiCoreService().client().addDefaultHeader("header-key", "header-value");
260-
DeploymentApi api = new DeploymentApi(client);
261-
```
262-
263-
For more customization, creating a [HeaderProvider](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations#about-headerproviders) is also possible.
257+
Create a [HeaderProvider](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations#about-headerproviders).
264258

265259

266260
### _"There's a vulnerability warning `CVE-2021-41251`?"_

core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
<removeOperationIdPrefix>true</removeOperationIdPrefix>
183183
<removeOperationIdPrefixDelimiter>\.</removeOperationIdPrefixDelimiter>
184184
<removeOperationIdPrefixCount>3</removeOperationIdPrefixCount>
185+
<aiSdkConstructor>true</aiSdkConstructor>
185186
</additionalProperties>
186187
</configuration>
187188
</execution>

core/src/main/java/com/sap/ai/sdk/core/AiCoreService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public AiCoreDeployment forDeployment(@Nonnull final String deploymentId) {
135135
public AiCoreDeployment forDeploymentByModel(@Nonnull final AiModel model)
136136
throws NoSuchElementException {
137137
return new AiCoreDeployment(
138-
this, () -> DEPLOYMENT_CACHE.getDeploymentIdByModel(this.client(), resourceGroup, model));
138+
this, () -> DEPLOYMENT_CACHE.getDeploymentIdByModel(this, resourceGroup, model));
139139
}
140140

141141
/**
@@ -150,8 +150,7 @@ public AiCoreDeployment forDeploymentByModel(@Nonnull final AiModel model)
150150
public AiCoreDeployment forDeploymentByScenario(@Nonnull final String scenarioId)
151151
throws NoSuchElementException {
152152
return new AiCoreDeployment(
153-
this,
154-
() -> DEPLOYMENT_CACHE.getDeploymentIdByScenario(client(), resourceGroup, scenarioId));
153+
this, () -> DEPLOYMENT_CACHE.getDeploymentIdByScenario(this, resourceGroup, scenarioId));
155154
}
156155

157156
/**
@@ -193,7 +192,6 @@ protected DefaultHttpDestination.Builder getDestinationBuilder(
193192
* @throws DestinationAccessException If the destination cannot be accessed.
194193
* @throws DestinationNotFoundException If the destination cannot be found.
195194
*/
196-
@SuppressWarnings("UnstableApiUsage")
197195
@Nonnull
198196
protected ApiClient getApiClient(@Nonnull final Destination destination) {
199197
val objectMapper =
@@ -223,6 +221,6 @@ protected ApiClient getApiClient(@Nonnull final Destination destination) {
223221
* @param resourceGroup the resource group of the deleted deployment, usually "default".
224222
*/
225223
public void reloadCachedDeployments(@Nonnull final String resourceGroup) {
226-
DEPLOYMENT_CACHE.resetCache(client(), resourceGroup);
224+
DEPLOYMENT_CACHE.resetCache(this, resourceGroup);
227225
}
228226
}

core/src/main/java/com/sap/ai/sdk/core/DeploymentCache.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.sap.ai.sdk.core.client.DeploymentApi;
44
import com.sap.ai.sdk.core.client.model.AiDeployment;
5-
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
65
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
76
import java.util.HashSet;
87
import java.util.Map;
@@ -30,14 +29,15 @@ class DeploymentCache {
3029
*
3130
* <p><b>Call this whenever a deployment is deleted.</b>
3231
*
33-
* @param client the API client to query deployments.
32+
* @param aiCoreDestination the configured connection to the AI Core service.
3433
* @param resourceGroup the resource group, usually "default".
3534
*/
36-
void resetCache(@Nonnull final ApiClient client, @Nonnull final String resourceGroup) {
35+
void resetCache(
36+
@Nonnull final AiCoreDestination aiCoreDestination, @Nonnull final String resourceGroup) {
3737
cache.remove(resourceGroup);
3838
try {
3939
val deployments =
40-
new HashSet<>(new DeploymentApi(client).query(resourceGroup).getResources());
40+
new HashSet<>(new DeploymentApi(aiCoreDestination).query(resourceGroup).getResources());
4141
cache.put(resourceGroup, deployments);
4242
} catch (final OpenApiRequestException e) {
4343
log.error("Failed to load deployments into cache", e);
@@ -48,22 +48,22 @@ void resetCache(@Nonnull final ApiClient client, @Nonnull final String resourceG
4848
* Get the deployment id from the foundation model object. If there are multiple deployments of
4949
* the same model, the first one is returned.
5050
*
51-
* @param client the API client to maybe reset the cache if the deployment is not found.
51+
* @param aiCoreDestination the configured connection to the AI Core service.
5252
* @param resourceGroup the resource group, usually "default".
5353
* @param model the foundation model.
5454
* @return the deployment id.
5555
* @throws NoSuchElementException if no running deployment is found for the model.
5656
*/
5757
@Nonnull
5858
String getDeploymentIdByModel(
59-
@Nonnull final ApiClient client,
59+
@Nonnull final AiCoreDestination aiCoreDestination,
6060
@Nonnull final String resourceGroup,
6161
@Nonnull final AiModel model)
6262
throws NoSuchElementException {
6363
return getDeploymentIdByModel(resourceGroup, model)
6464
.orElseGet(
6565
() -> {
66-
resetCache(client, resourceGroup);
66+
resetCache(aiCoreDestination, resourceGroup);
6767
return getDeploymentIdByModel(resourceGroup, model)
6868
.orElseThrow(
6969
() ->
@@ -84,22 +84,22 @@ private Optional<String> getDeploymentIdByModel(
8484
* Get the deployment id from the scenario id. If there are multiple deployments of the * same
8585
* model, the first one is returned.
8686
*
87-
* @param client the API client to maybe reset the cache if the deployment is not found.
87+
* @param aiCoreDestination the configured connection to the AI Core service.
8888
* @param resourceGroup the resource group, usually "default".
8989
* @param scenarioId the scenario id, can be "orchestration".
9090
* @return the deployment id.
9191
* @throws NoSuchElementException if no running deployment is found for the scenario.
9292
*/
9393
@Nonnull
9494
String getDeploymentIdByScenario(
95-
@Nonnull final ApiClient client,
95+
@Nonnull final AiCoreDestination aiCoreDestination,
9696
@Nonnull final String resourceGroup,
9797
@Nonnull final String scenarioId)
9898
throws NoSuchElementException {
9999
return getDeploymentIdByScenario(resourceGroup, scenarioId)
100100
.orElseGet(
101101
() -> {
102-
resetCache(client, resourceGroup);
102+
resetCache(aiCoreDestination, resourceGroup);
103103
return getDeploymentIdByScenario(resourceGroup, scenarioId)
104104
.orElseThrow(
105105
() ->

core/src/main/java/com/sap/ai/sdk/core/client/ApplicationApi.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sap.ai.sdk.core.client;
22

3-
import com.google.common.annotations.Beta;
3+
import com.sap.ai.sdk.core.AiCoreDestination;
4+
import com.sap.ai.sdk.core.AiCoreService;
45
import com.sap.ai.sdk.core.client.model.BckndAllArgoCDApplicationData;
56
import com.sap.ai.sdk.core.client.model.BckndArgoCDApplicationBaseData;
67
import com.sap.ai.sdk.core.client.model.BckndArgoCDApplicationCreationResponse;
@@ -10,8 +11,6 @@
1011
import com.sap.ai.sdk.core.client.model.BckndArgoCDApplicationRefreshResponse;
1112
import com.sap.ai.sdk.core.client.model.BckndArgoCDApplicationStatus;
1213
import com.sap.ai.sdk.core.client.model.KubesubmitV4ApplicationsCreateRequest;
13-
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
14-
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
1514
import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService;
1615
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
1716
import java.util.HashMap;
@@ -38,24 +37,19 @@
3837
* data and trained models.
3938
*/
4039
public class ApplicationApi extends AbstractOpenApiService {
41-
/**
42-
* Instantiates this API class to invoke operations on the AI Core.
43-
*
44-
* @param httpDestination The destination that API should be used with
45-
*/
46-
public ApplicationApi(@Nonnull final Destination httpDestination) {
47-
super(httpDestination);
40+
41+
/** Instantiates this API class to invoke operations on the AI Core */
42+
public ApplicationApi() {
43+
super(new AiCoreService().client());
4844
}
4945

5046
/**
51-
* Instantiates this API class to invoke operations on the AI Core based on a given {@link
52-
* ApiClient}.
47+
* Instantiates this API class to invoke operations on the AI Core
5348
*
54-
* @param apiClient ApiClient to invoke the API on
49+
* @param aiCoreDestination The configured connectivity instance to AI Core
5550
*/
56-
@Beta
57-
public ApplicationApi(@Nonnull final ApiClient apiClient) {
58-
super(apiClient);
51+
public ApplicationApi(@Nonnull final AiCoreDestination aiCoreDestination) {
52+
super(aiCoreDestination.client());
5953
}
6054

6155
/**

core/src/main/java/com/sap/ai/sdk/core/client/ArtifactApi.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.sap.ai.sdk.core.client;
22

3-
import com.google.common.annotations.Beta;
3+
import com.sap.ai.sdk.core.AiCoreDestination;
4+
import com.sap.ai.sdk.core.AiCoreService;
45
import com.sap.ai.sdk.core.client.model.AiArtifact;
56
import com.sap.ai.sdk.core.client.model.AiArtifactCreationResponse;
67
import com.sap.ai.sdk.core.client.model.AiArtifactList;
78
import com.sap.ai.sdk.core.client.model.AiArtifactPostData;
8-
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
99
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
1010
import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService;
1111
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
@@ -34,24 +34,19 @@
3434
* data and trained models.
3535
*/
3636
public class ArtifactApi extends AbstractOpenApiService {
37-
/**
38-
* Instantiates this API class to invoke operations on the AI Core.
39-
*
40-
* @param httpDestination The destination that API should be used with
41-
*/
42-
public ArtifactApi(@Nonnull final Destination httpDestination) {
43-
super(httpDestination);
37+
38+
/** Instantiates this API class to invoke operations on the AI Core */
39+
public ArtifactApi() {
40+
super(new AiCoreService().client());
4441
}
4542

4643
/**
47-
* Instantiates this API class to invoke operations on the AI Core based on a given {@link
48-
* ApiClient}.
44+
* Instantiates this API class to invoke operations on the AI Core
4945
*
50-
* @param apiClient ApiClient to invoke the API on
46+
* @param aiCoreDestination The configured connectivity instance to AI Core
5147
*/
52-
@Beta
53-
public ArtifactApi(@Nonnull final ApiClient apiClient) {
54-
super(apiClient);
48+
public ArtifactApi(@Nonnull final AiCoreDestination aiCoreDestination) {
49+
super(aiCoreDestination.client());
5550
}
5651

5752
/**

core/src/main/java/com/sap/ai/sdk/core/client/ConfigurationApi.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.sap.ai.sdk.core.client;
22

3-
import com.google.common.annotations.Beta;
3+
import com.sap.ai.sdk.core.AiCoreDestination;
4+
import com.sap.ai.sdk.core.AiCoreService;
45
import com.sap.ai.sdk.core.client.model.AiConfiguration;
56
import com.sap.ai.sdk.core.client.model.AiConfigurationBaseData;
67
import com.sap.ai.sdk.core.client.model.AiConfigurationCreationResponse;
78
import com.sap.ai.sdk.core.client.model.AiConfigurationList;
8-
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
99
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
1010
import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService;
1111
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
@@ -34,24 +34,19 @@
3434
* data and trained models.
3535
*/
3636
public class ConfigurationApi extends AbstractOpenApiService {
37-
/**
38-
* Instantiates this API class to invoke operations on the AI Core.
39-
*
40-
* @param httpDestination The destination that API should be used with
41-
*/
42-
public ConfigurationApi(@Nonnull final Destination httpDestination) {
43-
super(httpDestination);
37+
38+
/** Instantiates this API class to invoke operations on the AI Core */
39+
public ConfigurationApi() {
40+
super(new AiCoreService().client());
4441
}
4542

4643
/**
47-
* Instantiates this API class to invoke operations on the AI Core based on a given {@link
48-
* ApiClient}.
44+
* Instantiates this API class to invoke operations on the AI Core
4945
*
50-
* @param apiClient ApiClient to invoke the API on
46+
* @param aiCoreDestination The configured connectivity instance to AI Core
5147
*/
52-
@Beta
53-
public ConfigurationApi(@Nonnull final ApiClient apiClient) {
54-
super(apiClient);
48+
public ConfigurationApi(@Nonnull final AiCoreDestination aiCoreDestination) {
49+
super(aiCoreDestination.client());
5550
}
5651

5752
/**

core/src/main/java/com/sap/ai/sdk/core/client/DeploymentApi.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sap.ai.sdk.core.client;
22

3-
import com.google.common.annotations.Beta;
3+
import com.sap.ai.sdk.core.AiCoreDestination;
4+
import com.sap.ai.sdk.core.AiCoreService;
45
import com.sap.ai.sdk.core.client.model.AiDeploymentBulkModificationRequest;
56
import com.sap.ai.sdk.core.client.model.AiDeploymentBulkModificationResponse;
67
import com.sap.ai.sdk.core.client.model.AiDeploymentCreationRequest;
@@ -11,7 +12,6 @@
1112
import com.sap.ai.sdk.core.client.model.AiDeploymentModificationResponse;
1213
import com.sap.ai.sdk.core.client.model.AiDeploymentResponseWithDetails;
1314
import com.sap.ai.sdk.core.client.model.RTALogCommonResponse;
14-
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
1515
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
1616
import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService;
1717
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
@@ -41,24 +41,19 @@
4141
* data and trained models.
4242
*/
4343
public class DeploymentApi extends AbstractOpenApiService {
44-
/**
45-
* Instantiates this API class to invoke operations on the AI Core.
46-
*
47-
* @param httpDestination The destination that API should be used with
48-
*/
49-
public DeploymentApi(@Nonnull final Destination httpDestination) {
50-
super(httpDestination);
44+
45+
/** Instantiates this API class to invoke operations on the AI Core */
46+
public DeploymentApi() {
47+
super(new AiCoreService().client());
5148
}
5249

5350
/**
54-
* Instantiates this API class to invoke operations on the AI Core based on a given {@link
55-
* ApiClient}.
51+
* Instantiates this API class to invoke operations on the AI Core
5652
*
57-
* @param apiClient ApiClient to invoke the API on
53+
* @param aiCoreDestination The configured connectivity instance to AI Core
5854
*/
59-
@Beta
60-
public DeploymentApi(@Nonnull final ApiClient apiClient) {
61-
super(apiClient);
55+
public DeploymentApi(@Nonnull final AiCoreDestination aiCoreDestination) {
56+
super(aiCoreDestination.client());
6257
}
6358

6459
/**

0 commit comments

Comments
 (0)