use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class PathsBuilderTest method setupBaseDocument.
@Override
protected void setupBaseDocument(OpenAPI document) {
Operation operation = createOperation().summary("summary").description("description").responses(createAPIResponses().addAPIResponse("200", createAPIResponse().ref("ref")));
document.paths(createPaths().addExtension("x-ext", "ext-value").addPathItem("/item1/", createPathItem().summary("summary").description("description").GET(operation).DELETE(operation).HEAD(operation).OPTIONS(operation).PATCH(operation).POST(operation).PUT(operation).TRACE(operation).addExtension("x-ext", "ext-value").addServer(createServer().url("url1")).addServer(createServer().url("url2")).addParameter(createParameter().name("name1").in(In.QUERY)).addParameter(createParameter().name("name2").in(In.COOKIE))));
}
use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class ApplicationProcessor method mapException.
/**
* When an exception mapper is encountered, register the mapped response and
* find any operations already parsed that this exception mapper is applicable
* to
*/
private void mapException(ApiContext context, String exceptionType, APIResponseImpl exceptionResponse) {
// Don't allow null responses
if (exceptionResponse.getDescription() == null || exceptionResponse.getDescription().isEmpty()) {
exceptionResponse.setDescription(ModelUtils.getSimpleName(exceptionType));
}
context.addMappedExceptionResponse(exceptionType, exceptionResponse);
final String exceptionStatus = exceptionResponse.getResponseCode();
if (exceptionStatus != null) {
for (PathItem path : context.getApi().getPaths().getPathItems().values()) {
for (Operation operation : path.getOperations().values()) {
if (((OperationImpl) operation).getExceptionTypes().contains(exceptionType)) {
operation.getResponses().addAPIResponse(exceptionStatus, exceptionResponse);
}
}
}
} else {
LOGGER.fine("Failed to add mapped response as no response code was provided");
}
}
use of org.eclipse.microprofile.openapi.models.Operation 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.eclipse.microprofile.openapi.models.Operation 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.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class CallbackImpl method applyCallbackOperationAnnotation.
private static void applyCallbackOperationAnnotation(PathItem pathItem, Operation callbackOperation, boolean override, ApiContext context) {
if (callbackOperation instanceof OperationImpl) {
OperationImpl callbackOperationImpl = (OperationImpl) callbackOperation;
if (callbackOperationImpl.getMethod() != null) {
HttpMethod method = getHttpMethod(callbackOperationImpl.getMethod());
if (method != null) {
Operation operation = getOrCreateOperation(pathItem, method);
OperationImpl.merge(callbackOperation, operation, override, context);
}
}
}
}
Aggregations