Type-safe TypeScript + Zod schema generation for Java POJOs.
- Eliminate duplicate model definitions between backend and frontend
- Type-safe and consistent across the stack
- Zod validation schemas generated alongside TypeScript types
- Works with any framework: Spring, Micronaut, Quarkus, etc.
@Zyra(
export = Zyra.Export.DEFAULT,
style = Zyra.DefinitionStyle.INTERFACE
)
public class User {
private String username;
private int age;
private boolean active;
private Address address;
private List<String> roles;
private Map<String, Integer> preferences;
}mvn zyra:zyra-tsgenimport { Address } from './';
export default interface User {
username: string;
age: number;
active: boolean;
address: Address;
roles: string[];
preferences: { [key: string]: number };
}Add this to your pom.xml:
<plugin>
<groupId>dev.relism</groupId>
<artifactId>zyra-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>zyra-tsgen</goal>
</goals>
</execution>
</executions>
</plugin>Run it with:
mvn zyra:zyra-tsgenYour annotated classes can be configured with the @Zyra annotation, allowing you to have granulated control over the generated TypeScript.
| Option | Type | Description |
|---|---|---|
export |
enum | DEFAULT, NAMED, or NONE. Determines how the TypeScript is exported. |
style |
enum | INTERFACE or TYPE. Controls whether it generates an interface or alias. |
indentSpaces |
int | Number of spaces to use for indentation. Default is 2. |
name |
String | Overrides the default output name (e.g., UserDto.ts instead of User.ts). |
virtualFields |
ZyraVirtualField[] | Adds additional TypeScript-only fields that don’t exist in the original POJO. |
TThese options can be passed via -D Maven CLI parameters:
| Parameter | Default | Description |
|---|---|---|
zyra.outputDir |
${project.build.directory}/zyra/tsout |
Where the .ts files will be written |
zyra.singleFileOutput |
false |
If true, generates a single aggregated file |
zyra.fileHeader |
null |
Adds a header comment to all generated files |
project.build.outputDirectory |
${project.build.outputDirectory} |
Directory where compiled .class files are located |
Example :
mvn zyra:zyra-tsgen \
-Dzyra.outputDir=src/generated/types \
-Dzyra.singleFileOutput=true \
-Dzyra.fileHeader="// Auto-generated by Zyra — do not edit"- ✅ Java → TypeScript interface/type generation
- ✅ Full generic support (
List<T>,Map<K, V>,Optional<T>, nested structures) - ✅ Zod schema support with decorators like
@ZodString,@ZodNumber - ✅ Recursive import handling
- ✅ Custom output directory, style, and naming
- Zod schema generation toggle via CLI/Maven
- Pluggable Type Mappers via API
Pull requests, feedback, and issues are welcome! Please fork the repo and open a PR.
Zyra is licensed under the MIT License.
