Skip to content

Commit 40d87c3

Browse files
Merge pull request #17 from oyeli/Issue-16
Issue-16: Fixing NPE during ComposedModel validation in InheritanceCh…
2 parents 7fd1868 + 13853f7 commit 40d87c3

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed

src/main/java/com/github/sylvainlaurent/maven/swaggervalidator/semantic/validator/definition/InheritanceChainPropertiesValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public void validate(RefModelWrapper refModelWrapper) {
6868
@Override
6969
public void validate(ComposedModelWrapper composedModelWrapper) {
7070
if (composedModelWrapper != root) {
71-
Map<String, Property> childProperties = composedModelWrapper.getChild().getProperties() != null ?
72-
composedModelWrapper.getChild().getProperties() :
73-
Collections.<String, Property>emptyMap();
71+
Map<String, Property> childProperties = composedModelWrapper.getChild()== null || composedModelWrapper.getChild().getProperties() == null ?
72+
Collections.<String, Property>emptyMap() :
73+
composedModelWrapper.getChild().getProperties();
7474
parentProperties.addAll(childProperties.keySet());
7575
}
7676

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path;
2+
3+
import static com.github.sylvainlaurent.maven.swaggervalidator.SemanticValidationServiceTest.RESOURCE_FOLDER;
4+
import static com.github.sylvainlaurent.maven.swaggervalidator.SemanticValidationServiceTest.readDoc;
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertFalse;
7+
import static org.junit.Assert.assertTrue;
8+
9+
import java.util.List;
10+
11+
import com.github.sylvainlaurent.maven.swaggervalidator.ValidatorJunitRunner;
12+
import com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.error.SemanticError;
13+
import com.github.sylvainlaurent.maven.swaggervalidator.service.SemanticValidationService;
14+
import io.swagger.parser.util.SwaggerDeserializationResult;
15+
import org.junit.Test;
16+
import org.junit.runner.RunWith;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
@RunWith(ValidatorJunitRunner.class)
21+
public class InheritanceChainPropertiesValidatorTest {
22+
23+
private static Logger logger = LoggerFactory.getLogger(InheritanceChainPropertiesValidatorTest.class);
24+
25+
@Test
26+
public void succeed_when_ancestor_has_no_properties() {
27+
SwaggerDeserializationResult swaggerResult = readDoc(
28+
RESOURCE_FOLDER + "inheritance-hierarchy-model-valid.yml");
29+
List<SemanticError> errors = new SemanticValidationService(swaggerResult.getSwagger()).validate();
30+
logger.info(errors.toString());
31+
32+
assertTrue(errors.isEmpty());
33+
}
34+
35+
}

src/test/java/com/github/sylvainlaurent/maven/swaggervalidator/semantic/validator/path/OperationParametersReferenceValidatorTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path;
22

3+
import com.github.sylvainlaurent.maven.swaggervalidator.ValidatorJunitRunner;
34
import com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.error.SemanticError;
45
import com.github.sylvainlaurent.maven.swaggervalidator.service.SemanticValidationService;
56
import io.swagger.parser.util.SwaggerDeserializationResult;
67
import org.junit.Test;
8+
import org.junit.runner.RunWith;
79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
911

@@ -15,6 +17,7 @@
1517
import static org.junit.Assert.assertFalse;
1618
import static org.junit.Assert.assertTrue;
1719

20+
@RunWith(ValidatorJunitRunner.class)
1821
public class OperationParametersReferenceValidatorTest {
1922

2023
private static Logger logger = LoggerFactory.getLogger(OperationParametersReferenceValidatorTest.class);

src/test/java/com/github/sylvainlaurent/maven/swaggervalidator/util/UtilTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Set;
44

5+
import com.github.sylvainlaurent.maven.swaggervalidator.ValidatorJunitRunner;
56
import org.junit.Assert;
67
import org.junit.Test;
78

@@ -12,7 +13,9 @@
1213
import com.github.sylvainlaurent.maven.swaggervalidator.util.validators.path.PathValidatorImpl;
1314
import com.github.sylvainlaurent.maven.swaggervalidator.util.validators.path.PathValidatorTemplateImpl;
1415
import com.github.sylvainlaurent.maven.swaggervalidator.util.validators.path.SwaggerPathValidatorImpl;
16+
import org.junit.runner.RunWith;
1517

18+
@RunWith(ValidatorJunitRunner.class)
1619
public class UtilTest {
1720

1821
private static final String MODEL_VALIDATORS_PACKAGE = "com.github.sylvainlaurent.maven.swaggervalidator.util.validators.model";
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
swagger: '2.0'
2+
info:
3+
title: Test API
4+
description: Test API
5+
version: "1.0.0"
6+
host: none
7+
schemes:
8+
- https
9+
basePath: /v1
10+
produces:
11+
- application/json
12+
paths:
13+
/products/{id}:
14+
get:
15+
parameters:
16+
- name: id
17+
in: path
18+
required: true
19+
type: string
20+
operationId: getProduct
21+
summary: test service
22+
responses:
23+
200:
24+
description: ok
25+
schema:
26+
$ref: '#/definitions/Product'
27+
28+
definitions:
29+
TypedProduct1:
30+
x-discriminator-value: productType1
31+
allOf:
32+
- $ref: '#/definitions/CatalogProduct'
33+
CatalogProduct:
34+
allOf:
35+
- $ref: '#/definitions/Product'
36+
Product:
37+
allOf:
38+
- $ref: '#/definitions/Entity'
39+
- type: object
40+
discriminator: productType
41+
required:
42+
- productType
43+
properties:
44+
productType:
45+
$ref: '#/definitions/ProductType'
46+
Entity:
47+
type: object
48+
properties:
49+
id:
50+
type: string
51+
ProductType:
52+
type: string
53+
enum:
54+
- productType1
55+
- productType2
56+
- productType3

0 commit comments

Comments
 (0)