use of org.jboss.jandex.ParameterizedType in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method readParamType.
private Type readParamType(PathEntry pathEntry, Schema schema, ParameterizedType pType, TypeResolver typeResolver) {
LOG.debugv("Processing parameterized type {0}", pType);
// If it's a collection, we should treat it as an array.
if (isA(pType, COLLECTION_TYPE)) {
// TODO maybe also Iterable?
LOG.debugv("Processing Java Collection. Will treat as an array.");
SchemaImpl arraySchema = new SchemaImpl();
schema.type(Schema.SchemaType.ARRAY);
schema.items(arraySchema);
// Should only have one arg for collection.
Type arg = pType.arguments().get(0);
if (isTerminalType(arg)) {
TypeUtil.TypeWithFormat terminalType = TypeUtil.getTypeFormat(arg);
arraySchema.type(terminalType.getSchemaType());
arraySchema.format(terminalType.getFormat().format());
} else if (arg.kind() == Type.Kind.TYPE_VARIABLE || arg.kind() == Type.Kind.UNRESOLVED_TYPE_VARIABLE || arg.kind() == Type.Kind.WILDCARD_TYPE) {
Type resolved = resolveTypeVariable(typeResolver, arraySchema, pathEntry, arg);
if (indexContains(resolved)) {
arraySchema.type(Schema.SchemaType.OBJECT);
}
} else if (indexContains(arg)) {
arraySchema.type(Schema.SchemaType.OBJECT);
pushFieldToPath(pathEntry, arg, arraySchema);
}
// Representing collection as JSON array
return ARRAY_TYPE_OBJECT;
} else if (isA(pType, MAP_TYPE)) {
LOG.debugv("Processing Map. Will treat as an object.");
schema.type(Schema.SchemaType.OBJECT);
if (pType.arguments().size() == 2) {
Type valueType = pType.arguments().get(1);
SchemaImpl propsSchema = new SchemaImpl();
if (isTerminalType(valueType)) {
TypeUtil.TypeWithFormat tf = TypeUtil.getTypeFormat(valueType);
propsSchema.setType(tf.getSchemaType());
propsSchema.setFormat(tf.getFormat().format());
} else if (valueType.kind() == Type.Kind.TYPE_VARIABLE || valueType.kind() == Type.Kind.UNRESOLVED_TYPE_VARIABLE || valueType.kind() == Type.Kind.WILDCARD_TYPE) {
Type resolved = resolveTypeVariable(typeResolver, propsSchema, pathEntry, valueType);
if (indexContains(resolved)) {
propsSchema.type(Schema.SchemaType.OBJECT);
}
} else if (indexContains(valueType)) {
propsSchema.type(Schema.SchemaType.OBJECT);
pushFieldToPath(pathEntry, valueType, propsSchema);
}
schema.additionalProperties(propsSchema);
}
return OBJECT_TYPE;
} else {
// This attempts to allow us to resolve the types generically.
ClassInfo klazz = getClassByName(pType);
// Build mapping of class's type variables (e.g. A, B) to resolved variables
// Resolved variables could be any type (e.g. String, another param type, etc)
PathEntry pair = new PathEntry(pathEntry, klazz, pType, schema);
path.push(pair);
return pType;
}
}
use of org.jboss.jandex.ParameterizedType in project wildfly-swarm by wildfly-swarm.
the class TypeResolver method buildParamTypeResolutionMap.
private static Map<String, Type> buildParamTypeResolutionMap(ClassInfo klazz, ParameterizedType parameterizedType) {
List<TypeVariable> typeVariables = klazz.typeParameters();
List<Type> arguments = parameterizedType.arguments();
if (arguments.size() != typeVariables.size()) {
LOG.errorv("Unanticipated mismatch between type arguments and type variables \n" + "Args: {0}\n Vars:{1}", arguments, typeVariables);
}
Map<String, Type> resolutionMap = new LinkedHashMap<>();
for (int i = 0; i < arguments.size(); i++) {
TypeVariable typeVar = typeVariables.get(i);
Type arg = arguments.get(i);
resolutionMap.put(typeVar.identifier(), arg);
}
return resolutionMap;
}
Aggregations