Package io.jooby.trpc
Class TrpcGenerator
java.lang.Object
io.jooby.trpc.TrpcGenerator
A generator that orchestrates
typescript-generator to produce a tRPC-compatible
TypeScript API definition from compiled Jooby controllers.
This tool bypasses the standard REST scanner of typescript-generator. Instead, it:
- Scans the classpath via the provided ClassLoader for controllers marked with
@Trpc. - Extracts only the input and return types (DTOs) of the matching methods.
- Feeds those data models to the generator to produce clean TypeScript interfaces.
- Uses a fast, recursive type resolver to accurately map Java methods to tRPC
{ input, output }shapes. - Appends a strict
AppRouterdefinition to the generated file.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddController(Class<?> controller) Explicitly adds a controller class to the generation pipeline.voidgenerate()Executes the full TypeScript and tRPC generation pipeline.cz.habarta.typescript.generator.JsonLibrarycz.habarta.typescript.generator.DateMappingcz.habarta.typescript.generator.EnumMappingvoidsetClassLoader(ClassLoader classLoader) voidsetCustomTypeMappings(Map<String, String> customTypeMappings) voidsetCustomTypeNaming(Map<String, String> customTypeNaming) voidsetImportDeclarations(List<String> importDeclarations) voidsetJsonLibrary(cz.habarta.typescript.generator.JsonLibrary jsonLibrary) voidsetMapDate(cz.habarta.typescript.generator.DateMapping mapDate) voidsetMapEnum(cz.habarta.typescript.generator.EnumMapping mapEnum) voidsetOutputDir(Path outputDir) voidsetOutputFile(String outputFile)
-
Constructor Details
-
TrpcGenerator
public TrpcGenerator()
-
-
Method Details
-
generate
Executes the full TypeScript and tRPC generation pipeline.- Throws:
IOException- If an I/O error occurs reading classes or writing the output file.IllegalStateException- IfoutputDiris not configured or if no controllers are found.
-
addController
Explicitly adds a controller class to the generation pipeline. Highly recommended for unit testing to avoid classpath scanning issues.- Parameters:
controller- The controller class to analyze.
-
getClassLoader
- Returns:
- The class loader used to load compiled controllers.
-
setClassLoader
- Parameters:
classLoader- The class loader used to load compiled controllers. Defaults to context class loader.
-
getOutputDir
- Returns:
- The destination directory for the generated TypeScript file.
-
setOutputDir
- Parameters:
outputDir- The destination directory for the generated TypeScript file.
-
getOutputFile
- Returns:
- The name of the generated TypeScript file.
-
setOutputFile
- Parameters:
outputFile- The name of the generated TypeScript file. Defaults totrpc.d.ts.
-
getJsonLibrary
public cz.habarta.typescript.generator.JsonLibrary getJsonLibrary()- Returns:
- The target JSON library for data model generation.
-
setJsonLibrary
public void setJsonLibrary(cz.habarta.typescript.generator.JsonLibrary jsonLibrary) - Parameters:
jsonLibrary- The target JSON library used to parse field annotations. Defaults to Jackson 2.
-
getCustomTypeMappings
- Returns:
- Custom mapping overrides translating Java types to raw TypeScript strings.
-
setCustomTypeMappings
- Parameters:
customTypeMappings- Custom mapping overrides translating Java types to raw TypeScript strings.
-
getCustomTypeNaming
- Returns:
- Custom overrides for generating specific TypeScript interface names.
-
setCustomTypeNaming
- Parameters:
customTypeNaming- Custom overrides for generating specific TypeScript interface names.
-
getImportDeclarations
- Returns:
- Raw import statements appended to the top of the generated file.
-
setImportDeclarations
- Parameters:
importDeclarations- Raw import statements appended to the top of the generated file.
-
getMapDate
public cz.habarta.typescript.generator.DateMapping getMapDate()- Returns:
- The mapping strategy applied to Java date types.
-
setMapDate
public void setMapDate(cz.habarta.typescript.generator.DateMapping mapDate) - Parameters:
mapDate- The mapping strategy applied to Java date types.
-
getMapEnum
public cz.habarta.typescript.generator.EnumMapping getMapEnum()- Returns:
- The mapping strategy applied to Java enum types.
-
setMapEnum
public void setMapEnum(cz.habarta.typescript.generator.EnumMapping mapEnum) - Parameters:
mapEnum- The mapping strategy applied to Java enum types.
-