Repository navigation
fix: check for type specified on referenced class - #2694
Conversation
phillip-kruger
left a comment
There was a problem hiding this comment.
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:
-
Use the
Annotationsabstraction. The new lookup inTypeUtil.isTypeOverriddencallsclazz.declaredAnnotation(SchemaConstant.DOTNAME_SCHEMA)directly. The rest ofTypeUtilgoes throughcontext.annotations().getAnnotation(...)/getAnnotationValue(...)(e.g.getSchemaAnnotation,isIncludedAllOf). Using that here would keep it consistent and could reduce the block to a singlegetAnnotationValue(clazz, DOTNAME_SCHEMA, PROP_TYPE)call, assuming the enum conversion works there. -
Array types also hit the class lookup.
AugmentedIndexView.getClass(Type)goes throughTypeUtil.getName, which unwraps array types to the element type. For aZeta[]field, the lookup findsZeta's@Schema(type = STRING), soisTypeOverriddennow returnstrue(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 toCLASS/PARAMETERIZED_TYPEkinds? -
Comment on the
typeList == null ||change. If I read it right, this is needed because the type schema no longer gets a defaulttypewhen the class declares one, and without the change such fields would fall through tocheckRegistration. A short comment would help the next reader. -
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. -
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);
-
Parameters.
AbstractParameterProcessoralso callsisTypeOverridden, so something like@QueryParam("z") @Schema(description = "...") Zeta zwill no longer get the defaulttype: 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.
Signed-off-by: Michael Edgar <michael@xlate.io>
Signed-off-by: Michael Edgar <michael@xlate.io>
|
|



Fixes #2688