Search in sources :

Example 6 with SourceRoot

use of com.github.javaparser.utils.SourceRoot in project flow by vaadin.

the class OpenAPIObjectGenerator method init.

private void init() {
    if (javaSourcePaths == null || configuration == null) {
        throw new IllegalStateException("Java source path and configuration should not be null");
    }
    openApiModel = createBasicModel();
    nonEndpointMap = new HashMap<>();
    endpointExposedMap = new HashMap<>();
    qualifiedNameToPath = new HashMap<>();
    pathItems = new TreeMap<>();
    usedTypes = new HashMap<>();
    generatedSchema = new HashSet<>();
    endpointsJavadoc = new HashMap<>();
    schemaGenerator = new SchemaGenerator(this);
    needsDeferrableImport = false;
    ParserConfiguration parserConfiguration = createParserConfiguration();
    javaSourcePaths.stream().map(path -> new SourceRoot(path, parserConfiguration)).forEach(sourceRoot -> parseSourceRoot(sourceRoot, this::findEndpointExposed));
    javaSourcePaths.stream().map(path -> new SourceRoot(path, parserConfiguration)).forEach(sourceRoot -> parseSourceRoot(sourceRoot, this::process));
    for (Map.Entry<String, GeneratorType> entry : new ArrayList<>(usedTypes.entrySet())) {
        List<Schema> schemas = createSchemasFromQualifiedNameAndType(entry.getKey(), entry.getValue());
        schemas.forEach(schema -> {
            if (qualifiedNameToPath.get(schema.getName()) != null) {
                schema.addExtension(EXTENSION_VAADIN_FILE_PATH, qualifiedNameToPath.get(schema.getName()));
            }
            openApiModel.getComponents().addSchemas(schema.getName(), schema);
        });
    }
    addTagsInformation();
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) RolesAllowed(javax.annotation.security.RolesAllowed) LoggerFactory(org.slf4j.LoggerFactory) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement) Operation(io.swagger.v3.oas.models.Operation) LiteralStringValueExpr(com.github.javaparser.ast.expr.LiteralStringValueExpr) Pair(com.github.javaparser.utils.Pair) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ResolvedReferenceTypeDeclaration(com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration) NodeWithSimpleName(com.github.javaparser.ast.nodeTypes.NodeWithSimpleName) Type(com.github.javaparser.ast.type.Type) Scopes(io.swagger.v3.oas.models.security.Scopes) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Tag(io.swagger.v3.oas.models.tags.Tag) Path(java.nio.file.Path) JavaSymbolSolver(com.github.javaparser.symbolsolver.JavaSymbolSolver) NodeList(com.github.javaparser.ast.NodeList) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) Content(io.swagger.v3.oas.models.media.Content) PermitAll(javax.annotation.security.PermitAll) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) Collection(java.util.Collection) MediaType(io.swagger.v3.oas.models.media.MediaType) Set(java.util.Set) ParserConfiguration(com.github.javaparser.ParserConfiguration) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) EndpointTransferMapper(dev.hilla.endpointransfermapper.EndpointTransferMapper) Paths(io.swagger.v3.oas.models.Paths) Endpoint(dev.hilla.Endpoint) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) EndpointNameChecker(dev.hilla.EndpointNameChecker) Server(io.swagger.v3.oas.models.servers.Server) Optional(java.util.Optional) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) EndpointExposed(dev.hilla.EndpointExposed) ParseResult(com.github.javaparser.ParseResult) Callback(com.github.javaparser.utils.SourceRoot.Callback) Parameter(com.github.javaparser.ast.body.Parameter) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) HashMap(java.util.HashMap) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) TreeSet(java.util.TreeSet) OAuthFlows(io.swagger.v3.oas.models.security.OAuthFlows) ArrayList(java.util.ArrayList) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Schema(io.swagger.v3.oas.models.media.Schema) DenyAll(javax.annotation.security.DenyAll) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) SourceRoot(com.github.javaparser.utils.SourceRoot) Logger(org.slf4j.Logger) ReferenceTypeImpl(com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl) PathItem(io.swagger.v3.oas.models.PathItem) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) Info(io.swagger.v3.oas.models.info.Info) MapSchema(io.swagger.v3.oas.models.media.MapSchema) ResolvedReferenceType(com.github.javaparser.resolution.types.ResolvedReferenceType) TreeMap(java.util.TreeMap) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) OAuthFlow(io.swagger.v3.oas.models.security.OAuthFlow) Javadoc(com.github.javaparser.javadoc.Javadoc) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) Components(io.swagger.v3.oas.models.Components) AnonymousAllowed(com.vaadin.flow.server.auth.AnonymousAllowed) ClassLoaderTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ClassLoaderTypeSolver) Comparator(java.util.Comparator) Collections(java.util.Collections) ResolvedTypeParametersMap(com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap) 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) SourceRoot(com.github.javaparser.utils.SourceRoot) ParserConfiguration(com.github.javaparser.ParserConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ResolvedTypeParametersMap(com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap)

Aggregations

SourceRoot (com.github.javaparser.utils.SourceRoot)6 Path (java.nio.file.Path)4 Test (org.junit.Test)2 ParseResult (com.github.javaparser.ParseResult)1 ParserConfiguration (com.github.javaparser.ParserConfiguration)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 NodeList (com.github.javaparser.ast.NodeList)1 BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 LiteralStringValueExpr (com.github.javaparser.ast.expr.LiteralStringValueExpr)1 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)1 NodeWithSimpleName (com.github.javaparser.ast.nodeTypes.NodeWithSimpleName)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 Type (com.github.javaparser.ast.type.Type)1