Search in sources :

Example 61 with ResolvedReferenceType

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();
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType)

Example 62 with ResolvedReferenceType

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;
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) StringSchema(io.swagger.v3.oas.models.media.StringSchema)

Example 63 with ResolvedReferenceType

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());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Pair(com.github.javaparser.utils.Pair) Test(org.junit.Test)

Example 64 with ResolvedReferenceType

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());
}
Also used : ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Pair(com.github.javaparser.utils.Pair) Test(org.junit.Test)

Aggregations

ResolvedReferenceType (com.github.javaparser.resolution.types.ResolvedReferenceType)64 Test (org.junit.Test)36 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)28 ReferenceTypeImpl (com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl)16 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)14 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)14 Collectors (java.util.stream.Collectors)11 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)10 MethodUsage (com.github.javaparser.resolution.MethodUsage)9 List (java.util.List)9 ArrayList (java.util.ArrayList)8 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)6 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)6 Pair (com.github.javaparser.utils.Pair)6 ResolvedTypeVariable (com.github.javaparser.resolution.types.ResolvedTypeVariable)5 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)5 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4