Skip to content

Commit 2c3f493

Browse files
Merge pull request #38 from apiaddicts/fix/21/oar98_rule
fix: rule 098 is parametrized
2 parents 195107e + 2f93a08 commit 2c3f493

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
package apiaddicts.sonar.openapi.checks.format;
22

3+
import apiaddicts.sonar.openapi.checks.BaseCheck;
34
import com.google.common.collect.ImmutableSet;
45
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-
126
import java.net.MalformedURLException;
137
import java.net.URL;
148
import java.util.List;
159
import java.util.Set;
1610
import java.util.stream.Collectors;
1711
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;
1818

1919
@Rule(key = OAR098LongBasePathCheck.KEY)
2020
public class OAR098LongBasePathCheck extends BaseCheck {
2121

2222
public static final String KEY = "OAR098";
2323

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+
2429
@Override
2530
public Set<AstNodeType> subscribedKinds() {
2631
return ImmutableSet.of(OpenApi2Grammar.ROOT, OpenApi3Grammar.SERVER, OpenApi31Grammar.SERVER);
@@ -55,7 +60,7 @@ private void visitV3ServerNode(JsonNode node) {
5560
private void validatePath(String path, JsonNode node) {
5661
List<String> pathParts = Stream.of(path.split("/")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
5762

58-
if (pathParts.size() > 2) {
63+
if (pathParts.size() > basePahtLength) {
5964
addIssue(KEY, translate("OAR098.error-path-long"), node.value());
6065
}
6166
}

src/test/java/org/sonar/samples/openapi/checks/format/OAR098LongBasePathCheckTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.sonar.samples.openapi.checks.format;
22

3+
import apiaddicts.sonar.openapi.checks.format.OAR098LongBasePathCheck;
34
import org.junit.Before;
45
import org.junit.Test;
56
import org.sonar.api.rule.Severity;
67
import org.sonar.api.rules.RuleType;
8+
import org.sonar.api.server.rule.RuleParamType;
79
import org.sonar.samples.openapi.BaseCheckTest;
810

9-
import apiaddicts.sonar.openapi.checks.format.OAR098LongBasePathCheck;
10-
1111
public class OAR098LongBasePathCheckTest extends BaseCheckTest {
1212

1313
@Before
@@ -45,6 +45,7 @@ public void verifyRule() {
4545

4646
@Override
4747
public void verifyParameters() {
48-
assertNumberOfParameters(0);
48+
assertNumberOfParameters(1);
49+
assertParameterProperties("long-base-path", "2", RuleParamType.INTEGER);
4950
}
5051
}

0 commit comments

Comments
 (0)