Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>sonaropenapi-rules-community</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube OpenAPI Community Rules</name>
Expand All @@ -27,6 +27,12 @@
<email>[email protected]</email>
<organization>Cloudappi</organization>
</developer>
<developer>
<id>MH</id>
<name>Melsy Huamani</name>
<email>[email protected]</email>
<organization>Cloudappi</organization>
</developer>
</developers>
<licenses>
<license>
Expand Down Expand Up @@ -155,7 +161,7 @@
<version>0.8.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>ossrh</publishingServerId>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
<waitUntil>published</waitUntil>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -138,7 +138,7 @@ private boolean isPathWithParameter(String path) {
}

private boolean shouldIncludePath(String path) {
if (isPathWithParameter(path)) {
if (endsWithPathParam(path)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public void verifyInV2WithRef() {
verifyV2("with-ref");
}

@Test
public void verifyInV2PathEndingWithParam() {
verifyV3("with-param");
}

@Test
public void verifyInV3() {
verifyV3("plain");
Expand All @@ -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"));
Expand Down
27 changes: 27 additions & 0 deletions src/test/resources/checks/v2/parameters/OAR021/with-param.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions src/test/resources/checks/v2/parameters/OAR021/with-param.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions src/test/resources/checks/v3/parameters/OAR021/with-param.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions src/test/resources/checks/v3/parameters/OAR021/with-param.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading