diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7d7e31e..d34f6869 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.2.5] - 2025-12-31
+
+### Fixed
+ - OAR021 - ExludeParameterCheck
+
## [1.2.4] - 2025-12-15
### Fixed
diff --git a/pom.xml b/pom.xml
index 901af80f..e078c8c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.apiaddicts.apitools.dosonarapi
sonaropenapi-rules-community
- 1.2.4
+ 1.2.5
sonar-plugin
SonarQube OpenAPI Community Rules
@@ -27,6 +27,12 @@
aldo.torres.pe@cloudappi.net
Cloudappi
+
+ MH
+ Melsy Huamani
+ melsy.huamani.pe@cloudappi.net
+ Cloudappi
+
@@ -155,7 +161,7 @@
0.8.0
true
- ossrh
+ central
true
published
diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java
index f851b60d..e6057e7c 100644
--- a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java
+++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheck.java
@@ -70,6 +70,10 @@ public void visitNode(JsonNode node) {
String path = getPath(node);
+ if (endsWithPathParam(path)) {
+ return;
+ }
+
boolean hasParameter = hasParameterInNode(node);
if (shouldIncludePath(path) && !hasParameter) {
@@ -78,6 +82,14 @@ public void visitNode(JsonNode node) {
}
}
+ private boolean endsWithPathParam(String path) {
+ String[] segments = path.split("/");
+ if (segments.length == 0) return false;
+
+ String last = segments[segments.length - 1].trim();
+ return last.matches("^\\{[^}]+\\}$");
+ }
+
private boolean hasParameterInNode(JsonNode node) {
JsonNode parametersNode = node.get("parameters");
if (parametersNode != null) {
diff --git a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR022OrderbyParameterCheck.java b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR022OrderbyParameterCheck.java
index 673963c5..30924966 100644
--- a/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR022OrderbyParameterCheck.java
+++ b/src/main/java/apiaddicts/sonar/openapi/checks/parameters/OAR022OrderbyParameterCheck.java
@@ -129,7 +129,7 @@ private String getPath(JsonNode node) {
return pathBuilder.toString();
}
- private boolean isPathWithParameter(String path) {
+ private boolean endsWithPathParam(String path) {
String[] segments = path.split("/");
if (segments.length == 0) return false;
@@ -138,7 +138,7 @@ private boolean isPathWithParameter(String path) {
}
private boolean shouldIncludePath(String path) {
- if (isPathWithParameter(path)) {
+ if (endsWithPathParam(path)) {
return false;
}
diff --git a/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheckTest.java b/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheckTest.java
index 817b68ea..688a53f3 100644
--- a/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheckTest.java
+++ b/src/test/java/apiaddicts/sonar/openapi/checks/parameters/OAR021ExcludeParameterCheckTest.java
@@ -39,6 +39,11 @@ public void verifyInV2WithRef() {
verifyV2("with-ref");
}
+ @Test
+ public void verifyInV2PathEndingWithParam() {
+ verifyV3("with-param");
+ }
+
@Test
public void verifyInV3() {
verifyV3("plain");
@@ -59,6 +64,11 @@ public void verifyInV3WithRef() {
verifyV3("with-ref");
}
+ @Test
+ public void verifyInV3PathEndingWithParam() {
+ verifyV3("with-param");
+ }
+
@Override
public void verifyRule() {
assertRuleProperties("OAR021 - ExcludeParameter - the chosen parameter must be defined in this operation", RuleType.BUG, Severity.MINOR, tags("parameters"));
diff --git a/src/test/resources/checks/v2/parameters/OAR021/with-param.json b/src/test/resources/checks/v2/parameters/OAR021/with-param.json
new file mode 100644
index 00000000..799521d9
--- /dev/null
+++ b/src/test/resources/checks/v2/parameters/OAR021/with-param.json
@@ -0,0 +1,27 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "title": "Swagger Petstore",
+ "version": "1.0.0"
+ },
+ "paths": {
+ "/examples/{id}": {
+ "get": {
+ "responses": {
+ "200": {
+ "description": "OK"
+ }
+ }
+ }
+ },
+ "/examples/{id}/items/{id}": {
+ "get": {
+ "responses": {
+ "200": {
+ "description": "OK"
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/checks/v2/parameters/OAR021/with-param.yaml b/src/test/resources/checks/v2/parameters/OAR021/with-param.yaml
new file mode 100644
index 00000000..3f4a3407
--- /dev/null
+++ b/src/test/resources/checks/v2/parameters/OAR021/with-param.yaml
@@ -0,0 +1,15 @@
+swagger: "2.0"
+info:
+ title: Swagger Petstore
+ version: "1.0.0"
+paths:
+ /examples/{id}:
+ get:
+ responses:
+ 200:
+ description: OK
+ /examples/{id}/items/{id}:
+ get:
+ responses:
+ 200:
+ description: OK
diff --git a/src/test/resources/checks/v3/parameters/OAR021/with-param.json b/src/test/resources/checks/v3/parameters/OAR021/with-param.json
new file mode 100644
index 00000000..1097b436
--- /dev/null
+++ b/src/test/resources/checks/v3/parameters/OAR021/with-param.json
@@ -0,0 +1,27 @@
+{
+ "openapi": "3.0.0",
+ "info": {
+ "title": "Swagger Petstore",
+ "version": "1.0.0"
+ },
+ "paths": {
+ "/examples/{id}": {
+ "get": {
+ "responses": {
+ "200": {
+ "description": "OK"
+ }
+ }
+ }
+ },
+ "/examples/{id}/items/{id}": {
+ "get": {
+ "responses": {
+ "200": {
+ "description": "OK"
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/checks/v3/parameters/OAR021/with-param.yaml b/src/test/resources/checks/v3/parameters/OAR021/with-param.yaml
new file mode 100644
index 00000000..8b012753
--- /dev/null
+++ b/src/test/resources/checks/v3/parameters/OAR021/with-param.yaml
@@ -0,0 +1,15 @@
+openapi: 3.0.0
+info:
+ title: Swagger Petstore
+ version: 1.0.0
+paths:
+ /examples/{id}:
+ get:
+ responses:
+ '200':
+ description: OK
+ /examples/{id}/items/{id}:
+ get:
+ responses:
+ '200':
+ description: OK
\ No newline at end of file