use of org.eclipse.microprofile.openapi.models.Operation in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readCallbackOperations.
/**
* Reads the CallbackOperation annotations as a PathItem. The annotation value
* in this case is an array of CallbackOperation annotations.
* @param value
*/
private PathItem readCallbackOperations(AnnotationValue value) {
if (value == null) {
return null;
}
LOG.debug("Processing an array of @CallbackOperation annotations.");
AnnotationInstance[] nestedArray = value.asNestedArray();
PathItem pathItem = new PathItemImpl();
for (AnnotationInstance operationAnno : nestedArray) {
String method = JandexUtil.stringValue(operationAnno, OpenApiConstants.PROP_METHOD);
Operation operation = readCallbackOperation(operationAnno);
if (method == null) {
continue;
}
try {
PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(pathItem, method.toUpperCase());
Method mutator = PropertyUtils.getWriteMethod(descriptor);
mutator.invoke(pathItem, operation);
} catch (Exception e) {
LOG.error("Error reading a CallbackOperation annotation.", e);
}
}
return pathItem;
}
use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class ApplicationProcessor method addParameter.
private static void addParameter(AnnotatedElement element, ApiContext context, String name, In in, Boolean required) {
Boolean hidden = false;
AnnotationModel paramAnnotation = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.parameters.Parameter.class.getName());
if (paramAnnotation != null) {
hidden = paramAnnotation.getValue("hidden", Boolean.class);
}
if (hidden != null && hidden) {
return;
}
Parameter newParameter = new ParameterImpl();
newParameter.setName(name);
newParameter.setIn(in);
newParameter.setRequired(required);
SchemaImpl schema = new SchemaImpl();
String defaultValue = getDefaultValueIfPresent(element);
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
schema.setType(ModelUtils.getSchemaType(parameter.getTypeName(), context));
} else {
FieldModel field = (FieldModel) element;
schema.setType(ModelUtils.getSchemaType(field.getTypeName(), context));
}
if (schema.getType() == SchemaType.ARRAY) {
schema.setItems(getArraySchema(element, context));
if (defaultValue != null) {
schema.getItems().setDefaultValue(defaultValue);
}
} else if (defaultValue != null) {
schema.setDefaultValue(defaultValue);
}
newParameter.setSchema(schema);
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
for (Parameter parameter : workingOperation.getParameters()) {
final String parameterName = parameter.getName();
if (parameterName != null && parameterName.equals(newParameter.getName())) {
ParameterImpl.merge(newParameter, parameter, false, context);
return;
}
}
workingOperation.addParameter(newParameter);
} else {
LOGGER.log(SEVERE, "Couldn''t add {0} parameter, \"{1}\" to the OpenAPI Document. This is usually caused by declaring parameter under a method with an unsupported annotation.", new Object[] { newParameter.getIn(), newParameter.getName() });
}
}
use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class ApplicationProcessor method visitParameters.
@Override
public void visitParameters(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
List<AnnotationModel> parameters = annotation.getValue("value", List.class);
if (parameters != null) {
for (AnnotationModel paramAnnotation : parameters) {
final Parameter parameter = ParameterImpl.createInstance(paramAnnotation, context);
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
workingOperation.addParameter(parameter);
}
}
}
}
use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class ApplicationProcessor method visitFormParam.
@Override
public void visitFormParam(AnnotationModel param, AnnotatedElement element, ApiContext context) {
// Find the aggregate schema type of all the parameters
SchemaType formSchemaType = null;
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
List<org.glassfish.hk2.classmodel.reflect.Parameter> parameters = ((org.glassfish.hk2.classmodel.reflect.Parameter) element).getMethod().getParameters();
for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : parameters) {
if (methodParam.getAnnotation(FormParam.class.getName()) != null) {
formSchemaType = ModelUtils.getParentSchemaType(formSchemaType, ModelUtils.getSchemaType(methodParam, context));
}
}
}
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
// If there's no request body, fill out a new one right down to the schema
if (workingOperation.getRequestBody() == null) {
workingOperation.setRequestBody(new RequestBodyImpl().content(new ContentImpl().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, new MediaTypeImpl().schema(new SchemaImpl()))));
}
for (MediaType mediaType : workingOperation.getRequestBody().getContent().getMediaTypes().values()) {
final Schema schema = mediaType.getSchema();
if (schema != null) {
schema.setType(formSchemaType);
}
}
}
}
use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.
the class CallbackImpl method merge.
public static void merge(Callback from, Callback to, boolean override, ApiContext context) {
if (from == null) {
return;
}
if (from.getRef() != null && !from.getRef().isEmpty()) {
applyReference(to, from.getRef());
return;
}
if (from instanceof CallbackImpl) {
CallbackImpl fromImpl = (CallbackImpl) from;
String urlExpression = fromImpl.getUrlExpression();
if (urlExpression != null && !urlExpression.isEmpty()) {
PathItem pathItem = to.getPathItems().getOrDefault(urlExpression, new PathItemImpl());
to.addPathItem(urlExpression, pathItem);
if (fromImpl.getOperations() != null) {
for (Operation callbackOperation : fromImpl.getOperations()) {
applyCallbackOperationAnnotation(pathItem, callbackOperation, override, context);
}
}
}
}
}
Aggregations