Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1c63cd1
Add JavaParser dependency for static analysis of Controller impls
RyanM-RMA Oct 29, 2025
e9934ef
Trying to do some static analysis of controller classes.
rma-rripken Oct 6, 2025
96abc89
Removing previous parser dependency
RyanM-RMA Oct 29, 2025
6c25a81
Adding a more generic and faster method for identifying classes under…
RyanM-RMA Oct 29, 2025
ed5a3bd
Refactor OpenApiTestHelperTest to separate Handler and CrudHandler te…
RyanM-RMA Oct 29, 2025
ffd9625
Refactor OpenApiTestHelper and related tests to use separated OpenApi…
RyanM-RMA Oct 29, 2025
694157c
Refactor OpenApiDocInfo and related classes to improve type handling,…
RyanM-RMA Oct 30, 2025
797bcef
Attempting to resolve build failure
RyanM-RMA Oct 30, 2025
04142d0
Refactor OpenApiTestHelper and OpenApiDocTest to introduce JavaParser…
RyanM-RMA Oct 30, 2025
17d3973
Refactor OpenApiDocInfo, OpenApiTestHelper, and related tests to intr…
RyanM-RMA Oct 31, 2025
7ecba1b
Added testing for ignored OpenApi methods, need to talk with Corps ab…
RyanM-RMA Nov 4, 2025
24712de
Introduce `OpenApiParamUsage` for enhanced parameter tracking, refact…
RyanM-RMA Nov 4, 2025
3d82e40
Refactor parameter handling in OpenApi classes: replace `Set` with `L…
RyanM-RMA Nov 6, 2025
6fe8888
Adding better handling for queryParamAsClass methods, resolving "?" p…
RyanM-RMA Nov 11, 2025
94ccd94
Update `OpenApiTestHelperTest` to assert parameters using `OpenApiPar…
RyanM-RMA Nov 11, 2025
f77144b
Adding symbol resolver to more simply resolve symbols in JavaParser
RyanM-RMA Nov 22, 2025
cac927d
Adding EnabledIfEnvironmentVariable to the OpenApiDocTest and adding …
RyanM-RMA Nov 24, 2025
9f9a70e
Update OpenApi test workflow to always publish JUnit reports regardle…
RyanM-RMA Nov 24, 2025
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
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ jobs:
annotate_only: true
include_passed: true
report_paths: '**/TEST-*.xml'
open-api-static-analysis:
name: OpenApi Static Analysis Tests
runs-on: ubuntu-latest
env:
OPEN_API_TEST: "true"
steps:
- name: checkout code
uses: actions/checkout@v5.0.0
- name: setup java
uses: actions/setup-java@v5.0.0
with:
distribution: 'temurin'
java-version: 11
cache: 'gradle'
- name: build and test
id: thebuild
run: ./gradlew :cwms-data-api:test --tests "cwms.cda.api.OpenApiDocTest" --info --init-script init.gradle
- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
if: always()
with:
annotate_only: true
include_passed: true
report_paths: '**/TEST-*.xml'
build-docker-image:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions cwms-data-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ dependencies {

// override versions
implementation(libs.bundles.overrides)

testImplementation(libs.bundles.java.parser)
}

task extractWebJars(type: Copy) {
Expand Down
523 changes: 523 additions & 0 deletions cwms-data-api/src/test/java/cwms/cda/api/OpenApiDocTest.java

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions cwms-data-api/src/test/java/helpers/OpenApiDocInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* MIT License
* Copyright (c) 2025 Hydrologic Engineering Center
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package helpers;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class OpenApiDocInfo {
private final Method method;
private final List<OpenApiParamInfo> queryParameters = new ArrayList<>();
private final List<OpenApiParamInfo> pathParameters = new ArrayList<>();
private final boolean ignored;

public OpenApiDocInfo(Method method, boolean ignored) {
this.method = method;
this.ignored = ignored;
}

public Method getMethod() {
return method;
}

public List<OpenApiParamInfo> getPathParameters() {
return pathParameters;
}

public List<OpenApiParamInfo> getQueryParameters() {
return queryParameters;
}

public boolean isIgnored() {
return ignored;
}

@Override
public String toString() {
String temp = ignored ? " - Ignored" : "";
return method.getName() + temp;
}
}
51 changes: 51 additions & 0 deletions cwms-data-api/src/test/java/helpers/OpenApiDocTestInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* MIT License
* Copyright (c) 2025 Hydrologic Engineering Center
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package helpers;

import java.lang.reflect.Method;
import java.util.List;
import java.util.stream.Collectors;

public class OpenApiDocTestInfo {
private final Class<?> clazz;
private final List<OpenApiDocInfo> methodDocs;

public OpenApiDocTestInfo(Class<?> clazz, List<OpenApiDocInfo> methodDocs) {
this.clazz = clazz;
this.methodDocs = methodDocs;
}

public List<OpenApiDocInfo> getMethodDocs() {
return methodDocs;
}

public Class<?> getClazz() {
return clazz;
}

@Override
public String toString() {
return clazz.getSimpleName() + ": " + methodDocs.stream()
.map(OpenApiDocInfo::getMethod)
.map(Method::getName)
.collect(Collectors.joining(", "));
}
}
73 changes: 73 additions & 0 deletions cwms-data-api/src/test/java/helpers/OpenApiParamInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* MIT License
* Copyright (c) 2025 Hydrologic Engineering Center
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package helpers;

import java.util.Objects;

public class OpenApiParamInfo {
private String name;
private final boolean required;
private final Class<?> type;

public OpenApiParamInfo(String name, boolean required, Class<?> type) {
this.name = name;
this.required = required;
this.type = type;
}

public OpenApiParamInfo setName(String name) {
this.name = name;
return this;
}

public String getName() {
return name;
}

public boolean isRequired() {
return required;
}

public Class<?> getType() {
return type;
}

@Override
public String toString() {
String req = required ? " (required)" : "";
String clazz = type != null ? type.getSimpleName() : "null";
return clazz + " " + name + req;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof OpenApiParamInfo)) {
return false;
}
OpenApiParamInfo that = (OpenApiParamInfo) o;
return Objects.equals(getName(), that.getName());
}

@Override
public int hashCode() {
return Objects.hashCode(getName());
}
}
65 changes: 65 additions & 0 deletions cwms-data-api/src/test/java/helpers/OpenApiParamUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* MIT License
* Copyright (c) 2025 Hydrologic Engineering Center
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package helpers;

import java.util.Objects;
import java.util.Set;

public class OpenApiParamUsage {
private final Set<OpenApiParamUsageInfo> queryParams;
private final Set<OpenApiParamUsageInfo> pathParams;
private final OpenApiParamUsageInfo resourceId;

public OpenApiParamUsage(Set<OpenApiParamUsageInfo> pathParams, Set<OpenApiParamUsageInfo> queryParams,
OpenApiParamUsageInfo resourceId) {
this.pathParams = pathParams;
this.queryParams = queryParams;
this.resourceId = resourceId;
}

public Set<OpenApiParamUsageInfo> getPathParams() {
return pathParams;
}

public Set<OpenApiParamUsageInfo> getQueryParams() {
return queryParams;
}

public OpenApiParamUsageInfo getResourceId() {
return resourceId;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof OpenApiParamUsage)) {
return false;
}
OpenApiParamUsage that = (OpenApiParamUsage) o;
return Objects.equals(getQueryParams(), that.getQueryParams()) && Objects.equals(getPathParams(),
that.getPathParams()) && Objects.equals(
getResourceId(), that.getResourceId());
}

@Override
public int hashCode() {
return Objects.hash(getQueryParams(), getPathParams(), getResourceId());
}
}
67 changes: 67 additions & 0 deletions cwms-data-api/src/test/java/helpers/OpenApiParamUsageInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* MIT License
* Copyright (c) 2025 Hydrologic Engineering Center
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package helpers;

import java.util.Objects;

public class OpenApiParamUsageInfo {
private final OpenApiParamInfo paramInfo;
private final boolean used;
private final boolean nullHandled;

public OpenApiParamUsageInfo(OpenApiParamInfo paramInfo, boolean used, boolean nullHandled) {
this.paramInfo = paramInfo;
this.used = used;
this.nullHandled = nullHandled;
}

public OpenApiParamInfo getParamInfo() {
return paramInfo;
}

public boolean isUsed() {
return used;
}

public boolean isNullHandled() {
return nullHandled;
}

@Override
public String toString() {
String realUse = used ? "In use" : "Not Used";
return paramInfo + " - " + realUse;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof OpenApiParamUsageInfo)) {
return false;
}
OpenApiParamUsageInfo that = (OpenApiParamUsageInfo) o;
return Objects.equals(getParamInfo(), that.getParamInfo());
}

@Override
public int hashCode() {
return Objects.hashCode(getParamInfo());
}
}
Loading
Loading