Skip to content
/ Zyra Public

Zyra is a Java annotation-based code generation tool for producing type-safe TypeScript definitions and Zod schemas from your POJOs.

License

Notifications You must be signed in to change notification settings

Relism/Zyra

Repository files navigation

Zyra Zyra logo

Type-safe TypeScript + Zod schema generation for Java POJOs.

License Java Maven Plugin



🌷 Why Zyra?

  • 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.

Getting Started

1. Annotate your classes

@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;
}

2. Run the Zyra Maven plugin

mvn zyra:zyra-tsgen

3. Enjoy the output

import { Address } from './';

export default interface User {
    username: string;
    age: number;
    active: boolean;
    address: Address;
    roles: string[];
    preferences: { [key: string]: number };
}

🌷 Maven Plugin Configuration for Codegen

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-tsgen

🌷 @Zyra Annotation Options

Your 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.

🌷 Maven Plugin Options

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"

🌷 Supported Features

  • ✅ 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

🌷 Roadmap

  • Zod schema generation toggle via CLI/Maven
  • Pluggable Type Mappers via API

🌷 Contributing

Pull requests, feedback, and issues are welcome! Please fork the repo and open a PR.


🌷 License

Zyra is licensed under the MIT License.

About

Zyra is a Java annotation-based code generation tool for producing type-safe TypeScript definitions and Zod schemas from your POJOs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages