Skip to content

Commit 3300a29

Browse files
committed
change base path behaviour
1 parent 5f4d5f8 commit 3300a29

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ HttpDestination getDestination() {
6161

6262
@Nonnull
6363
static HttpDestination fromCustomBaseDestination(@Nonnull final HttpDestination destination) {
64-
// for custom base destinations we only add the client type header, since users are allowed to
65-
// pass a custom base path
66-
return addClientTypeHeader(destination);
64+
var enhancedBaseDestination = addClientTypeHeader(destination);
65+
val path = enhancedBaseDestination.getUri().getPath();
66+
if (path == null || path.isEmpty() || path.equals("/")) {
67+
return setBasePath(enhancedBaseDestination);
68+
}
69+
return enhancedBaseDestination;
6770
}
6871

6972
@Nonnull

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.sap.cloud.environment.servicebinding.api.ServiceBindingAccessor;
99
import com.sap.cloud.environment.servicebinding.api.exception.ServiceBindingAccessException;
10+
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
1011
import java.util.List;
1112
import lombok.val;
1213
import org.junit.jupiter.api.Test;
@@ -54,4 +55,19 @@ void testNoServiceBindingLoadingThrows() {
5455
var resolver = new DestinationResolver(mock);
5556
assertThatThrownBy(resolver::getDestination).isSameAs(exception);
5657
}
58+
59+
@Test
60+
void testFromCustomBaseDestination() {
61+
var destination = DefaultHttpDestination.builder("https://api.ai.sap").build();
62+
assertThat(DestinationResolver.fromCustomBaseDestination(destination).getUri())
63+
.hasToString("https://api.ai.sap/v2/");
64+
65+
destination = DefaultHttpDestination.builder("https://api.ai.sap/").build();
66+
assertThat(DestinationResolver.fromCustomBaseDestination(destination).getUri())
67+
.hasToString("https://api.ai.sap/v2/");
68+
69+
destination = DefaultHttpDestination.builder("https://api.ai.sap/foo").build();
70+
assertThat(DestinationResolver.fromCustomBaseDestination(destination).getUri())
71+
.hasToString("https://api.ai.sap/foo");
72+
}
5773
}

0 commit comments

Comments
 (0)