Skip to content

Commit 2f61d28

Browse files
committed
Merge branch 'main' into Improve-Logging
2 parents 649f265 + cea022d commit 2f61d28

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ static ServiceBinding createServiceBinding(@Nonnull final String serviceKey)
8181
new AiCoreCredentialsInvalidException("Missing clientid in service key"));
8282
}
8383

84+
if (credentials.get("clientsecret") != null && credentials.get("credential-type") == null) {
85+
// add missing "credential-type: binding-secret"
86+
credentials.put("credential-type", "binding-secret");
87+
}
88+
8489
return new DefaultServiceBindingBuilder()
8590
.withServiceIdentifier(ServiceIdentifier.AI_CORE)
8691
.withCredentials(credentials)

core/src/test/java/com/sap/ai/sdk/core/AiCoreServiceKeyAccessorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,32 @@ void testMalformedDotenv() {
5555
assertThatThrownBy(accessor::getServiceBindings)
5656
.isInstanceOf(ServiceBindingAccessException.class);
5757
}
58+
59+
@Test
60+
void testServiceBindingCreation() {
61+
var serviceKeyWithoutCredentialType =
62+
"""
63+
{
64+
"clientid": "",
65+
"clientsecret": ""
66+
}
67+
""";
68+
var binding1 = AiCoreServiceKeyAccessor.createServiceBinding(serviceKeyWithoutCredentialType);
69+
assertThat(binding1.getCredentials().containsKey("credential-type"))
70+
.describedAs("The missing 'credential-type' should have automatically been added")
71+
.isTrue();
72+
var serviceKeyWithCredentialType =
73+
"""
74+
{
75+
"clientid": "",
76+
"clientsecret": "",
77+
"credential-type": "foo"
78+
}
79+
}
80+
""";
81+
var binding2 = AiCoreServiceKeyAccessor.createServiceBinding(serviceKeyWithCredentialType);
82+
assertThat(binding2.getCredentials().get("credential-type"))
83+
.describedAs("The 'credential-type' field should not get overwritten")
84+
.isEqualTo("foo");
85+
}
5886
}

docs/release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
### 📈 Improvements
1818

19-
-
19+
- [Core] If the AI Core credentials used are missing an explicit `credential-type` but `clientid` and `clientsecret` are present then `"credential-type": "binding-secret"` is inferred automatically.
20+
2021

2122
### 🐛 Fixed Issues
2223

orchestration/src/main/java/com/sap/ai/sdk/orchestration/ResponseJsonSchema.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class ResponseJsonSchema {
3333
@Nonnull Map<String, Object> schemaMap;
3434
@Nonnull String name;
3535
@Nullable String description;
36+
37+
/**
38+
* ⚠️ Fields of the schema class should be annotated with {@code @JsonProperty(required = true)}
39+
* to not fail requests if set to true.
40+
*/
3641
@Nullable Boolean strict;
3742

3843
/**
@@ -51,6 +56,9 @@ public static ResponseJsonSchema fromMap(
5156
/**
5257
* Create a new instance of {@link ResponseJsonSchema} from a given class.
5358
*
59+
* <p>⚠️ Fields of the schema class should be annotated with {@code @JsonProperty(required =
60+
* true)}.
61+
*
5462
* @param classType The class to generate the schema from
5563
* @return The new instance of {@link ResponseJsonSchema}
5664
*/

sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/GroundingTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.time.format.TextStyle;
1717
import java.util.Locale;
1818
import java.util.UUID;
19-
import org.junit.jupiter.api.Disabled;
2019
import org.junit.jupiter.api.Test;
2120

2221
class GroundingTest {
@@ -52,7 +51,6 @@ void testRepositoriesGetAll() {
5251
}
5352

5453
@Test
55-
@Disabled("Temporary disabled because of an unresolved minor bug") // SAP/ai-sdk-java-backlog#232
5654
void testCreateDeleteCollection() {
5755
final var controller = new GroundingController();
5856

0 commit comments

Comments
 (0)