Contract-aware Java generator extension for OpenAPI Generics.
openapi-generics-java-codegen provides the custom OpenAPI Generator implementation used by OpenAPI Generics.
It registers the generator named:
java-generics-contract
This module is build-time only. In normal usage, consumers do not depend on it directly. It is wired through:
openapi-generics-java-codegen-parent
Its responsibility is:
OpenAPI metadata → contract-aligned Java client types
- What It Does
- Generation Pipeline
- Wrapper Reconstruction
- BYOE
- BYOC
- Wrapper Metadata
- Container Metadata
- Model Filtering
- Out of Scope
- Mental Model
This module extends OpenAPI Generator’s Java client generation with OpenAPI Generics semantics.
It:
- detects wrapper schemas marked with
x-api-wrapper - derives envelope metadata from OpenAPI wrapper metadata
- reconstructs generic container payloads from OpenAPI metadata
- imports container Java types through
x-data-container-type - reuses externally owned DTOs through BYOC mappings
- filters infrastructure schemas marked with
x-ignore-model - generates thin contract-aligned wrapper classes
It consumes metadata already present in the OpenAPI document.
It does not discover server-side Java contracts or create OpenAPI schemas.
OpenAPI Models
↓
Ignored / External Model Resolution
↓
Wrapper Metadata Resolution
↓
Container Metadata Consumption
↓
External Import Resolution
↓
Wrapper Reconstruction
↓
Generated Java Client
The generator operates entirely on OpenAPI metadata and reconstructs Java types that preserve the original generic contract shape.
OpenAPI wrapper schemas are reconstructed as thin Java subclasses.
Simple wrapper:
public class ServiceResponseCustomerDto
extends ServiceResponse<CustomerDto> {
}Built-in container wrapper:
public class ServiceResponsePageCustomerDto
extends ServiceResponse<Page<CustomerDto>> {
}BYOE wrapper:
public class ApiResponseListCustomerDto
extends ApiResponse<List<CustomerDto>> {
}Application-defined container wrapper:
public class ApiResponsePagingCustomerDto
extends ApiResponse<Paging<CustomerDto>> {
}The wrapper superclass is derived directly from the x-api-wrapper-type vendor extension.
Generated wrappers intentionally contain no behavior. Their role is to bind generic parameters to contract-owned envelope and container types.
Bring Your Own Envelope (BYOE) is configured only on the producer side.
During OpenAPI projection the producer publishes the resolved Java envelope identity as metadata:
x-api-wrapper-type: io.example.contract.ApiResponseThe generator derives the wrapper superclass directly from this metadata.
Default envelope:
ServiceResponse<T>Configured envelope example:
ApiResponse<T>No client-side envelope configuration is required.
The envelope type simply needs to be available on the generated client's compile classpath.
BYOC maps OpenAPI model names to externally owned Java types.
<additionalProperty>
openapi-generics.response-contract.CustomerDto=io.example.contract.CustomerDto
</additionalProperty>Effect:
- the mapped model is not generated
- wrapper classes import the external type
- generated clients reuse the contract-owned DTO
This keeps DTO ownership outside generated code.
Wrapper reconstruction is driven by canonical OpenAPI vendor extensions.
Example:
x-api-wrapper: true
x-api-wrapper-type: io.example.contract.ApiResponse
x-api-wrapper-datatype: PagingCustomerDtoThe generator uses:
x-api-wrapperto identify projected wrapper schemasx-api-wrapper-typeas the fully qualified Java wrapper typex-api-wrapper-datatypeas the resolved generic payload type published by the producer
The OpenAPI document is the single source of truth for wrapper identity.
Container reconstruction is driven by OpenAPI vendor extensions.
Built-in container example:
x-api-wrapper: true
x-api-wrapper-type: io.github.blueprintplatform.openapi.generics.contract.envelope.ServiceResponse
x-api-wrapper-datatype: PageCustomerDto
x-data-container: Page
x-data-container-type: io.github.blueprintplatform.openapi.generics.contract.paging.Page
x-data-item: CustomerDtoApplication-defined container example:
x-api-wrapper: true
x-api-wrapper-type: io.example.contract.ApiResponse
x-api-wrapper-datatype: PagingCustomerDto
x-data-container: Paging
x-data-container-type: io.example.contract.Paging
x-data-item: CustomerDtoThe generator uses:
x-data-containeras the generic container name used in the generated wrapperx-data-container-typeas the fully qualified Java importx-data-itemas the generic item type
This allows built-in and application-defined generic containers to be reconstructed through the same template path.
Some schemas exist only as OpenAPI projection artifacts.
They must not become generated DTOs.
The generator filters models marked with:
x-ignore-model: trueIt also filters models registered through BYOC.
Ignored model imports are removed from generated wrapper models so wrappers do not reference non-generated classes.
This module does not:
- run Springdoc
- inspect controller return types
- create OpenAPI schemas
- orchestrate Maven plugin phases
- patch upstream templates
- own runtime application behavior
Those responsibilities belong to the server starter or the codegen parent.
OpenAPI + Vendor Extensions
↓
Contract-Aware Java Generation
↓
Thin Wrapper Types
This module does not generate additional business models.
It generates only the minimum Java wrapper types required to preserve the original generic contract defined by the OpenAPI document.