Skip to content

Commit cafd804

Browse files
Fix InputBuilder lazy initialization to prevent validation errors (#1444)
* no-issue: Fix eagerly set inputBuilder from/schema to avoid validation errors in runtime Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix co-pilot comments Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> * Restore db-samples files to match main --------- Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent a323be7 commit cafd804

2 files changed

Lines changed: 366 additions & 2 deletions

File tree

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/InputBuilder.java

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,70 @@ public class InputBuilder {
2929

3030
InputBuilder() {
3131
this.input = new Input();
32-
this.input.setFrom(new InputFrom());
33-
this.input.setSchema(new SchemaUnion());
3432
}
3533

3634
public InputBuilder from(String expr) {
35+
if (expr == null) {
36+
this.input.setFrom(null);
37+
return this;
38+
}
39+
40+
if (this.input.getFrom() == null) {
41+
this.input.setFrom(new InputFrom());
42+
} else {
43+
this.input.getFrom().setObject(null);
44+
}
45+
3746
this.input.getFrom().setString(expr);
3847
return this;
3948
}
4049

4150
public InputBuilder from(Object object) {
51+
if (object == null) {
52+
this.input.setFrom(null);
53+
return this;
54+
}
55+
56+
if (this.input.getFrom() == null) {
57+
this.input.setFrom(new InputFrom());
58+
} else {
59+
this.input.getFrom().setString(null);
60+
}
61+
4262
this.input.getFrom().setObject(object);
4363
return this;
4464
}
4565

4666
public InputBuilder schema(Object schema) {
67+
if (schema == null) {
68+
this.input.setSchema(null);
69+
return this;
70+
}
71+
72+
if (this.input.getSchema() == null) {
73+
this.input.setSchema(new SchemaUnion());
74+
} else {
75+
// Clear external schema when setting inline schema
76+
this.input.getSchema().setSchemaExternal(null);
77+
}
78+
4779
this.input.getSchema().setSchemaInline(new SchemaInline(schema));
4880
return this;
4981
}
5082

5183
public InputBuilder schema(String schema) {
84+
if (schema == null) {
85+
this.input.setSchema(null);
86+
return this;
87+
}
88+
89+
if (this.input.getSchema() == null) {
90+
this.input.setSchema(new SchemaUnion());
91+
} else {
92+
// Clear inline schema when setting external schema
93+
this.input.getSchema().setSchemaInline(null);
94+
}
95+
5296
this.input
5397
.getSchema()
5498
.setSchemaExternal(
@@ -61,6 +105,23 @@ public InputBuilder schema(String schema) {
61105
return this;
62106
}
63107

108+
public InputBuilder schemaAsJsonString(String schema) {
109+
if (schema == null) {
110+
this.input.setSchema(null);
111+
return this;
112+
}
113+
114+
if (this.input.getSchema() == null) {
115+
this.input.setSchema(new SchemaUnion());
116+
} else {
117+
// Clear external schema when setting inline schema
118+
this.input.getSchema().setSchemaExternal(null);
119+
}
120+
121+
this.input.getSchema().setSchemaInline(new SchemaInline(schema));
122+
return this;
123+
}
124+
64125
public Input build() {
65126
return this.input;
66127
}

0 commit comments

Comments
 (0)