Search in sources :

Example 76 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project flow by vaadin.

the class OpenAPIObjectGenerator method parseNonEndpointClassAsSchema.

private List<Schema> parseNonEndpointClassAsSchema(String fullQualifiedName) {
    TypeDeclaration<?> typeDeclaration = nonEndpointMap.get(fullQualifiedName);
    if (typeDeclaration == null || typeDeclaration.isEnumDeclaration()) {
        return Collections.emptyList();
    }
    List<Schema> result = new ArrayList<>();
    Schema schema = schemaGenerator.createSingleSchema(fullQualifiedName, typeDeclaration);
    generatedSchema.add(fullQualifiedName);
    NodeList<ClassOrInterfaceType> extendedTypes = null;
    if (typeDeclaration.isClassOrInterfaceDeclaration()) {
        extendedTypes = typeDeclaration.asClassOrInterfaceDeclaration().getExtendedTypes();
    }
    if (extendedTypes == null || extendedTypes.isEmpty()) {
        result.add(schema);
        result.addAll(generatedRelatedSchemas(schema));
    } else {
        ComposedSchema parentSchema = new ComposedSchema();
        parentSchema.setName(fullQualifiedName);
        result.add(parentSchema);
        extendedTypes.forEach(parentType -> {
            GeneratorType type = new GeneratorType(parentType.resolve());
            String parentQualifiedName = type.asResolvedType().asReferenceType().getQualifiedName();
            String parentRef = SchemaResolver.getFullQualifiedNameRef(parentQualifiedName);
            parentSchema.addAllOfItem(new ObjectSchema().$ref(parentRef));
            usedTypes.put(parentQualifiedName, type);
        });
        // The inserting order matters for `allof` property.
        parentSchema.addAllOfItem(schema);
        result.addAll(generatedRelatedSchemas(parentSchema));
    }
    return result;
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ArrayList(java.util.ArrayList) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema)

Aggregations

ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)76 Expression (com.github.javaparser.ast.expr.Expression)33 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)29 Type (com.github.javaparser.ast.type.Type)24 NameExpr (com.github.javaparser.ast.expr.NameExpr)23 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)21 DrlxParseUtil.toClassOrInterfaceType (org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType)21 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)17 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)17 NodeList (com.github.javaparser.ast.NodeList)14 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)13 TypeParameter (com.github.javaparser.ast.type.TypeParameter)13 StaticJavaParser.parseClassOrInterfaceType (com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType)12 Test (org.junit.Test)11 StaticJavaParser.parseType (com.github.javaparser.StaticJavaParser.parseType)9 List (java.util.List)9 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)8 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)7 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)7 HashMap (java.util.HashMap)7