Skip to content

Commit d057528

Browse files
authored
Merge pull request #2049 from garydgregory/Issue2048
[Issue 2048] NullPointerException in SchemaProcessor.processArraySchema()
2 parents 00d2c5c + 25381a3 commit d057528

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public void processSchema(Schema schema) {
6565

6666
public void processSchemaType(Schema schema){
6767

68+
if (schema == null) {
69+
return;
70+
}
6871
if (schema instanceof ArraySchema) {
6972
processArraySchema((ArraySchema) schema);
7073
}
@@ -215,7 +218,7 @@ private void changeDiscriminatorMapping(ComposedSchema composedSchema, String ol
215218
public void processArraySchema(ArraySchema arraySchema) {
216219

217220
final Schema items = arraySchema.getItems();
218-
if (items.get$ref() != null) {
221+
if (items != null && items.get$ref() != null) {
219222
processReferenceSchema(items);
220223
}else{
221224
processSchemaType(items);

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,9 @@ public void copyVendorExtensions(Schema source, Schema target) {
735735
}
736736

737737
private boolean isObjectSchema(Schema schema) {
738+
if (schema == null) {
739+
return false;
740+
}
738741
return schema instanceof ObjectSchema
739742
|| "object".equalsIgnoreCase(schema.getType())
740743
|| (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty()

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,4 +1464,13 @@ private static int getDynamicPort() {
14641464
return new Random().ints(50000, 60000).findFirst().getAsInt();
14651465
}
14661466

1467+
@Test
1468+
public void testResolveArraySchemaItemsNullPointerException() {
1469+
final ParseOptions options = new ParseOptions();
1470+
options.setResolve(true);
1471+
final String actualLocation = "C:/Users/ggregory/git/r/api-gateway/ais-swagger-test-fixtures/src/test/resources/APIs-guru/openapi-directory-master/APIs/clearblade.com/3.0/swagger.yaml";
1472+
final OpenAPI output = new OpenAPIV3Parser().read(actualLocation, null, options);
1473+
new OpenAPIResolver(output, null, actualLocation).resolve();
1474+
}
1475+
14671476
}

0 commit comments

Comments
 (0)