Skip to content

Commit f542eed

Browse files
author
Chris Wiechmann
committed
Fixed NPE
NPE when validating method with query parameters without providing the correct query parameter as part of the request
1 parent 061cab4 commit f542eed

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.6.3] 2022-07-05
8+
### Fixed
9+
- NPE when validating method with query parameters without providing the correct query parameter as part of the request
10+
711
## [1.6.2] 2022-06-30
812
### Fixed
913
- If a Content-Type header is set, it is used for validation and then removed, because it additionally exists in the http.content.headers attribute.

src/main/java/com/axway/apim/openapi/validator/OpenAPIValidator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public Collection<String> getQueryParameters() {
224224
public Collection<String> getQueryParameterValues(String name) {
225225
if(queryParams==null) return Collections.emptyList();
226226
ArrayList<String> values = queryParams.getHeaderValues(name);
227+
if(values == null) return Collections.emptyList();
227228
if(decodeQueryParams) {
228229
values.replaceAll(headerValue -> {
229230
try {

src/test/java/com/axway/apim/openapi/validator/TestOpenAPIValidator.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ public void validGetRequestPetsByStatusPetstoreSwagger20() throws IOException
8686
Assert.assertTrue(validator.isValidRequest(null, verb, path, queryParams, headers), "Request should be valid!");
8787
}
8888

89+
@Test
90+
public void invalidGetRequestPetsByStatusWithoutQueryParam() throws IOException
91+
{
92+
String swagger = Files.readFile(this.getClass().getClassLoader().getResourceAsStream(TEST_PACKAGE + "PetstoreSwagger2.0.json"));
93+
OpenAPIValidator validator = OpenAPIValidator.getInstance(swagger);
94+
95+
String path = "/pet/findByStatus";
96+
QueryStringHeaderSet queryParams = new QueryStringHeaderSet();
97+
String verb = "GET";
98+
HeaderSet headers = new HeaderSet();
99+
headers.addHeader("Content-Type", "application/json");
100+
101+
Assert.assertFalse(validator.isValidRequest(null, verb, path, queryParams, headers), "Request is invalid!");
102+
}
103+
89104
@Test
90105
public void validRequestWithFullPathAndPathParameter() throws IOException
91106
{

0 commit comments

Comments
 (0)