Skip to content

Commit 9c9d5e2

Browse files
committed
exhaustive tests
1 parent be9c170 commit 9c9d5e2

File tree

11 files changed

+1957
-441
lines changed

11 files changed

+1957
-441
lines changed

jtd-esm-codegen/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<artifactId>assertj-core</artifactId>
5858
<scope>test</scope>
5959
</dependency>
60+
<dependency>
61+
<groupId>net.jqwik</groupId>
62+
<artifactId>jqwik</artifactId>
63+
<version>1.9.3</version>
64+
<scope>test</scope>
65+
</dependency>
6066
</dependencies>
6167

6268
<build>

jtd-esm-codegen/src/main/java/io/github/simbo1905/json/jtd/codegen/EsmRenderer.java

Lines changed: 466 additions & 159 deletions
Large diffs are not rendered by default.

jtd-esm-codegen/src/main/java/io/github/simbo1905/json/jtd/codegen/JtdAst.java

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,59 @@
33
import java.util.List;
44
import java.util.Map;
55

6-
/// Minimal AST for the experimental "flat JTD → ESM validator" code generator.
6+
/// Complete AST for RFC 8927 JTD code generation.
7+
/// Supports all schema forms: empty, type, enum, elements, properties, values,
8+
/// discriminator, ref, and nullable.
79
///
8-
/// Supported JTD subset:
9-
/// - root: `properties`, `optionalProperties`, `metadata.id`
10-
/// - leaf: `{}` (empty form), `{ "type": ... }`, `{ "enum": [...] }`
10+
/// This AST is designed for stack-based code generation where each node
11+
/// knows how to generate its own validation logic.
1112
public final class JtdAst {
1213
private JtdAst() {}
1314

14-
public sealed interface JtdNode permits SchemaNode, PropertyNode, TypeNode, EnumNode, EmptyNode {}
15+
public sealed interface JtdNode permits
16+
EmptyNode, TypeNode, EnumNode, ElementsNode, PropertiesNode,
17+
ValuesNode, DiscriminatorNode, RefNode, NullableNode {}
1518

16-
public record SchemaNode(
17-
String id, // metadata.id
18-
Map<String, PropertyNode> properties,
19-
Map<String, PropertyNode> optionalProperties
20-
) implements JtdNode {}
19+
/// Root of a JTD document with metadata, definitions, and root schema.
20+
public record RootNode(
21+
String id,
22+
Map<String, JtdNode> definitions,
23+
JtdNode rootSchema
24+
) {}
2125

22-
public record PropertyNode(String name, JtdNode type) implements JtdNode {}
26+
/// Empty form {} - accepts any JSON value.
27+
public record EmptyNode() implements JtdNode {}
2328

24-
/// JTD primitive type keyword as a string, e.g. "string", "int32", "timestamp".
29+
/// Type form - validates primitive types.
30+
/// Type values: string, boolean, timestamp, int8, uint8, int16, uint16,
31+
/// int32, uint32, float32, float64
2532
public record TypeNode(String type) implements JtdNode {}
2633

27-
/// Enum values (strings only in RFC 8927).
34+
/// Enum form - validates string is one of allowed values.
2835
public record EnumNode(List<String> values) implements JtdNode {}
2936

30-
/// Empty form `{}`: accepts any JSON value.
31-
public record EmptyNode() implements JtdNode {}
32-
}
37+
/// Elements form - validates array where each element matches schema.
38+
public record ElementsNode(JtdNode schema) implements JtdNode {}
39+
40+
/// Properties form - validates object with required/optional properties.
41+
public record PropertiesNode(
42+
Map<String, JtdNode> properties,
43+
Map<String, JtdNode> optionalProperties,
44+
boolean additionalProperties
45+
) implements JtdNode {}
3346

47+
/// Values form - validates object where all values match schema.
48+
public record ValuesNode(JtdNode schema) implements JtdNode {}
49+
50+
/// Discriminator form - validates tagged unions.
51+
public record DiscriminatorNode(
52+
String discriminator,
53+
Map<String, JtdNode> mapping
54+
) implements JtdNode {}
55+
56+
/// Ref form - references a definition.
57+
public record RefNode(String ref) implements JtdNode {}
58+
59+
/// Nullable wrapper - allows null in addition to wrapped schema.
60+
public record NullableNode(JtdNode wrapped) implements JtdNode {}
61+
}

0 commit comments

Comments
 (0)