Quarkus - OpenAPI Generator - Server - Apicurio
Quarkus' extension for generation of server Stubs based on OpenAPI specification files.
This server extension has support for two code generation tools:
|
This extension is for REST code generation for server side only. |
Want to contribute? Great! We try to make it easy, and all contributions, even the smaller ones, are more than welcome. This includes bug reports, fixes, documentation, examples… But first, read this page.
Apicurio vs OpenAPITools
The following table compares the Apicurio and OpenAPITools code generators.
| Aspect | Apicurio Code Generator | OpenAPITools Code Generator |
|---|---|---|
How it is selected |
Explicit via |
Explicit via |
Customization mechanism |
OpenAPI specification extensions ( |
Configuration properties |
Customization location |
OpenAPI document (root, paths, schemas, properties) |
Not supported |
Fine-grained control per operation |
Yes ( |
Yes ( |
Fine-grained control per schema |
Yes ( |
Not supported |
Add annotations to generated beans |
Yes ( |
Yes ( |
Add annotations to method parameters |
Yes ( |
Not supported |
Async / reactive support |
Per operation via |
Global via |
Custom return types |
Yes ( |
|
Context root configuration |
Via OpenAPI ( |
Not supported |
Date/time formatting control |
Yes ( |
Not supported |
Inline schemas instead of generating classes |
Yes ( |
Not supported |
Override generated Java type |
Yes ( |
Not supported |
Extend a base class |
Yes ( |
Not supported |
Package customization |
Per schema via |
Globally via |
OpenAPI spec location |
|
|
Supported OpenAPI formats |
JSON, YAML, YML |
JSON, YAML, YML |
Generated sources location |
|
|
Customization philosophy |
Spec-driven, fine-grained, declarative |
Property-driven, coarse-grained |
Extension maturity |
Preview |
Experimental / early development |
Both generators support multi-file OpenAPI documents with relative $ref entries. Keep the referenced files under the same input base directory as the entry spec so they can be resolved during generation.
You can also generate multiple server stubs in a single project by configuring one block per spec under quarkus.openapi.generator.server.spec.<id>.*. The <id> can either be the sanitized relative file name, such as petstore_openapi_json, or an alias when you also set quarkus.openapi.generator.server.spec.<id>.spec=<file>.
|
When using per-spec configuration ( |
Using Client and Server Generators Together
When using both the Client and Server generators in the same project, note that they have different default input directories:
| Generator | Default Input Directory |
|-----------|-------------------------|
| Client | src/main/openapi |
| Server | src/main/resources/openapi |
This means if you place your OpenAPI spec in src/main/openapi, the client generator will find it automatically, but the server generator will not.
Option 1: Configure Server Generator to Use Client’s Directory
Add to src/main/resources/application.properties:
quarkus.openapi.generator.server.input-base-dir=src/main/openapi
quarkus.openapi.generator.server.use=apicurio
# or openapitools
quarkus.openapi.generator.server.spec=your-spec.yaml
Option 2: Use Separate Directories
Keep specs in their default locations:
- Client specs: src/main/openapi/
- Server specs: src/main/resources/openapi/
Option 3: Explicit Spec Configuration (Recommended)
For full control, explicitly configure both generators:
# Client generator (uses src/main/openapi by default)
quarkus.openapi-generator.codegen.spec.your-spec_yaml.base-package=org.acme.client
# Server generator (explicit config)
quarkus.openapi.generator.server.use=apicurio
quarkus.openapi.generator.server.spec=your-spec.yaml
quarkus.openapi.generator.server.input-base-dir=src/main/openapi
quarkus.openapi.generator.server.base-package=org.acme.server
Important Notes
-
The
quarkus.openapi.generator.server.useproperty is required for server generation (values:apicuriooropenapitools) -
Without explicit server config, running
mvn quarkus:generate-codemay only generate client code with a warning -
Run
mvn compileormvn quarkus:generate-codeafter configuring to generate both client and server code
Multiple Files Support
Both Apicurio and OpenAPITools generators support multiple OpenAPI files in the input directory:
-
Multi-file specs: An entry spec can use relative
$refto reference other YAML/JSON files in the same input directory -
Auto-discovery: All
.json,.yaml,.ymlfiles ininput-base-dirare automatically discovered and generated with defaults (base-package=org.acme,use-builders=true) -
Filtering: Use
quarkus.openapi.generator.server.includeandquarkus.openapi.generator.server.excludeto control which files are processed -
Per-spec config: Use
quarkus.openapi.generator.server.spec.<id>.*to customize each spec individually (the<id>is the sanitized relative file name, e.g.,petstore_openapi_json)
|
To exclude shared reference files (like |
Configuration Properties
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
|---|---|---|
This property is deprecated: Use The OpenAPI specification filename. Environment variable: |
string |
|
This property is deprecated: Use The input base dir where the OpenAPI specification is. Environment variable: |
string |
|
This property is deprecated: Use Whether it must generate with reactive code. Environment variable: |
boolean |
|
This property is deprecated: Whether it must generate builders for properties. Environment variable: |
boolean |
|
This property is deprecated: Use The base package to be used to generated sources. Environment variable: |
string |
|
This property is deprecated: Use Whether it must generate resources and beans using bean validation (JSR-303). Environment variable: |
boolean |
|
The generator to be used for generating the server code. Possible values are: By default, is Environment variable: |
string |
|
The OpenAPI specification filename. Environment variable: |
string |
|
The input base dir where the OpenAPI specification is. Environment variable: |
string |
|
Whether it must generate with reactive code. Environment variable: |
boolean |
|
Whether it must generate builders for properties. Environment variable: |
boolean |
|
The base package to be used to generated sources. Environment variable: |
string |
|
Whether it must generate resources and beans using bean validation (JSR-303). Environment variable: |
boolean |
|
Whether the generated server methods should use Environment variable: |
boolean |
|
Whether to skip generation when the persisted fingerprint of the OpenAPI specification and relevant generation configuration matches the previous run. Environment variable: |
boolean |
|
List of OpenAPI file names to include for code generation. When set, only the listed files are processed by the auto-discovery mechanism. Environment variable: |
list of string |
|
List of OpenAPI file names to exclude from code generation. When set, the listed files are skipped by the auto-discovery mechanism. This is useful for excluding shared reference files (e.g., Environment variable: |
list of string |
|
The name of the method parameter that should be used to return the response from the operation. Environment variable: |
string |
required |