Skip to content

Commit

Permalink
Only make json the default for POJO
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Sep 28, 2023
1 parent 0cae54a commit c5b1c2a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.Set;

import org.eclipse.microprofile.openapi.models.Extensible;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;

import io.smallrye.openapi.api.OpenApiConfig;
import io.smallrye.openapi.api.constants.OpenApiConstants;
Expand Down Expand Up @@ -99,4 +102,20 @@ private static boolean profileIncluded(OpenApiConfig config, Set<String> profile

return config.getScanProfiles().stream().anyMatch(profiles::contains);
}

protected String[] getDefaultConsumes(AnnotationScannerContext context, MethodInfo methodInfo) {
if (methodInfo.returnType().kind().equals(Type.Kind.PRIMITIVE)
|| methodInfo.returnType().name().equals(DotName.createSimple(String.class))) {
return OpenApiConstants.DEFAULT_MEDIA_TYPES.get();
}
return context.getConfig().getDefaultConsumes().orElseGet(OpenApiConstants.DEFAULT_MEDIA_TYPES);
}

protected String[] getDefaultProduces(AnnotationScannerContext context, MethodInfo methodInfo) {
if (methodInfo.returnType().kind().equals(Type.Kind.PRIMITIVE)
|| methodInfo.returnType().name().equals(DotName.createSimple(String.class))) {
return OpenApiConstants.DEFAULT_MEDIA_TYPES.get();
}
return context.getConfig().getDefaultProduces().orElseGet(OpenApiConstants.DEFAULT_MEDIA_TYPES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,10 @@ private void processResourceMethod(final AnnotationScannerContext context,
JaxRsLogging.log.processingMethod(method.toString());

// Figure out the current @Produces and @Consumes (if any)
String[] defaultConsumes = context.getConfig().getDefaultConsumes().orElseGet(OpenApiConstants.DEFAULT_MEDIA_TYPES);
String[] defaultConsumes = getDefaultConsumes(context, method);
context.setCurrentConsumes(getMediaTypes(context, method, JaxRsConstants.CONSUMES, defaultConsumes));

String[] defaultProduces = context.getConfig().getDefaultProduces().orElseGet(OpenApiConstants.DEFAULT_MEDIA_TYPES);
String[] defaultProduces = getDefaultProduces(context, method);
context.setCurrentProduces(getMediaTypes(context, method, JaxRsConstants.PRODUCES, defaultProduces));

// Process any @Operation annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ private void processControllerMethod(final AnnotationScannerContext context,
SpringLogging.log.processingMethod(method.toString());

// Figure out the current @Produces and @Consumes (if any)
context.setCurrentConsumes(getMediaTypes(method, SpringConstants.MAPPING_CONSUMES,
context.getConfig().getDefaultConsumes().orElse(OpenApiConstants.DEFAULT_MEDIA_TYPES.get())).orElse(null));
String[] defaultConsumes = getDefaultConsumes(context, method);
context.setCurrentConsumes(getMediaTypes(method, SpringConstants.MAPPING_CONSUMES, defaultConsumes).orElse(null));

context.setCurrentProduces(getMediaTypes(method, SpringConstants.MAPPING_PRODUCES,
context.getConfig().getDefaultProduces().orElse(OpenApiConstants.DEFAULT_MEDIA_TYPES.get())).orElse(null));
String[] defaultProduces = getDefaultProduces(context, method);
context.setCurrentProduces(getMediaTypes(method, SpringConstants.MAPPING_PRODUCES, defaultProduces).orElse(null));

// Process any @Operation annotation
Optional<Operation> maybeOperation = processOperation(context, resourceClass, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ private void processRouteMethod(final AnnotationScannerContext context,
VertxLogging.log.processingMethod(method.toString());

// Figure out the current @Produces and @Consumes (if any)
String[] defaultConsumes = getDefaultConsumes(context, method);
context.setCurrentConsumes(getMediaTypes(method, VertxConstants.ROUTE_CONSUMES,
context.getConfig().getDefaultConsumes().orElse(OpenApiConstants.DEFAULT_MEDIA_TYPES.get())).orElse(null));
defaultConsumes).orElse(null));
String[] defaultProduces = getDefaultProduces(context, method);
context.setCurrentProduces(getMediaTypes(method, VertxConstants.ROUTE_PRODUCES,
context.getConfig().getDefaultProduces().orElse(OpenApiConstants.DEFAULT_MEDIA_TYPES.get())).orElse(null));
defaultProduces).orElse(null));

// Process any @Operation annotation
Optional<Operation> maybeOperation = processOperation(context, resourceClass, method);
Expand Down

0 comments on commit c5b1c2a

Please sign in to comment.