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
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: [email protected]
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: {}