use of org.glassfish.hk2.classmodel.reflect.FieldModel in project Payara by payara.
the class ApplicationProcessor method getArraySchema.
private static SchemaImpl getArraySchema(AnnotatedElement element, ApiContext context) {
SchemaImpl arraySchema = new SchemaImpl();
List<ParameterizedType> parameterizedType;
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
parameterizedType = parameter.getParameterizedTypes();
} else {
FieldModel field = (FieldModel) element;
parameterizedType = field.getParameterizedTypes();
}
arraySchema.setType(ModelUtils.getSchemaType(parameterizedType.get(0).getTypeName(), context));
return arraySchema;
}
use of org.glassfish.hk2.classmodel.reflect.FieldModel 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.glassfish.hk2.classmodel.reflect.FieldModel in project Payara by payara.
the class ModelUtils method getSchemaName.
@SuppressWarnings("unchecked")
public static String getSchemaName(ApiContext context, AnnotatedElement type) {
assert type != null;
// context and annotation can be null
final Class<? extends Annotation>[] ANNOTATION_TYPES = new Class[] { org.eclipse.microprofile.openapi.annotations.media.Schema.class, javax.xml.bind.annotation.XmlRootElement.class, javax.xml.bind.annotation.XmlElement.class };
for (Class<? extends Annotation> annotationType : ANNOTATION_TYPES) {
AnnotationModel annotationModel;
// Fetch the element annotations
if (context != null && type instanceof ExtensibleType) {
// Fetch the annotation from the cache
ExtensibleType<?> implementationType = (ExtensibleType<?>) type;
AnnotationInfo annotationInfo = context.getAnnotationInfo(implementationType);
annotationModel = annotationInfo.getAnnotation(annotationType);
} else {
// Fetch the annotation manually
annotationModel = type.getAnnotation(annotationType.getName());
}
// Fields can be named by their accessors
if (annotationModel == null) {
if (type instanceof FieldModel) {
final FieldModel field = (FieldModel) type;
final String accessorName = getAccessorName(field.getName());
for (MethodModel method : field.getDeclaringType().getMethods()) {
// Check if it's the accessor
if (accessorName.equals(method.getName())) {
annotationModel = type.getAnnotation(annotationType.getName());
break;
}
}
}
}
// Get the schema name if the annotation exists
if (annotationModel != null) {
final String name = annotationModel.getValue("name", String.class);
if (name != null && !name.isEmpty() && !name.equals("##default")) {
return name;
}
}
}
return getSimpleName(type.getName());
}
use of org.glassfish.hk2.classmodel.reflect.FieldModel in project Payara by payara.
the class AnnotationInfo method init.
private void init(ExtensibleType<? extends ExtensibleType> type) {
// recurse first so that re-stated annotations "override"
ExtensibleType<? extends ExtensibleType> supertype = type.getParent();
if (supertype != null) {
init(supertype);
}
for (InterfaceModel implementedInterface : type.getInterfaces()) {
if (implementedInterface != null && implementedInterface != type) {
init(implementedInterface);
}
}
// collect annotations
putAll(type.getAnnotations(), typeAnnotations);
if (type instanceof ClassModel) {
for (FieldModel field : ((ClassModel) type).getFields()) {
putAll(field.getAnnotations(), fieldAnnotations.computeIfAbsent(field.getName(), key -> new ConcurrentHashMap<>()));
}
}
for (MethodModel method : type.getMethods()) {
putAll(method.getAnnotations(), methodAnnotations.computeIfAbsent(getSignature(method), key -> new ConcurrentHashMap<>()));
for (Parameter parameter : method.getParameters()) {
putAll(parameter.getAnnotations(), methodParameterAnnotations.computeIfAbsent(getIdentifier(parameter), key -> new ConcurrentHashMap<>()));
}
}
}
use of org.glassfish.hk2.classmodel.reflect.FieldModel in project Payara by payara.
the class OpenApiWalker method processAnnotation.
@SuppressWarnings("unchecked")
public final void processAnnotation(ClassModel annotatedClass, ApiVisitor visitor) {
AnnotationInfo annotations = context.getAnnotationInfo(annotatedClass);
processAnnotation((E) annotatedClass, annotations, visitor, new OpenApiContext(context, annotatedClass));
for (final MethodModel method : annotatedClass.getMethods()) {
processAnnotation((E) method, annotations, visitor, new OpenApiContext(context, method));
}
for (final FieldModel field : annotatedClass.getFields()) {
processAnnotation((E) field, annotations, visitor, new OpenApiContext(context, field));
}
for (final MethodModel method : annotatedClass.getMethods()) {
for (org.glassfish.hk2.classmodel.reflect.Parameter parameter : method.getParameters()) {
processAnnotation((E) parameter, annotations, visitor, new OpenApiContext(context, method));
}
}
}
Aggregations