use of org.glassfish.hk2.classmodel.reflect.MethodModel in project Payara by payara.
the class ApplicationProcessor method visitSecurityRequirement.
@Override
public void visitSecurityRequirement(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel) {
String securityRequirementName = annotation.getValue("name", String.class);
SecurityRequirement securityRequirement = SecurityRequirementImpl.createInstance(annotation, context);
if (securityRequirementName != null && !securityRequirementName.isEmpty()) {
SecurityRequirement model = new SecurityRequirementImpl();
SecurityRequirementImpl.merge(securityRequirement, model);
context.getWorkingOperation().addSecurityRequirement(model);
}
}
}
use of org.glassfish.hk2.classmodel.reflect.MethodModel 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.MethodModel in project Payara by payara.
the class ApplicationProcessor method findOperationParameterFor.
private static Parameter findOperationParameterFor(Parameter parameter, MethodModel annotated, ApiContext context) {
String name = parameter.getName();
// If the parameter reference is valid
if (name != null && !name.isEmpty()) {
// Get all parameters with the same name
List<org.glassfish.hk2.classmodel.reflect.Parameter> matchingMethodParameters = annotated.getParameters().stream().filter(x -> name.equals(ModelUtils.getParameterName(context, x))).collect(Collectors.toList());
// If there is more than one match, filter it further
In in = parameter.getIn();
if (matchingMethodParameters.size() > 1 && in != null) {
// Remove all parameters of the wrong input type
matchingMethodParameters.removeIf(x -> ModelUtils.getParameterType(context, x) != In.valueOf(in.name()));
}
if (matchingMethodParameters.isEmpty()) {
return null;
}
// If there's only one matching parameter, handle it immediately
String matchingMethodParamName = ModelUtils.getParameterName(context, matchingMethodParameters.get(0));
// Find the matching operation parameter
for (Parameter operationParam : context.getWorkingOperation().getParameters()) {
if (operationParam.getName().equals(matchingMethodParamName)) {
return operationParam;
}
}
}
return null;
}
use of org.glassfish.hk2.classmodel.reflect.MethodModel 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.MethodModel in project Payara by payara.
the class ApplicationProcessor method insertDefaultRequestBody.
// PRIVATE METHODS
private RequestBody insertDefaultRequestBody(ApiContext context, Operation operation, MethodModel method) {
RequestBody requestBody = new RequestBodyImpl();
// Get the request body type of the method
org.glassfish.hk2.classmodel.reflect.ParameterizedType bodyType = null;
for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : method.getParameters()) {
if (ModelUtils.isRequestBody(context, methodParam)) {
bodyType = methodParam;
break;
}
}
if (bodyType == null) {
return null;
}
// Create the default request body with a wildcard mediatype
MediaType mediaType = new MediaTypeImpl().schema(createSchema(context, bodyType));
requestBody.getContent().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, mediaType);
operation.setRequestBody(requestBody);
return requestBody;
}
Aggregations