[Java][JAX-RS] Support abstract models and sealed discriminator hierarchies

DE
1d ago
+1765-15

Summary

This PR adds support for abstract models and Java sealed discriminator hierarchies to the Java JAX-RS Spec server generator.

Changes

  • Add the x-abstract vendor extension for explicitly declaring abstract models.
  • Support Java 21 sealed model hierarchies with discriminator-based inheritance.
  • Improve Jackson @JsonTypeName handling for inherited discriminator mappings.
  • Add generator tests and OpenAPI specifications covering abstract and sealed model hierarchies.
  • Add a generated JAX-RS Spec sample demonstrating the new functionality.
  • Update generator documentation.

Validation

  • ./mvnw clean package — BUILD SUCCESS (all 8 modules; Maven Central used via a separate settings file).
  • Full core library test suite — 5,791 tests, 0 failures, 0 errors, 18 skipped.
  • Targeted JAX-RS Spec tests — 215 tests passed.
  • ./bin/generate-samples.sh bin/configs/jaxrs-spec-sealed.yaml — successful, no generated changes.
  • ./bin/utils/export_docs_generators.sh — completed, no generated changes.

PR checklist

  • Read the contribution guidelines.
  • Run Maven build and tests.
  • Regenerate the relevant JAX-RS Spec sample.
  • Export generator documentation.
  • Commit all changes.

Follow-up

JSON-B discriminator deserialization support is implemented separately and will be submitted as a follow-up PR.


Summary by cubic

Adds the x-abstract vendor extension and sealed discriminator hierarchy support to the jaxrs-spec generator. Models marked x-abstract are generated as abstract classes with protected constructors and without builders or JSON creators, and they can be combined with useSealed to produce sealed hierarchies with final leaves.

Details

  • Explicit discriminator mappings to an abstract model fail generation; implicit ones are replaced by mappings to its concrete subclasses.
  • With useSealed, an abstract model needs a generated subclass, otherwise generation fails.
  • For allOf grandchildren, @JsonTypeName is now resolved from the nearest ancestor discriminator that maps the model.
  • x-abstract is supported by jaxrs-spec only; jaxrs-cxf-cdi ignores it because it uses its own templates.
  • JSON-B discriminator deserialization is not included in this PR.