Skip to content

Commit c7ebefe

Browse files
vaadin-bottomivirkkiclaude
authored
fix: fail build when plot options schemas are not generated (#10049) (CP: 25.3) (#10054)
This PR cherry-picks changes from the original PR #10049 to branch 25.3. --- #### Original PR description > ## Summary > - The chart plot options schemas are generated at build time from the chart model sources and shipped in the jar. When the source directory was missing the generator only logged a warning and skipped, so a build with tests skipped could publish a jar without schemas and the tool would report every chart type as unknown. The generator now fails the build in that case, and a missing resource at runtime is logged as an error. > - Added tests that check the generated resource is on the classpath, covers every supported chart type with descriptions, and is exposed through `ChartAIController`'s tools, so a regression in generation or packaging fails the module's unit tests directly. Co-authored-by: Tomi Virkki <tomivirkki@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 2c2264b commit c7ebefe

4 files changed

Lines changed: 135 additions & 4 deletions

File tree

‎vaadin-ai-components-flow-parent/vaadin-ai-extensions-flow/src/main/java/com/vaadin/flow/component/ai/chart/PlotOptionsSchema.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import java.util.Map;
1717
import java.util.Set;
1818

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
1922
import com.vaadin.flow.component.charts.model.AbstractPlotOptions;
2023
import com.vaadin.flow.internal.JacksonUtils;
2124

@@ -30,6 +33,9 @@
3033
*/
3134
final class PlotOptionsSchema implements Serializable {
3235

36+
private static final Logger LOGGER = LoggerFactory
37+
.getLogger(PlotOptionsSchema.class);
38+
3339
private static final String SCHEMAS_RESOURCE = "plot-options-schemas.json";
3440

3541
private static final Map<String, String> SCHEMAS;
@@ -75,6 +81,11 @@ private static Map<String, String> loadSchemas() {
7581
try (var input = PlotOptionsSchema.class
7682
.getResourceAsStream(SCHEMAS_RESOURCE)) {
7783
if (input == null) {
84+
LOGGER.error(
85+
"Plot options schema resource '{}' is missing from the "
86+
+ "classpath. The get_plot_options_schema tool "
87+
+ "will report every chart type as unknown.",
88+
SCHEMAS_RESOURCE);
7889
return Map.of();
7990
}
8091
JsonNode root = JacksonUtils.getMapper().readTree(input);

‎vaadin-ai-components-flow-parent/vaadin-ai-extensions-flow/src/main/java/com/vaadin/flow/component/ai/chart/PlotOptionsSchemaGenerator.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
* type's plot options, including property descriptions parsed from JavaDoc.
7373
* <p>
7474
* Invoked automatically during the Maven build via {@code exec-maven-plugin}.
75-
* The output is consumed by {@link PlotOptionsSchema} at runtime.
75+
* The output is consumed by {@link PlotOptionsSchema} at runtime. The build
76+
* fails if the chart model sources cannot be found, so the published jar never
77+
* silently ships without the schemas.
7678
*
7779
* @since 25.3
7880
*/
@@ -151,14 +153,21 @@ public static void main(String[] args) throws IOException {
151153
Path outputFile = Path.of(args[1]);
152154

153155
if (!Files.isDirectory(sourceDir)) {
154-
LOGGER.warn("Source directory not found: {}"
155-
+ " — skipping schema generation", sourceDir);
156-
return;
156+
throw new IllegalStateException(
157+
"Chart model source directory not found: " + sourceDir
158+
+ ". The plot options schemas cannot be generated "
159+
+ "without it.");
157160
}
158161

159162
// Parse descriptions from source files
160163
Map<String, Map<String, String>> descriptions = parseDescriptions(
161164
sourceDir);
165+
if (descriptions.isEmpty()) {
166+
throw new IllegalStateException(
167+
"No chart model sources found in " + sourceDir
168+
+ ". The plot options schemas would be generated "
169+
+ "without property descriptions.");
170+
}
162171

163172
// Build complete schemas for each chart type
164173
var plotOptionsByType = buildTypeMap();

‎vaadin-ai-components-flow-parent/vaadin-ai-extensions-flow/src/test/java/com/vaadin/flow/component/ai/chart/ChartAIControllerTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,26 @@ void toolNamesIncludeExpected() {
8787
Assertions.assertTrue(names.contains("get_chart_state"));
8888
Assertions.assertTrue(names.contains("update_chart_configuration"));
8989
Assertions.assertTrue(names.contains("update_chart_data_source"));
90+
Assertions.assertTrue(names.contains("get_plot_options_schema"));
9091
}
9192

9293
@Test
9394
void instructionsToolIsFirst() {
9495
Assertions.assertEquals("get_chart_instructions",
9596
controller.getTools().get(0).getName());
9697
}
98+
99+
@Test
100+
void plotOptionsSchemaTool_returnsGeneratedSchema() {
101+
var tool = findTool(controller.getTools(),
102+
"get_plot_options_schema");
103+
var result = tool.execute(json("{\"chartType\":\"column\"}"));
104+
Assertions.assertFalse(result.startsWith("Error"), result);
105+
var schema = json(result);
106+
Assertions.assertEquals("object", schema.get("type").asString());
107+
Assertions.assertTrue(schema.get("properties").has("stacking"),
108+
"Column schema should expose plot option properties");
109+
}
97110
}
98111

99112
@Nested
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright 2000-2026 Vaadin Ltd.
3+
*
4+
* This program is available under Vaadin Commercial License and Service Terms.
5+
*
6+
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} for the full
7+
* license.
8+
*/
9+
package com.vaadin.flow.component.ai.chart;
10+
11+
import java.nio.file.Path;
12+
13+
import org.junit.jupiter.api.Assertions;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.io.TempDir;
16+
17+
import com.vaadin.flow.internal.JacksonUtils;
18+
19+
import tools.jackson.databind.JsonNode;
20+
21+
/**
22+
* Verifies that the plot options schemas generated at build time by
23+
* {@link PlotOptionsSchemaGenerator} end up on the classpath and are usable
24+
* through {@link PlotOptionsSchema}.
25+
*/
26+
class PlotOptionsSchemaTest {
27+
28+
private static final String RESOURCE = "plot-options-schemas.json";
29+
30+
@Test
31+
void schemaResource_isOnClasspath() {
32+
Assertions.assertNotNull(PlotOptionsSchema.class.getResource(RESOURCE),
33+
RESOURCE + " is missing next to PlotOptionsSchema. It is "
34+
+ "generated into the build output directory by the "
35+
+ "exec-maven-plugin execution in this module's pom, "
36+
+ "so the module must be built with Maven.");
37+
}
38+
39+
@Test
40+
void everySupportedType_hasSchema() {
41+
var types = PlotOptionsSchema.supportedTypes();
42+
Assertions.assertFalse(types.isEmpty());
43+
for (String type : types) {
44+
String schema = PlotOptionsSchema.getSchema(type);
45+
Assertions.assertNotNull(schema,
46+
"No generated schema for chart type '" + type + "'");
47+
JsonNode node = JacksonUtils.readTree(schema);
48+
Assertions.assertEquals("object", node.get("type").asString());
49+
Assertions.assertFalse(node.get("properties").isEmpty(),
50+
"Schema for '" + type + "' has no properties");
51+
}
52+
}
53+
54+
@Test
55+
void everySchema_hasDescriptionsFromChartSources() {
56+
for (String type : PlotOptionsSchema.supportedTypes()) {
57+
JsonNode properties = JacksonUtils
58+
.readTree(PlotOptionsSchema.getSchema(type))
59+
.get("properties");
60+
boolean described = false;
61+
for (var property : properties.properties()) {
62+
if (property.getValue().has("description")) {
63+
described = true;
64+
break;
65+
}
66+
}
67+
Assertions.assertTrue(described,
68+
"Schema for '" + type
69+
+ "' has no property descriptions. The generator "
70+
+ "could not read the chart model sources.");
71+
}
72+
}
73+
74+
@Test
75+
void unknownType_returnsNull() {
76+
Assertions.assertNull(PlotOptionsSchema.getSchema("nonexistent"));
77+
Assertions.assertNull(
78+
PlotOptionsSchema.getPlotOptionsClass("nonexistent"));
79+
}
80+
81+
@Test
82+
void generator_missingSourceDirectory_fails(@TempDir Path tempDir) {
83+
var missingSources = tempDir.resolve("missing").toString();
84+
var output = tempDir.resolve("out.json").toString();
85+
Assertions.assertThrows(IllegalStateException.class,
86+
() -> PlotOptionsSchemaGenerator
87+
.main(new String[] { missingSources, output }));
88+
}
89+
90+
@Test
91+
void generator_sourceDirectoryWithoutChartModel_fails(
92+
@TempDir Path tempDir) {
93+
var output = tempDir.resolve("out.json").toString();
94+
Assertions.assertThrows(IllegalStateException.class,
95+
() -> PlotOptionsSchemaGenerator
96+
.main(new String[] { tempDir.toString(), output }));
97+
}
98+
}

0 commit comments

Comments
 (0)