|
1 | 1 | package apiaddicts.sonar.openapi.checks.format; |
2 | 2 |
|
| 3 | +import apiaddicts.sonar.openapi.checks.BaseCheck; |
3 | 4 | import com.google.common.collect.ImmutableSet; |
4 | 5 | import com.sonar.sslr.api.AstNodeType; |
5 | | -import org.sonar.check.Rule; |
6 | | -import org.apiaddicts.apitools.dosonarapi.api.v2.OpenApi2Grammar; |
7 | | -import org.apiaddicts.apitools.dosonarapi.api.v3.OpenApi3Grammar; |
8 | | -import org.apiaddicts.apitools.dosonarapi.api.v31.OpenApi31Grammar; |
9 | | -import apiaddicts.sonar.openapi.checks.BaseCheck; |
10 | | -import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode; |
11 | | - |
12 | 6 | import java.net.MalformedURLException; |
13 | 7 | import java.net.URL; |
14 | 8 | import java.util.List; |
15 | 9 | import java.util.Set; |
16 | 10 | import java.util.stream.Collectors; |
17 | 11 | import java.util.stream.Stream; |
| 12 | +import org.apiaddicts.apitools.dosonarapi.api.v2.OpenApi2Grammar; |
| 13 | +import org.apiaddicts.apitools.dosonarapi.api.v3.OpenApi3Grammar; |
| 14 | +import org.apiaddicts.apitools.dosonarapi.api.v31.OpenApi31Grammar; |
| 15 | +import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode; |
| 16 | +import org.sonar.check.Rule; |
| 17 | +import org.sonar.check.RuleProperty; |
18 | 18 |
|
19 | 19 | @Rule(key = OAR098LongBasePathCheck.KEY) |
20 | 20 | public class OAR098LongBasePathCheck extends BaseCheck { |
21 | 21 |
|
22 | 22 | public static final String KEY = "OAR098"; |
23 | 23 |
|
| 24 | + private static final int LONG_BASE_PATH = 2; |
| 25 | + |
| 26 | + @RuleProperty(key = "long-base-path", description = "long of the path in the basepath keywork value", defaultValue = "" + LONG_BASE_PATH ) |
| 27 | + private static int basePahtLength = LONG_BASE_PATH; |
| 28 | + |
24 | 29 | @Override |
25 | 30 | public Set<AstNodeType> subscribedKinds() { |
26 | 31 | return ImmutableSet.of(OpenApi2Grammar.ROOT, OpenApi3Grammar.SERVER, OpenApi31Grammar.SERVER); |
@@ -55,7 +60,7 @@ private void visitV3ServerNode(JsonNode node) { |
55 | 60 | private void validatePath(String path, JsonNode node) { |
56 | 61 | List<String> pathParts = Stream.of(path.split("/")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList()); |
57 | 62 |
|
58 | | - if (pathParts.size() > 2) { |
| 63 | + if (pathParts.size() > basePahtLength) { |
59 | 64 | addIssue(KEY, translate("OAR098.error-path-long"), node.value()); |
60 | 65 | } |
61 | 66 | } |
|
0 commit comments