use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitAPIResponse.
@Override
public void visitAPIResponse(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
APIResponseImpl apiResponse = APIResponseImpl.createInstance(annotation, context);
Operation workingOperation = context.getWorkingOperation();
// Handle exception mappers
if (workingOperation == null) {
if (element instanceof MethodModel && "toResponse".equals(element.getName())) {
final MethodModel methodModel = (MethodModel) element;
final String exceptionType = methodModel.getParameter(0).getTypeName();
mapException(context, exceptionType, apiResponse);
} else {
LOGGER.warning("Unrecognised annotation position at: " + element.shortDesc());
}
return;
}
APIResponsesImpl.merge(apiResponse, workingOperation.getResponses(), true, context);
// If an APIResponse has been processed that isn't the default
String responseCode = apiResponse.getResponseCode();
if (responseCode != null && !responseCode.isEmpty() && !responseCode.equals(APIResponses.DEFAULT)) {
// If the element doesn't also contain a response mapping to the default
AnnotationModel apiResponsesParent = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.responses.APIResponses.class.getName());
if (apiResponsesParent != null) {
List<AnnotationModel> apiResponses = apiResponsesParent.getValue("value", List.class);
if (apiResponses.stream().map(a -> a.getValue("responseCode", String.class)).noneMatch(code -> code == null || code.isEmpty() || code.equals(APIResponses.DEFAULT))) {
// Then remove the default response
workingOperation.getResponses().removeAPIResponse(APIResponses.DEFAULT);
}
} else {
workingOperation.getResponses().removeAPIResponse(APIResponses.DEFAULT);
}
}
}
use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitCallback.
@Override
public void visitCallback(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel) {
String name = annotation.getValue("name", String.class);
Callback callbackModel = context.getWorkingOperation().getCallbacks().getOrDefault(name, new CallbackImpl());
context.getWorkingOperation().addCallback(name, callbackModel);
CallbackImpl.merge(CallbackImpl.createInstance(annotation, context), callbackModel, true, context);
}
}
use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitRequestBodySchema.
@Override
public void visitRequestBodySchema(AnnotationModel requestBodySchema, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel || element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
final RequestBody currentRequestBody = context.getWorkingOperation().getRequestBody();
if (currentRequestBody != null) {
final String implementationClass = requestBodySchema.getValue("value", String.class);
final SchemaImpl schema = SchemaImpl.fromImplementation(implementationClass, context);
for (MediaType mediaType : currentRequestBody.getContent().getMediaTypes().values()) {
mediaType.setSchema(schema);
}
}
}
}
Aggregations