Class SchemaGenerator

java.lang.Object
com.github.copilot.tool.SchemaGenerator

@CopilotExperimental public class SchemaGenerator extends Object
Compile-time utility that maps javax.lang.model types to JSON Schema represented as Java source code literals (Map.of(...) expressions).

This class is invoked by the annotation processor and operates exclusively with the javax.lang.model API. It does NOT use java.lang.reflect.

Since:
1.0.2
  • Constructor Details

    • SchemaGenerator

      public SchemaGenerator()
  • Method Details

    • generateSchemaSource

      public String generateSchemaSource(TypeMirror type, Types typeUtils, Elements elementUtils)
      Given a TypeMirror from the annotation processing environment, returns a String containing Java source code for a Map literal representing the JSON Schema of that type.
      Parameters:
      type - the type to generate schema for
      typeUtils - the Types utility from the processing environment
      elementUtils - the Elements utility from the processing environment
      Returns:
      a Java source code string representing the JSON Schema
    • generateParametersSchemaSource

      public String generateParametersSchemaSource(List<? extends VariableElement> parameters, Types typeUtils, Elements elementUtils)
      Generates the full "parameters" schema source for a method's parameters. Produces a Map.of("type", "object", "properties", Map.of(...), "required", List.of(...)).
      Parameters:
      parameters - the method parameters to generate schema for
      typeUtils - the Types utility from the processing environment
      elementUtils - the Elements utility from the processing environment
      Returns:
      a Java source code string representing the parameters JSON Schema