Skip to content

Commit 6db8d37

Browse files
AllT2709Aldo Torresadrian-palanques-cloudappi
authored
fix: support basePath with dots (#25)
* fix: support basePath with dots * fix: custom regex to kebab case on rule oar011 * fix: resolving v2 and v3 test * chore: format --------- Co-authored-by: Aldo Torres <[email protected]> Co-authored-by: Adrian Palanques <[email protected]>
1 parent b93af22 commit 6db8d37

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main/java/apiaddicts/sonar/openapi/checks/format/OAR011UrlNamingConventionCheck.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.collect.ImmutableSet;
44
import com.sonar.sslr.api.AstNodeType;
5+
56
import org.sonar.check.Rule;
67
import org.sonar.check.RuleProperty;
78
import org.apiaddicts.apitools.dosonarapi.api.v2.OpenApi2Grammar;
@@ -20,7 +21,8 @@ public class OAR011UrlNamingConventionCheck extends AbstractNamingConventionChec
2021
private static final String MESSAGE = "OAR011.error";
2122

2223
private static final String NAMING_CONVENTION = KEBAB_CASE;
23-
24+
private static final String KEBAB_SEGMENT ="^[a-z0-9-.]*$";
25+
2426
@RuleProperty(
2527
key = "naming-convention",
2628
description = "Naming convention (snake_case, kebab-case, camelCase or UpperCamelCase).",
@@ -84,4 +86,24 @@ private void visitPathNode(JsonNode node) {
8486
String path = node.key().getTokenValue();
8587
validateNamingConvention(path, node.key());
8688
}
89+
90+
@Override
91+
protected void validateNamingConvention(String name, JsonNode nameNode) {
92+
if (nameExceptions.contains(name)) return;
93+
if (KEBAB_CASE.equalsIgnoreCase(namingConvention)) {
94+
if (!isKebabCaseWithDots(name)) {
95+
addIssue(KEY, translate(MESSAGE, KEBAB_CASE), nameNode.key());
96+
}
97+
return;
98+
}
99+
super.validateNamingConvention(name, nameNode);
100+
}
101+
102+
private boolean isKebabCaseWithDots(String path) {
103+
if (path.contains("/")) {
104+
path = path.replaceAll("\\{[^}{]*}", "");
105+
}
106+
String transformed = path.replace("/", "-");
107+
return transformed.matches(KEBAB_SEGMENT);
108+
}
87109
}

0 commit comments

Comments
 (0)