| title | openapi-generics-platform — Architecture (1.0.0) |
|---|---|
| nav_exclude | true |
- Purpose
- Core Principle
- Problem Statement
- Solution Overview
- Supported Contract Shapes
- Server-Side Architecture
- Client-Side Architecture
- Build-Time Orchestration
- Ownership Model
- Design Decisions
- System Boundaries
- Summary
OpenAPI Generics is a contract-first, generics-aware API platform that ensures:
- A single source of truth for API contracts (Java)
- A deterministic OpenAPI projection (no semantic loss)
- Client generation aligned with the contract (no drift, no duplication)
This document defines the architecture, responsibilities, and boundaries of the platform.
OpenAPI is a projection. The Java contract is the authority.
Implications:
- Contract models are not re-generated on the client
- OpenAPI contains semantic hints, not ownership
- Client generation reconstructs the original contract abstraction
Standard OpenAPI workflows break down with generics:
ServiceResponse<T>loses type semanticsPage<T>becomes flattened or duplicated- Envelope models are re-generated per client
- Contract ownership becomes ambiguous
Result:
- Drift between producer and consumer
- Model duplication
- Loss of abstraction
The platform introduces a two-phase architecture:
- Extracts real response types from runtime
- Interprets generic structures
- Enriches OpenAPI with vendor extensions
- Suppresses infrastructure models from generation
- Reads vendor extensions
- Reconstructs wrapper abstractions
- Reuses external contract models
- Avoids model duplication
The platform intentionally supports a restricted, deterministic set:
ServiceResponse<T>ServiceResponse<Page<T>>
YourEnvelope<T>
Constraints:
- Exactly one generic parameter
- Exactly one direct payload field
- No nested generics (
YourEnvelope<Page<T>>is NOT supported)
Design intent:
Determinism over flexibility
OpenApiPipelineOrchestrator
Pipeline execution:
- Discover response types
- Introspect generic structure
- Generate wrapper semantics
- Mark infrastructure schemas
- Validate contract integrity
ResponseTypeDiscoveryStrategy
- Framework-specific
- Default: Spring MVC (
RequestMappingHandlerMapping) - Produces:
ResolvableType
ResponseTypeIntrospector
Responsibilities:
-
Unwrap async / wrapper types
ResponseEntityCompletionStageFutureDeferredResult
-
Detect contract envelope
-
Extract payload structure
Output:
ResponseTypeDescriptor
ResponseIntrospectionPolicyResolver
Modes:
- Default →
ServiceResponse - External → configured via:
openapi-generics:
envelope:
type: com.example.ApiResponse
Validation rules:
- Must be a concrete class
- Must have exactly one type parameter
- Must expose exactly one payload field
WrapperSchemaProcessor + WrapperSchemaEnricher
Adds semantic extensions:
x-api-wrapperx-api-wrapper-datatypex-data-container(if container)x-data-item
Purpose:
Encode generics semantics into OpenAPI
SchemaGenerationControlMarker
Marks schemas with:
x-ignore-model
Used for:
- Envelope types
- Infrastructure models (
Meta,Sort) - Derived container schemas
Result:
OpenAPI keeps structure, client avoids regeneration
OpenApiContractGuard
Validates:
- Wrapper existence
- Required extensions
- Payload structure
Behavior:
Fail-fast — no silent inconsistencies
GenericAwareJavaCodegen
Extends:
JavaClientCodegen
Responsibilities:
- Filter ignored models
- Inject external imports
- Apply envelope metadata
- Preserve wrapper semantics
Configuration:
openapi-generics.response-contract.CustomerDto=com.example.CustomerDto
Behavior:
- Prevents generation of DTO
- Injects correct import
Configuration:
openapi-generics.envelope=com.example.ApiResponse
Injected into wrapper models:
x-envelope-importx-envelope-type
Purpose:
Ensure generated clients use correct envelope type
- Patches upstream
model.mustache - Injects wrapper-aware template (
api_wrapper.mustache) - Verifies patch integrity at build-time
Guarantee:
Deterministic generation — upstream changes cannot silently break behavior
openapi-generics-java-codegen-parent
Pipeline:
- Extract upstream templates
- Extract custom templates
- Patch model template
- Validate patch
- Overlay templates
- Run generator
- Register generated sources
Control:
openapi.generics.skip=true
- Owns contract
- Defines response shapes
- Reconstructs contract
- Owns adapter usage
- Defines transformation rules
- Enforces determinism
Trade-off:
- (+) Deterministic
- (+) Predictable codegen
- (-) Limited flexibility
Trade-off:
- (+) No OpenAPI spec violation
- (+) Full semantic control
- (-) Requires custom generator
Trade-off:
- (+) Early detection
- (+) No silent corruption
- (-) Strict adoption curve
The platform does NOT:
- Define business logic
- Enforce API design patterns
- Handle runtime behavior
It ONLY:
Preserves contract semantics across server → OpenAPI → client
OpenAPI Generics provides:
- Contract-first architecture
- Deterministic OpenAPI projection
- Generics-aware client generation
- External contract reuse
Key outcome:
No drift. No duplication. No semantic loss.