Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Apr 29, 2024
1 parent 49ca174 commit 7e4eeef
Show file tree
Hide file tree
Showing 32 changed files with 524 additions and 2,670 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void getFunctionBodyNodes(String yamlFile, String path, String content) t
TypeHandler.createInstance(openapi, false);
FunctionBodyGeneratorImp functionBodyGeneratorImp = new FunctionBodyGeneratorImp(path, operation, openapi,
new AuthConfigGeneratorImp(false, false),
new BallerinaUtilGenerator(), new ArrayList<>());
new BallerinaUtilGenerator(), new ArrayList<>(), false, false, false);
Optional<FunctionBodyNode> bodyNode = functionBodyGeneratorImp.getFunctionBodyNode();
content = content.trim().replaceAll("\n", "").replaceAll("\\s+", "");
String bodyNodeContent = bodyNode.get().toString().trim().replaceAll("\n", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void getFunctionSignatureNodeTests() throws IOException, BallerinaOpenApi
Operation operation = openAPI.getPaths().get("/products/{country}").getGet();
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(operation,
openAPI, "get");
openAPI, "get", "products/{country}");
Optional<FunctionSignatureNode> signature = functionSignatureGenerator.generateFunctionSignature();
SeparatedNodeList<ParameterNode> parameters = signature.get().parameters();
Assert.assertFalse(parameters.isEmpty());
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testFunctionSignatureNodeForXMLPayload() throws IOException, Balleri
Operation operation = openAPI.getPaths().get("/pets").getPost();
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(operation,
openAPI, "post");
openAPI, "post", "/pets");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
SeparatedNodeList<ParameterNode> parameters = signature.parameters();
Assert.assertFalse(parameters.isEmpty());
Expand All @@ -111,7 +111,7 @@ public void testFunctionSignatureNodeForJSONPayload() throws IOException, Baller
Operation operation = openAPI.getPaths().get("/pets").getPost();
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(operation,
openAPI, "post");
openAPI, "post", "/pets");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
SeparatedNodeList<ParameterNode> parameters = signature.parameters();
Assert.assertFalse(parameters.isEmpty());
Expand All @@ -131,7 +131,7 @@ public void testFunctionSignatureNodeForMultipartCustomHeader() throws IOExcepti
Operation operation = openAPI.getPaths().get("/pets").getPost();
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(operation,
openAPI, "post");
openAPI, "post", "/pets");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
SeparatedNodeList<ParameterNode> parameters = signature.parameters();
Assert.assertFalse(parameters.isEmpty());
Expand All @@ -157,7 +157,7 @@ public void getFunctionSignatureForNestedArrayResponse() throws IOException, Bal
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/response_nested_array.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(
openAPI.getPaths().get("/timestags").getGet(), openAPI, "get");
openAPI.getPaths().get("/timestags").getGet(), openAPI, "get", "/timestags");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
ReturnTypeDescriptorNode returnTypeNode = signature.returnTypeDesc().orElseThrow();
Assert.assertEquals(returnTypeNode.type().toString(), "string[][]|error");
Expand All @@ -168,7 +168,7 @@ public void getFunctionSignatureForStringArrayResponse() throws IOException, Bal
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/response_string_array.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(
openAPI.getPaths().get("/timestags").getGet(), openAPI, "get");
openAPI.getPaths().get("/timestags").getGet(), openAPI, "get", "/timestags");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
ReturnTypeDescriptorNode returnTypeNode = signature.returnTypeDesc().orElseThrow();
Assert.assertEquals(returnTypeNode.type().toString(), "string[]|error");
Expand All @@ -179,7 +179,7 @@ public void getFunctionSignatureForRequestBodyWithRef() throws IOException, Ball
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/request_body_with_ref.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(
openAPI.getPaths().get("/pets").getPost(), openAPI, "post");
openAPI.getPaths().get("/pets").getPost(), openAPI, "post", "/pets");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
SeparatedNodeList<ParameterNode> parameters = signature.parameters();
Assert.assertFalse(parameters.isEmpty());
Expand All @@ -193,7 +193,7 @@ public void getFunctionSignatureForUnsupportedRequests() throws IOException, Bal
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/pdf_payload.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(
openAPI.getPaths().get("/pets").getPost(), openAPI, "post");
openAPI.getPaths().get("/pets").getPost(), openAPI, "post", "/pets");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();
SeparatedNodeList<ParameterNode> parameters = signature.parameters();
Assert.assertFalse(parameters.isEmpty());
Expand All @@ -210,7 +210,7 @@ public void testNestedArrayQueryParamGeneration() throws IOException, BallerinaO
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/invalid_array_query_params.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(
openAPI.getPaths().get("/pets").getPost(), openAPI, "post");
openAPI.getPaths().get("/pets").getPost(), openAPI, "post", "/pets");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();

}
Expand All @@ -223,7 +223,7 @@ public void testArrayQueryParamWithNoTypeGeneration() throws IOException, Baller
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/invalid_array_query_params.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator functionSignatureGenerator = new RemoteFunctionSignatureGenerator(
openAPI.getPaths().get("/dogs").getGet(), openAPI, "get");
openAPI.getPaths().get("/dogs").getGet(), openAPI, "get", "/dogs");
FunctionSignatureNode signature = functionSignatureGenerator.generateFunctionSignature().get();

}
Expand All @@ -233,10 +233,10 @@ public void testNumericFunctionSignatureJSONPayload() throws IOException, Baller
OpenAPI openAPI = getOpenAPI(RESDIR.resolve("swagger/integer_request_payload.yaml"));
TypeHandler.createInstance(openAPI, false);
RemoteFunctionSignatureGenerator signature = new RemoteFunctionSignatureGenerator(openAPI.getPaths().
get("/pets").getPost(), openAPI, "post");
get("/pets").getPost(), openAPI, "post", "/pets");
FunctionSignatureNode petSignature = signature.generateFunctionSignature().get();
RemoteFunctionSignatureGenerator owSignature = new RemoteFunctionSignatureGenerator(openAPI.getPaths().
get("/owners").getPost(), openAPI, "post");
get("/owners").getPost(), openAPI, "post", "/owners");
FunctionSignatureNode ownerSignature = owSignature.generateFunctionSignature().get();
SeparatedNodeList<ParameterNode> parameters = petSignature.parameters();
Assert.assertFalse(parameters.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import io.ballerina.openapi.core.generators.common.GeneratorUtils;
import io.ballerina.openapi.core.generators.common.exception.BallerinaOpenApiException;
import io.ballerina.openapi.core.generators.common.model.Filter;
import io.ballerina.openapi.core.generators.document.ClientDocCommentGeneratorNew;
import io.ballerina.openapi.core.generators.document.ClientDocCommentGenerator;
import io.ballerina.openapi.core.generators.document.DocCommentsGeneratorUtil;
import io.ballerina.tools.text.TextDocument;
import io.ballerina.tools.text.TextDocuments;
Expand Down Expand Up @@ -198,7 +198,7 @@ public SyntaxTree generateSyntaxTree() throws BallerinaOpenApiException, ClientE
SyntaxTree syntaxTree = SyntaxTree.from(textDocument);
syntaxTree = syntaxTree.modifyWith(modulePartNode);
//Add comments
ClientDocCommentGeneratorNew clientDocCommentGenerator = new ClientDocCommentGeneratorNew(syntaxTree, openAPI,
ClientDocCommentGenerator clientDocCommentGenerator = new ClientDocCommentGenerator(syntaxTree, openAPI,
resourceMode);
return clientDocCommentGenerator.updateSyntaxTreeWithDocComments();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ private Optional<FunctionDefinitionNode> createImplFunction(String path,
Token functionKeyWord = createToken(FUNCTION_KEYWORD);
IdentifierToken functionName = createIdentifierToken(operation.getValue().getOperationId() + "Impl");
// Create function signature
ImplFunctionSignatureGeneratorNew signatureGenerator = new ImplFunctionSignatureGeneratorNew(clientExternFunction);
ImplFunctionSignatureGenerator signatureGenerator = new ImplFunctionSignatureGenerator(operation.getValue(),
openAPI, operation.getKey().toString().toLowerCase(Locale.ROOT), path, clientExternFunction);
//Create function body
FunctionBodyGeneratorImp functionBodyGenerator = new ImplFunctionBodyGenerator(path, operation, openAPI,
authConfigGeneratorImp, ballerinaUtilGenerator, imports);
authConfigGeneratorImp, ballerinaUtilGenerator, imports, signatureGenerator.hasHeaders(),
signatureGenerator.hasDefaultHeaders(), signatureGenerator.hasQueries());
FunctionBodyNode functionBodyNode;
Optional<FunctionBodyNode> functionBodyNodeResult = functionBodyGenerator.getFunctionBodyNode();
if (functionBodyNodeResult.isEmpty()) {
Expand Down
Loading

0 comments on commit 7e4eeef

Please sign in to comment.