Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use SchemaType.ARRAY instead of "ARRAY" for native support #30940

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class StandardMethodImplementor implements MethodImplementor {
private static final String OPENAPI_RESPONSE_ANNOTATION = OPENAPI_PACKAGE + ".responses.APIResponse";
private static final String OPENAPI_CONTENT_ANNOTATION = OPENAPI_PACKAGE + ".media.Content";
private static final String OPENAPI_SCHEMA_ANNOTATION = OPENAPI_PACKAGE + ".media.Schema";
private static final String SCHEMA_TYPE_CLASS_NAME = "org.eclipse.microprofile.openapi.annotations.enums.SchemaType";
private static final String SCHEMA_TYPE_ARRAY = "ARRAY";
private static final String ROLES_ALLOWED_ANNOTATION = "jakarta.annotation.security.RolesAllowed";
private static final Logger LOGGER = Logger.getLogger(StandardMethodImplementor.class);
Expand Down Expand Up @@ -197,7 +198,7 @@ protected void addOpenApiResponseAnnotation(AnnotatedElement element, Response.S
.add("implementation", clazz);

if (isList) {
schemaAnnotation.add("type", SCHEMA_TYPE_ARRAY);
schemaAnnotation.add("type", schemaTypeArray());
}

element.addAnnotation(OPENAPI_RESPONSE_ANNOTATION)
Expand Down Expand Up @@ -235,6 +236,11 @@ protected boolean isNotReactivePanache() {
return !capabilities.isPresent(Capability.HIBERNATE_REACTIVE);
}

private static Enum schemaTypeArray() {
Class<?> schemaTypeClass = toClass(SCHEMA_TYPE_CLASS_NAME);
return Enum.valueOf((Class<Enum>) schemaTypeClass, SCHEMA_TYPE_ARRAY);
Comment on lines +240 to +241
Copy link
Contributor

Choose a reason for hiding this comment

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

This can probably be made a constant, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class is optional (it's only available when the quarkus-smallrye-openapi extension is used).
We're only resolving the class when this capability is enabled:

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, no problem

}

private static Class<?> toClass(String className) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
Expand Down