Skip to content

Commit

Permalink
Merge pull request #1701 from lnash94/fixes
Browse files Browse the repository at this point in the history
[master]Fix doc comment override issue
  • Loading branch information
lnash94 authored May 1, 2024
2 parents 4063adb + cab232e commit b4f8b72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package io.ballerina.openapi.generators.common;

import io.ballerina.openapi.core.generators.common.GeneratorUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

public class DocCommenTests {
@Test()
public void testForFunctionReplaceContentWithinBrackets() {
// need ot improve regex to capture abc.json
// Assert.assertEquals("admin/api/ZZZ/customers/XXX/abc.json",
// todo : need ot improve regex to capture `.` in string ex: abc.json
// Assert.assertEquals("admin/api/ZZZ/customers/XXX/ZZZ",
// GeneratorUtils.replaceContentWithinBrackets("admin/api/2021-10/customers/{customer_id}/abc.json", "XXX"));
// Assert.assertEquals("admin/api/ZZZ/customers/XXX/abc.json",
// GeneratorUtils.replaceContentWithinBrackets(
// Assert.assertEquals("admin/api/ZZZ/customers/XXX/ZZZ",
// GeneratorUtils.replaceContentWithinBrackets(
// "admin/api/'2021\\-10/customers/[string customer_id]/abc\\.json", "XXX"));

Assert.assertEquals("/user/ssh_signing_keys/XXX", GeneratorUtils.replaceContentWithinBrackets(
"/user/ssh_signing_keys/{ssh_signing_key_id}", "XXX"));
Assert.assertEquals("/user/gpg_keys/XXX", GeneratorUtils.replaceContentWithinBrackets(
"/user/gpg_keys/{gpg_key_id}", "XXX"));

Assert.assertEquals(GeneratorUtils.replaceContentWithinBrackets("user/gpg_keys/[int gpg_key_id]",
"XXX"), "user/gpg_keys/XXX");
Assert.assertEquals(GeneratorUtils.replaceContentWithinBrackets(
"user/ssh_signing_keys/[int ssh_signing_key_id]", "XXX"),
"user/ssh_signing_keys/XXX");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -994,19 +994,26 @@ public static String replaceContentWithinBrackets(String input, String replaceme
input = sb.toString();
if (!input.startsWith(".")) {
//Pattern to ignore especial characters
//todo: need to improve the regex pattern to capture abc.json
Pattern pattern2 = Pattern.compile("/(?=[^/]*[^a-zA-Z0-9/])(.*?)(?=/)");
Pattern pattern2 = Pattern.compile("/(?=[^/]*[^a-zA-Z0-9_/])(.*?)(?=/)");
Matcher matcher2 = pattern2.matcher(input);
StringBuffer sb2 = new StringBuffer();
while (matcher2.find()) {
matcher2.appendReplacement(sb2, "/" + "ZZZ");
matcher2.appendReplacement(sb2, "/ZZZ");
}
matcher2.appendTail(sb2);
//todo: need to improve the regex pattern to capture abc.json
// input = sb2.toString();
// Pattern pattern3 = Pattern.compile("\\..*?[^/]*");
// Matcher matcher3 = pattern3.matcher(input);
// StringBuffer sb3 = new StringBuffer();
// while (matcher3.find()) {
// matcher3.appendReplacement(sb3, "/ZZZ");
// }
// matcher3.appendTail(sb3);
return sb2.toString();
} else {
return input;
}

}

public static TypeDescriptorNode generateStatusCodeTypeInclusionRecord(String code, ApiResponse response,
Expand Down

0 comments on commit b4f8b72

Please sign in to comment.