use of com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration in project flow by vaadin.
the class SchemaGenerator method createSingleSchemaFromResolvedType.
Schema createSingleSchemaFromResolvedType(GeneratorType type) {
ResolvedReferenceType resolvedReferenceType = type.asResolvedType().asReferenceType();
if (type.isEnum()) {
List<String> entries = resolvedReferenceType.getTypeDeclaration().orElseThrow(IllegalArgumentException::new).asEnum().getEnumConstants().stream().map(ResolvedEnumConstantDeclaration::getName).collect(Collectors.toList());
StringSchema schema = new StringSchema();
schema.name(resolvedReferenceType.getQualifiedName());
schema.setEnum(entries);
return schema;
}
Schema schema = new ObjectSchema().name(resolvedReferenceType.getQualifiedName());
Map<String, Boolean> fieldsOptionalMap = getFieldsAndOptionalMap(type);
List<ResolvedFieldDeclaration> serializableFields = resolvedReferenceType.getTypeDeclaration().orElseThrow(IllegalArgumentException::new).getDeclaredFields().stream().filter(resolvedFieldDeclaration -> fieldsOptionalMap.containsKey(resolvedFieldDeclaration.getName())).collect(Collectors.toList());
// Make sure the order is consistent in properties map
schema.setProperties(new LinkedHashMap<>());
for (ResolvedFieldDeclaration resolvedFieldDeclaration : serializableFields) {
String name = resolvedFieldDeclaration.getName();
ResolvedType fieldType = resolvedFieldDeclaration.getType();
ResolvedType mappedType = openApiObjectGenerator.toMappedType(fieldType);
if (mappedType != null) {
fieldType = mappedType;
}
Schema subtype = openApiObjectGenerator.parseResolvedTypeToSchema(new GeneratorType(fieldType)).nullable(null);
if (!fieldsOptionalMap.get(name)) {
schema.addRequiredItem(name);
}
schema.addProperties(name, subtype);
}
return schema;
}
Aggregations