-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1209 from lnash94/project_api
Use Project API for Ballerina to OpenAPI code generation
- Loading branch information
Showing
18 changed files
with
420 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...bal-service/src/main/java/io/ballerina/openapi/converter/model/OASGenerationMetaInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.openapi.converter.model; | ||
|
||
import io.ballerina.compiler.api.SemanticModel; | ||
import io.ballerina.compiler.syntax.tree.ServiceDeclarationNode; | ||
import io.ballerina.projects.Project; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* This {@code OASGenerationMetaInfo} contains details related to openAPI specification. | ||
* | ||
* @since 1.6.0 | ||
*/ | ||
public class OASGenerationMetaInfo { | ||
|
||
private final String openApiFileName; | ||
private final Path ballerinaFilePath; | ||
private final SemanticModel semanticModel; | ||
private final ServiceDeclarationNode serviceDeclarationNode; | ||
private final Project project; | ||
|
||
public OASGenerationMetaInfo(OASGenerationMetaInfoBuilder builder) { | ||
this.openApiFileName = builder.openApiFileName; | ||
this.ballerinaFilePath = builder.ballerinaFilePath; | ||
this.semanticModel = builder.semanticModel; | ||
this.serviceDeclarationNode = builder.serviceDeclarationNode; | ||
this.project = builder.project; | ||
} | ||
|
||
public String getOpenApiFileName() { | ||
return openApiFileName; | ||
} | ||
|
||
public Path getBallerinaFilePath() { | ||
return ballerinaFilePath; | ||
} | ||
|
||
public SemanticModel getSemanticModel() { | ||
return semanticModel; | ||
} | ||
|
||
public ServiceDeclarationNode getServiceDeclarationNode() { | ||
return serviceDeclarationNode; | ||
} | ||
|
||
public Project getProject() { | ||
return project; | ||
} | ||
|
||
/** | ||
* This method is used to create a new {@link OASGenerationMetaInfoBuilder} instance. | ||
*/ | ||
public static class OASGenerationMetaInfoBuilder { | ||
|
||
private String openApiFileName; | ||
private Path ballerinaFilePath; | ||
private SemanticModel semanticModel; | ||
private ServiceDeclarationNode serviceDeclarationNode; | ||
private Project project; | ||
|
||
public OASGenerationMetaInfoBuilder setBallerinaFilePath(Path ballerinaFilePath) { | ||
this.ballerinaFilePath = ballerinaFilePath; | ||
return this; | ||
} | ||
|
||
public OASGenerationMetaInfoBuilder setSemanticModel(SemanticModel semanticModel) { | ||
this.semanticModel = semanticModel; | ||
return this; | ||
} | ||
|
||
public OASGenerationMetaInfoBuilder setServiceDeclarationNode(ServiceDeclarationNode serviceDeclarationNode) { | ||
this.serviceDeclarationNode = serviceDeclarationNode; | ||
return this; | ||
} | ||
|
||
public OASGenerationMetaInfoBuilder setOpenApiFileName(String openApiFileName) { | ||
this.openApiFileName = openApiFileName; | ||
return this; | ||
} | ||
|
||
public Project setProject(Project project) { | ||
this.project = project; | ||
return project; | ||
} | ||
|
||
public OASGenerationMetaInfo build() { | ||
return new OASGenerationMetaInfo(this); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...bal-service/src/main/java/io/ballerina/openapi/converter/service/ModuleMemberVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.openapi.converter.service; | ||
|
||
import io.ballerina.compiler.syntax.tree.ListenerDeclarationNode; | ||
import io.ballerina.compiler.syntax.tree.NodeVisitor; | ||
import io.ballerina.compiler.syntax.tree.TypeDefinitionNode; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Visitor to get the TypeDefinitionNode and ListenerDeclarationNodes. | ||
* | ||
* @since 1.6.0 | ||
*/ | ||
public class ModuleMemberVisitor extends NodeVisitor { | ||
|
||
LinkedList<TypeDefinitionNode> typeDefinitionNodes = new LinkedList<>(); | ||
LinkedList<ListenerDeclarationNode> listenerDeclarationNodes = new LinkedList<>(); | ||
|
||
@Override | ||
public void visit(TypeDefinitionNode typeDefinitionNode) { | ||
typeDefinitionNodes.add(typeDefinitionNode); | ||
} | ||
|
||
@Override | ||
public void visit(ListenerDeclarationNode listenerDeclarationNode) { | ||
listenerDeclarationNodes.add(listenerDeclarationNode); | ||
} | ||
|
||
public List<TypeDefinitionNode> getTypeDefinitionNodes() { | ||
return typeDefinitionNodes; | ||
} | ||
|
||
public List<ListenerDeclarationNode> getListenerDeclarationNodes() { | ||
return listenerDeclarationNodes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.