File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
main/java/com/sap/ai/sdk/core
test/java/com/sap/ai/sdk/core Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 77
88import com .sap .cloud .environment .servicebinding .api .ServiceBindingAccessor ;
99import com .sap .cloud .environment .servicebinding .api .exception .ServiceBindingAccessException ;
10+ import com .sap .cloud .sdk .cloudplatform .connectivity .DefaultHttpDestination ;
1011import java .util .List ;
1112import lombok .val ;
1213import 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}
You can’t perform that action at this time.
0 commit comments