Skip to content

Commit 2e6e126

Browse files
committed
fix: Merged the main branch code and adjusted getRequiredVariables to handle cases where subclasses do not support this method.
Signed-off-by: Sun Yuhan <[email protected]>
1 parent c920cbf commit 2e6e126

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

spring-ai-commons/src/main/java/org/springframework/ai/template/TemplateRenderer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Set;
2121
import java.util.function.BiFunction;
2222

23+
import javax.naming.OperationNotSupportedException;
24+
2325
/**
2426
* Renders a template using a given strategy.
2527
*
@@ -32,6 +34,8 @@ public interface TemplateRenderer extends BiFunction<String, Map<String, Object>
3234
@Override
3335
String apply(String template, Map<String, Object> variables);
3436

35-
Set<String> getRequiredVariables(String template);
37+
default Set<String> getRequiredVariables(String template) throws OperationNotSupportedException {
38+
throw new OperationNotSupportedException("getRequiredVariables is not supported");
39+
}
3640

3741
}

spring-ai-template-st/src/test/java/org/springframework/ai/template/st/StTemplateRendererTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ void shouldRenderTemplateWithBuiltInFunctions() {
299299
assertThat(result).isEqualTo("Hello!");
300300
}
301301

302-
303302
/**
304303
* Tests that property access syntax like {test.name} is correctly handled. The
305304
* top-level variable 'test' should be identified as required, but 'name' should not.
@@ -351,12 +350,11 @@ void shouldValidatePropertyAccessCorrectly() {
351350
missingVariables.put("profile", Map.of("name", "John"));
352351

353352
assertThatThrownBy(() -> renderer.apply("Hello {user.profile.name}!", missingVariables))
354-
.isInstanceOf(IllegalStateException.class)
355-
.hasMessageContaining(
356-
"Not all variables were replaced in the template. Missing variable names are: [user]");
353+
.isInstanceOf(IllegalStateException.class)
354+
.hasMessageContaining(
355+
"Not all variables were replaced in the template. Missing variable names are: [user]");
357356
}
358357

359-
360358
/**
361359
* Test whether the required variables can be correctly extracted from the template.
362360
*/

0 commit comments

Comments
 (0)