use of com.github.javaparser.resolution.types.ResolvedReferenceType in project flow by vaadin.
the class SchemaResolver method createUserBeanSchema.
private Schema createUserBeanSchema() {
if (type.isReference()) {
ResolvedReferenceType resolvedReferenceType = type.asResolvedType().asReferenceType();
String qualifiedName = resolvedReferenceType.getQualifiedName();
usedTypes.put(qualifiedName, type);
return new ObjectSchema().name(qualifiedName).$ref(getFullQualifiedNameRef(qualifiedName));
}
return new ObjectSchema();
}
use of com.github.javaparser.resolution.types.ResolvedReferenceType in project flow by vaadin.
the class SchemaResolver method createEnumTypeSchema.
private Schema createEnumTypeSchema() {
ResolvedReferenceType resolvedReferenceType = type.asResolvedType().asReferenceType();
List<String> entries = resolvedReferenceType.getTypeDeclaration().orElseThrow(IllegalArgumentException::new).asEnum().getEnumConstants().stream().map(ResolvedEnumConstantDeclaration::getName).collect(Collectors.toList());
String qualifiedName = resolvedReferenceType.getQualifiedName();
usedTypes.put(qualifiedName, type);
StringSchema schema = new StringSchema();
schema.name(qualifiedName);
schema.setEnum(entries);
schema.$ref(getFullQualifiedNameRef(qualifiedName));
return schema;
}
use of com.github.javaparser.resolution.types.ResolvedReferenceType in project flow by vaadin.
the class SchemaResolverTest method should_ReturnNullableArray_When_GivenTypeIsAListString.
@Test
public void should_ReturnNullableArray_When_GivenTypeIsAListString() {
ResolvedType resolvedType = mockReferencedTypeOf(Collection.class);
ResolvedReferenceType resolvedReferenceType = resolvedType.asReferenceType();
List<Pair<ResolvedTypeParameterDeclaration, ResolvedType>> pairs = Collections.singletonList(new Pair<>(null, mockReferencedTypeOf(String.class)));
when(resolvedReferenceType.getTypeParametersMap()).thenReturn(pairs);
Map<String, GeneratorType> usedTypes = new HashMap<>();
SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(resolvedType), usedTypes);
Schema schema = schemaResolver.resolve();
Assert.assertTrue(schema instanceof ArraySchema);
Assert.assertTrue(schema.getNullable());
Assert.assertTrue(((ArraySchema) schema).getItems() instanceof StringSchema);
Assert.assertTrue(usedTypes.isEmpty());
}
use of com.github.javaparser.resolution.types.ResolvedReferenceType in project flow by vaadin.
the class SchemaResolverTest method should_ReturnNullableOptional_When_GivenTypeIsAnOptionalString.
@Test
public void should_ReturnNullableOptional_When_GivenTypeIsAnOptionalString() {
ResolvedType resolvedType = mockReferencedTypeOf(Optional.class);
ResolvedReferenceType resolvedReferenceType = resolvedType.asReferenceType();
List<Pair<ResolvedTypeParameterDeclaration, ResolvedType>> pairs = Collections.singletonList(new Pair<>(null, mockReferencedTypeOf(String.class)));
when(resolvedReferenceType.getTypeParametersMap()).thenReturn(pairs);
Map<String, GeneratorType> usedTypes = new HashMap<>();
SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(resolvedType), usedTypes);
Schema schema = schemaResolver.resolve();
Assert.assertTrue(schema instanceof StringSchema);
Assert.assertTrue(schema.getNullable());
Assert.assertTrue(usedTypes.isEmpty());
}
Aggregations