Skip to content

fix: check for type specified on referenced class - #2694

Merged
MikeEdgar merged 2 commits into
smallrye:mainfrom
MikeEdgar:issue-2688
Oct 12, 2026
Merged

MikeEdgar merged 2 commits into
smallrye:mainfrom
MikeEdgar:issue-2688

Conversation

@MikeEdgar

@MikeEdgar MikeEdgar commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #2688

@MikeEdgar MikeEdgar added this to the 4.4.0 milestone Oct 2, 2026

@phillip-kruger phillip-kruger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The fix addresses the root cause: a @Schema on the field without type caused readSchemaAnnotatedField to apply the default type: object next to the $ref. I built the branch and ran the core tests (410 run, 0 failures). I also checked the issue's example in both scan orders (Zeta, Beta, Alpha and Alpha, Beta, Zeta). Both give zeta: {$ref, description} now, where main emitted type: object in both. Zeta[], @Schema(description) Zeta[] and @Schema(description) List<Zeta> produce the same output as before.

A few minor suggestions, none blocking:

  1. Use the Annotations abstraction. The new lookup in TypeUtil.isTypeOverridden calls clazz.declaredAnnotation(SchemaConstant.DOTNAME_SCHEMA) directly. The rest of TypeUtil goes through context.annotations().getAnnotation(...) / getAnnotationValue(...) (e.g. getSchemaAnnotation, isIncludedAllOf). Using that here would keep it consistent and could reduce the block to a single getAnnotationValue(clazz, DOTNAME_SCHEMA, PROP_TYPE) call, assuming the enum conversion works there.

  2. Array types also hit the class lookup. AugmentedIndexView.getClass(Type) goes through TypeUtil.getName, which unwraps array types to the element type. For a Zeta[] field, the lookup finds Zeta's @Schema(type = STRING), so isTypeOverridden now returns true (STRING vs. the array format). The generated output is still correct because array typing is applied elsewhere, but that seems accidental. Maybe limit the lookup to CLASS/PARAMETERIZED_TYPE kinds?

  3. Comment on the typeList == null || change. If I read it right, this is needed because the type schema no longer gets a default type when the class declares one, and without the change such fields would fall through to checkRegistration. A short comment would help the next reader.

  4. Javadoc wording. "If the classType does not itself define a type" reads as if it should say that the schemaAnnotation doesn't define one, with the class being the fallback.

  5. Test both scan orders. The issue is about ordering, so asserting the reversed order against the same expected JSON would be cheap:

    assertJsonEquals("components.schemas.type-retained-from-class-annotation.json", Alpha.class, Beta.class, Zeta.class);
  6. Parameters. AbstractParameterProcessor also calls isTypeOverridden, so something like @QueryParam("z") @Schema(description = "...") Zeta z will no longer get the default type: object. That's probably the desired outcome, but I didn't manage to verify the resulting parameter schema, so a test there may be worthwhile.

Also, for the release notes: the "expected" output in #2688 (type: string alongside $ref) is no longer produced either. Fields now get only the $ref plus their own attributes, which I think is better, but it will show up in users' spec diffs.

phillip-kruger
phillip-kruger previously approved these changes Oct 6, 2026
Signed-off-by: Michael Edgar <michael@xlate.io>
Signed-off-by: Michael Edgar <michael@xlate.io>
@MikeEdgar

Copy link
Copy Markdown
Member Author
  • ✔️ Use the Annotations abstraction
  • ✔️ limit the lookup to CLASS/PARAMETERIZED_TYPE kinds
  • ✔️ Comment on the typeList == null || change
  • ✔️ Javadoc wording.
  • ⚠️ skipped for now - Test both scan orders.
  • ⚠️ skipped for now - Parameters

@sonarqubecloud

Copy link
Copy Markdown

@MikeEdgar
MikeEdgar merged commit 3db341d into smallrye:main Oct 12, 2026
20 checks passed
@MikeEdgar
MikeEdgar deleted the issue-2688 branch October 12, 2026 11:51
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.

Order of class scanning causes incorrect type for value class fields

3 participants