Skip to content

[java][microprofile] Support useOneOfInterfaces with JSON-B serialization (stacked on #24190)#24197

Draft
Ignacio-Vidal wants to merge 2 commits into
OpenAPITools:masterfrom
Ignacio-Vidal:mp-client-oneof-interface-jsonb
Draft

[java][microprofile] Support useOneOfInterfaces with JSON-B serialization (stacked on #24190)#24197
Ignacio-Vidal wants to merge 2 commits into
OpenAPITools:masterfrom
Ignacio-Vidal:mp-client-oneof-interface-jsonb

Conversation

@Ignacio-Vidal

@Ignacio-Vidal Ignacio-Vidal commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Stacked on #24190

This PR is stacked on top of #24190 ([java][microprofile] Support useOneOfInterfaces). It adds JSON-B coverage for the same feature. Review/merge #24190 first — until it merges, this PR's diff transiently includes that commit.

What & why

#24190 renders a oneOf schema as an interface in the microprofile library and its committed sample uses serializationLibrary=jackson. The microprofile library also supports JSON-B, and the shared typeInfoAnnotation.mustache already has a jsonbPolymorphism branch that emits @JsonbTypeInfo / @JsonbSubtype. That path is enabled for serializationLibrary=jsonb + microprofileRestClientVersion=3.0 (JavaClientCodegen sets jsonbPolymorphism).

So useOneOfInterfaces + JSON-B already works — this PR locks it in with a sample and a test. No generator source change is required.

Generated interface under JSON-B (from the committed sample):

@JsonbTypeInfo(key = "petType", value = {
  @JsonbSubtype(alias = "CAT", type = CatRequest.class),
  @JsonbSubtype(alias = "DOG", type = DogRequest.class),
})
public interface PetRequest {
    public PetType getPetType();
}

No Jackson annotations are emitted; children implements PetRequest.

Changes

  • Test JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb — asserts the interface emits @JsonbTypeInfo(key = "petType") + the CAT/DOG @JsonbSubtype mappings, emits no @JsonTypeInfo/@JsonSubTypes, and that children implement the interface.
  • Sample bin/configs/java-microprofile-oneof-interface-jsonb.yamlsamples/client/petstore/java/microprofile-oneof-interface-jsonb (JSON-B, restClientVersion 3.0). Reuses the same oneof_interface_petstore.yaml fixture as the jackson sample.
  • CI — registered the sample in samples-java-client-jdk11.yaml so it is compiled on every run (the jackson sample from [java][microprofile] Extend support for useOneOfInterfaces to the microprofile library when Jackson serialisation is enabled #24190 is not currently in a matrix; this one is).

Verification

  • JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb passes.
  • The generated sample compiles under the sample's java.version=11 target (@Jsonb* annotations resolve against jakarta.json.bind-api 3.0.0).

Scope / caveat

The jsonbPolymorphism flag is set only for microprofileRestClientVersion=3.0. For older rest-client versions (1.4.1/2.0), a JSON-B oneOf interface is still emitted but without discriminator annotations — that pre-existing gate is unchanged and out of scope here.


Summary by cubic

Adds JSON-B support and test coverage for useOneOfInterfaces in the Java MicroProfile client. When serializationLibrary=jsonb and microprofileRestClientVersion=3.0, the generated oneOf interface uses JSON-B polymorphism, with a new sample compiled in CI.

  • New Features
    • Generates the oneOf interface with @JsonbTypeInfo(key="petType") and @JsonbSubtype mappings; no Jackson annotations; children implement the interface (tested by oneOfInterfaceMicroprofileJsonb).
    • Adds bin/configs/java-microprofile-oneof-interface-jsonb.yaml and the samples/client/petstore/java/microprofile-oneof-interface-jsonb project; registered in .github/workflows/samples-java-client-jdk11.yaml.
    • Applies to MicroProfile Rest Client 3.0 only; older versions still generate the interface without JSON-B polymorphism.

Written for commit 48343d5. Summary will update on new commits.

Review in cubic

Route oneOf schemas to the shared oneof_interface template in the microprofile
library's model.mustache, so useOneOfInterfaces=true renders a oneOf schema as a
Java interface implemented by its subtypes, instead of an unrelated pojo.

The microprofile library ships its own model.mustache (it overrides the base to
support JSON-B and the jakarta/javax package split), which did not carry the
oneOf-interface routing the base template has. Adding the routing lets the
existing global oneof_interface template render the interface; children already
implement it via x-implements. Scoped to serializationLibrary=jackson (the
interface polymorphism annotations are Jackson-based).

Adds a self-consistent oneof_interface_petstore.yaml fixture, a
JavaClientCodegenTest case, and a microprofile-oneof-interface sample.
…tion

Add JSON-B coverage for the useOneOfInterfaces feature in the microprofile
library. With serializationLibrary=jsonb and microprofileRestClientVersion=3.0,
the generated oneOf interface carries JSON-B polymorphism (@JsonbTypeInfo /
@JsonbSubtype) instead of the Jackson annotations, driven by the existing
jsonbPolymorphism path in typeInfoAnnotation.mustache. No generator source
change is required - this locks the behaviour in with a sample and a test.

- new JavaClientCodegenTest#oneOfInterfaceMicroprofileJsonb asserting the
  interface emits @JsonbTypeInfo(key="petType") + @JsonbSubtype CAT/DOG and no
  Jackson annotations, and that children implement the interface.
- new bin/configs/java-microprofile-oneof-interface-jsonb.yaml + generated
  microprofile-oneof-interface-jsonb sample (JSON-B, restClientVersion 3.0).
- register the sample in the samples-java-client-jdk11 workflow so CI compiles it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant