Skip to content

Commit

Permalink
Merge pull request #1612 from ballerina-platform/oas-gen-for-test-res…
Browse files Browse the repository at this point in the history
…ources-1.8.x

[1.8.x] Fix the error when generating OAS for services in `tests` with empty base path
  • Loading branch information
TharmiganK authored Feb 26, 2024
2 parents a8e69b7 + d2063ee commit e1cd619
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void perform(SyntaxNodeAnalysisContext context) {
*/
private String constructFileName(SyntaxTree syntaxTree, Map<Integer, String> services, Symbol serviceSymbol) {
String fileName = getNormalizedFileName(services.get(serviceSymbol.hashCode()));
String balFileName = syntaxTree.filePath().split("\\.")[0];
String balFileName = syntaxTree.filePath().replaceAll(SLASH, UNDERSCORE).split("\\.")[0];
if (fileName.equals(SLASH)) {
return balFileName + OPENAPI_SUFFIX + YAML_EXTENSION;
} else if (fileName.contains(HYPHEN) && fileName.split(HYPHEN)[0].equals(SLASH) || fileName.isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public void basePathWithUnicodeCharacter() throws IOException, InterruptedExcept
TEST_RESOURCE.resolve("project_9"), buildArgs);
Assert.assertTrue(Files.exists(RESOURCE.resolve("build/project_9/target/openapi/ชื่อ_openapi.yaml")));
}

@Test(description = "Empty base path service inside tests directory")
public void emptyBasePathServiceInTests() throws IOException, InterruptedException {
List<String> buildArgs = new LinkedList<>();
buildArgs.add("--export-openapi");
boolean successful = executeBuild(DISTRIBUTION_FILE_NAME,
TEST_RESOURCE.resolve("project_10"), buildArgs);
Assert.assertTrue(successful);
Assert.assertTrue(Files.exists(RESOURCE.resolve("build/project_10/target/openapi/" +
"main_openapi.yaml")));
Assert.assertTrue(Files.exists(RESOURCE.resolve("build/project_10/target/openapi/" +
"module_openapi.yaml")));
Assert.assertTrue(Files.exists(RESOURCE.resolve("build/project_10/target/openapi/" +
"tests_test_openapi.yaml")));
Assert.assertTrue(Files.exists(RESOURCE.resolve("build/project_10/target/openapi/" +
"tests_module_test_openapi.yaml")));
}


private void executeCommand(String resourcePath) throws IOException, InterruptedException {
List<String> buildArgs = new LinkedList<>();
boolean successful = executeBuild(DISTRIBUTION_FILE_NAME,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "openapi_extension_test"
name = "project_10"
version = "0.1.0"

[build-options]
observabilityIncluded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ballerina/http;

service / on new http:Listener(9090) {

resource function get path/test(string query) returns string {
return "Hello, " + query;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ballerina/http;

service / on new http:Listener(9090) {

resource function get path/test(string query) returns string {
return "Hello, " + query;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ballerina/http;

service / on new http:Listener(9090) {

resource function get path/test(string query) returns string {
return "Hello, " + query;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ballerina/http;

service / on new http:Listener(9090) {

resource function get path/test(string query) returns string {
return "Hello, " + query;
}
}

0 comments on commit e1cd619

Please sign in to comment.