Skip to content

feat(java): add SchemaGenerator compile-time type-to-JSON-Schema utility#1766

Draft
Copilot wants to merge 3 commits into
edburns/1682-java-tool-ergonomicsfrom
copilot/edburns1682-java-tool-ergonomics
Draft

feat(java): add SchemaGenerator compile-time type-to-JSON-Schema utility#1766
Copilot wants to merge 3 commits into
edburns/1682-java-tool-ergonomicsfrom
copilot/edburns1682-java-tool-ergonomics

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Compile-time schema generation utility that maps javax.lang.model types to JSON Schema represented as Map.of(...) source code literals, for use by the annotation processor (task 4.2 of the tool ergonomics plan).

SchemaGenerator.java

  • Operates exclusively with javax.lang.model APIs — no java.lang.reflect
  • generateSchemaSource(TypeMirror, Types, Elements) → schema source for a single type
  • generateParametersSchemaSource(List<VariableElement>, Types, Elements) → full parameters object schema with properties/required
  • Handles all 24 specified type mappings: primitives, boxed types, String, UUID, OffsetDateTime, JsonNode, Object, Optional variants, List/Collection/Set, Map with typed values, arrays, enums (with constant enumeration), records, POJOs, and sealed interfaces (oneOf)
// Example: given a method parameter of type List<String>, produces:
"Map.of(\"type\", \"array\", \"items\", Map.of(\"type\", \"string\"))"

// For a record like `record Person(String name, Optional<String> nick)`, produces:
"Map.of(\"type\", \"object\", \"properties\", Map.of(\"name\", Map.of(\"type\", \"string\"), \"nickname\", Map.of(\"type\", \"string\")), \"required\", List.of(\"name\"))"

SchemaGeneratorTest.java

  • Uses compilation-testing approach: compiles in-memory Java source snippets with javax.tools.JavaCompiler and a custom SchemaCapturingProcessor that exercises SchemaGenerator during annotation processing
  • Covers all minimum required type mappings plus nested types, sealed interfaces, and generated source validity (re-compiles generated expressions to prove syntactic correctness)

Copilot AI added 2 commits June 23, 2026 01:03
Creates SchemaGenerator.java that maps javax.lang.model TypeMirror
instances to JSON Schema source code literals (Map.of(...) expressions).

Implements all 24 type mappings from the specification including:
- Primitives and boxed types (int/Integer, long/Long, etc.)
- String, UUID, OffsetDateTime
- Collections (List<T>, Collection<T>, Set<T>)
- Maps (Map<String, V> with typed values)
- Arrays (String[])
- Enums (with constant enumeration)
- Records and POJOs (with properties/required)
- Optional<T>, OptionalInt, OptionalDouble
- Sealed interfaces (oneOf)
- JsonNode and Object (any)

Also adds SchemaGeneratorTest using compilation-testing approach
with javax.tools.JavaCompiler to exercise the generator at compile time.

Closes #1759
Copilot AI changed the title [WIP] Add schema generation utility for TypeMirror to JSON Schema feat(java): add SchemaGenerator compile-time type-to-JSON-Schema utility Jun 23, 2026
Copilot AI requested a review from edburns June 23, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java] @CopilotTool ergonomics 4.2: Schema generation utility (TypeMirror to JSON Schema)

2 participants