use of fish.payara.microprofile.openapi.impl.visitor.AnnotationInfo 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());
}
Aggregations