Skip to content

Fix NullPointerException when diffing security schemes without components element #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private List<Pair<SecurityScheme.Type, SecurityScheme.In>> getListOfSecuritySche
return securityRequirement.keySet().stream()
.map(
x -> {
if (components == null) {
throw new IllegalArgumentException("Missing securitySchemes component definition.");
}
Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes();
if (securitySchemes == null) {
throw new IllegalArgumentException("Missing securitySchemes component definition.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SecurityDiffTest {
private final String OPENAPI_DOC2 = "security_diff_2.yaml";
private final String OPENAPI_DOC3 = "security_diff_3.yaml";
private final String OPENAPI_DOC4 = "security_diff_4.yaml";
private final String OPENAPI_DOC5 = "security_diff_5.yaml";

@Test
public void testDiffDifferent() {
Expand Down Expand Up @@ -94,4 +95,11 @@ public void testWithUnknownSecurityScheme() {
IllegalArgumentException.class,
() -> OpenApiCompare.fromLocations(OPENAPI_DOC4, OPENAPI_DOC4));
}

@Test
public void testMissingSecurityDefinition() {
assertThrows(
IllegalArgumentException.class,
() -> OpenApiCompare.fromLocations(OPENAPI_DOC5, OPENAPI_DOC5));
}
}
32 changes: 32 additions & 0 deletions core/src/test/resources/security_diff_5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
`special-key` to test the authorization filters.
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'

paths:
'/pet':
get:
summary: Deletes a pet
description: ''
operationId: qqq
security:
- test: []
responses:
'200':
description: Invalid ID supplied

# security components missing
components: {}