Skip to content

Commit aaab68e

Browse files
MikeEdgarAzquelt
andcommitted
fix: skip class introspection when $ref is derived from annotation
Signed-off-by: Michael Edgar <michael@xlate.io> Co-authored-by: Andrew Rouse <anrouse@uk.ibm.com>
1 parent 084174a commit aaab68e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

core/src/main/java/io/smallrye/openapi/runtime/scanner/OpenApiDataObjectScanner.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212
import java.util.Map;
13-
import java.util.Optional;
1413
import java.util.stream.BaseStream;
1514

1615
import org.eclipse.microprofile.openapi.OASFactory;
@@ -38,7 +37,6 @@
3837
import io.smallrye.openapi.runtime.scanner.dataobject.IgnoreResolver;
3938
import io.smallrye.openapi.runtime.scanner.dataobject.TypeResolver;
4039
import io.smallrye.openapi.runtime.scanner.spi.AnnotationScannerContext;
41-
import io.smallrye.openapi.runtime.util.JandexUtil;
4240
import io.smallrye.openapi.runtime.util.TypeUtil;
4341

4442
/**
@@ -257,19 +255,20 @@ private void depthFirstGraphSearch() {
257255

258256
TypeUtil.mapDeprecated(context, currentClass, currentSchema::getDeprecated, currentSchema::setDeprecated);
259257
currentPathEntry.setSchema(currentSchema);
260-
boolean hasImplementation = Optional.ofNullable(TypeUtil.getSchemaAnnotation(context, currentClass))
261-
.map(JandexUtil::hasImplementation)
262-
.orElse(false);
263258

264-
if (!hasImplementation && !hasNonNullType(currentSchema)) {
259+
if (currentSchema.getRef() != null) {
260+
continue;
261+
}
262+
263+
if (!hasNonNullType(currentSchema)) {
265264
// If not schema has yet been set, consider this an "object"
266265
SchemaSupport.setType(currentSchema, Schema.SchemaType.OBJECT);
267266
} else if (allowRegistration) {
268267
maybeRegisterSchema(currentType, currentSchema, entrySchema);
269268
}
270269

271270
List<Schema.SchemaType> types = currentSchema.getType();
272-
if (!hasImplementation && types != null && types.contains(Schema.SchemaType.OBJECT)) {
271+
if (types != null && types.contains(Schema.SchemaType.OBJECT)) {
273272
// Only 'object' type schemas should have properties of their own
274273
ScannerLogging.logger.gettingFields(currentType, currentClass);
275274

core/src/test/java/io/smallrye/openapi/runtime/scanner/StandaloneSchemaScanTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,19 @@ public final boolean isNull() {
10411041
// ... some other methods ...
10421042
}
10431043

1044+
@Schema(ref = "#/components/schemas/1UseSchemaImplementationImpl")
1045+
class UseSchemaImplementationType2 {
1046+
private String value;
1047+
private final String internalValue = "internalValue";
1048+
private final Boolean composite = true;
1049+
1050+
public final boolean isNull() {
1051+
return value == null;
1052+
}
1053+
// ... some other methods ...
1054+
}
1055+
10441056
assertJsonEquals("components.schemas.implementation-no-introspection.json", UseSchemaImplementationImpl.class,
1045-
UseSchemaImplementationType.class);
1057+
UseSchemaImplementationType.class, UseSchemaImplementationType2.class);
10461058
}
10471059
}

core/src/test/resources/io/smallrye/openapi/runtime/scanner/components.schemas.implementation-no-introspection.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
},
1616
"1UseSchemaImplementationType" : {
1717
"$ref" : "#/components/schemas/1UseSchemaImplementationImpl"
18+
},
19+
"1UseSchemaImplementationType2" : {
20+
"$ref" : "#/components/schemas/1UseSchemaImplementationImpl"
1821
}
1922
}
2023
}

0 commit comments

Comments
 (0)