Complete documentation for Apicurio Codegen, including configuration options, templates, and customization.
<plugin>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-codegen-maven-plugin</artifactId>
<version>${apicurio-codegen.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<spec>${project.basedir}/src/main/resources/openapi.yaml</spec>
<output>${project.build.directory}/generated-sources/apicurio</output>
<template>jax-rs</template>
</configuration>
</execution>
</executions>
</plugin>
| Parameter | Description | Default |
|---|---|---|
spec |
Path to the OpenAPI specification file | Required |
output |
Output directory for generated code | ${project.build.directory}/generated-sources/apicurio |
template |
Code generation template to use | jax-rs |
packageName |
Java package for generated classes | Derived from spec |
includePatterns |
Comma-separated list of paths to include | All paths |
excludePatterns |
Comma-separated list of paths to exclude | None |
Apicurio Codegen produces the following types of artifacts:
When used in a Quarkus application:
Apicurio Codegen supports OpenAPI specification extensions to customize generated code.
x-codegen ExtensionThe x-codegen extension can be defined at the root level of the OpenAPI document:
x-codegen:
bean-annotations:
- "@lombok.ToString"
- annotation: "@lombok.EqualsAndHashCode"
excludeEnums: true
contextRoot: "/api/v1"
suppress-date-time-formatting: false
Add custom annotations to generated bean classes:
x-codegen:
bean-annotations:
- "@lombok.Data"
- "@lombok.Builder"
Set a base path for all JAX-RS resources:
x-codegen:
contextRoot: "/api/v1"
This generates:
@Path("/api/v1/users")
public class UserResource {
// ...
}
Control how date-time properties are formatted:
x-codegen:
suppress-date-time-formatting: true
By default, Apicurio Codegen adds @JsonFormat annotations to date-time fields. Set this to true to suppress that behavior.
You can create custom templates for code generation. See the template development guide for details.
Implement custom logic during code generation using hooks:
public class MyCodegenHook implements CodegenHook {
@Override
public void beforeGeneration(OpenAPI spec) {
// Custom logic before generation
}
@Override
public void afterGeneration(List<GeneratedFile> files) {
// Custom logic after generation
}
}
Integrate Apicurio Codegen in your CI/CD pipeline by running the Maven plugin during your build:
# GitHub Actions example
- name: Build with Maven
run: mvn clean compile
The Maven plugin will automatically run during the build process and generate code as configured in your pom.xml.
Issue: Generated code doesn’t compile
Solution: Ensure your OpenAPI spec is valid and includes all required schema definitions.
Issue: Custom annotations not appearing in generated code
Solution: Verify the x-codegen.bean-annotations extension is at the root level of your OpenAPI document.
Issue: Maven plugin not generating code
Solution: Check that the generate goal is bound to a lifecycle phase (default is generate-sources).