Skip to content

Commit

Permalink
Merge pull request #1453 from r-sreesaran/issue-1419
Browse files Browse the repository at this point in the history
Fix for issue-1419
  • Loading branch information
gracekarina authored Nov 3, 2020
2 parents 91866d9 + 0a6bc80 commit 1f9130c
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,12 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
catch( ParseException e) {
result.invalidType( location, String.format( "enum=`%s`", e.getMessage()), schema.getFormat(), n);
}
} else {
} else if (n.isArray()) {
for (JsonNode n1 : (ArrayNode)n) {
schema.addEnumItemObject(String.valueOf(n1));
}
}
else {
result.invalidType(location, "enum", "value", n);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2617,4 +2617,21 @@ public void testDiscriminatorSeparateFileExternalMapping() throws Exception {
Assert.assertNotNull(cat);
}

@Test
public void testParser() {

OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(Boolean.TRUE);
final SwaggerParseResult result = parser.readLocation("src/test/resources/issue-1419.yaml", null, options);
System.out.println(result.getMessages());
Assert.assertNotNull(result);
ArraySchema schema = (ArraySchema) result.getOpenAPI().getComponents().getSchemas().get("Vehicle").getProperties().get("arrayG");
ArraySchema schema1 = (ArraySchema) schema.getItems();
ArrayList enum1 = (ArrayList) schema1.getEnum();

Assert.assertEquals(enum1.get(0),"[[1,2],[2,6]]");

}

}
158 changes: 158 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-1419.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"openapi": "3.0.0",
"servers": [{
"description": "Production environment",
"url": "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry"
},
{
"description": "Test environment",
"url": "https://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry"
}
],
"info": {
"contact": {
"email": "DvlaAPIAccess@dvla.gov.uk",
"name": "DVLA API Team",
"x-twitter": "GDSTeam"
},
"description": "Interface specification for the DVLA Vehicle Enquiry API",
"title": "Vehicle Enquiry",
"version": "1.1.0",
"x-apisguru-categories": [
"open_data"
],
"x-logo": {
"url": "https://api.apis.guru/v2/cache/logo/https_twitter.com_GDSTeam_profile_image.png"
},
"x-origin": [{
"format": "openapi",
"url": "https://developer-portal.driver-vehicle-licensing.api.gov.uk/apis/vehicle-enquiry-service/v1.1.0-vehicle-enquiry-service.json",
"version": "3.0"
}],
"x-preferred": true,
"x-providerName": "api.gov.uk",
"x-serviceName": "vehicle-enquiry"
},
"tags": [{
"name": "vehicle"
}],
"paths": {
"/v1/vehicles": {
"post": {
"description": "Returns vehicle details based on registration number",
"operationId": "getVehicleDetailsByRegistrationNumber",
"parameters": [{
"description": "Client Specific API Key",
"in": "header",
"name": "x-api-key",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Consumer Correlation ID",
"in": "header",
"name": "X-Correlation-Id",
"required": false,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Vehicle"
}
}
},
"description": "Registration number of the vehicle to find details for",
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {

}
},
"description": "Successful response"
},
"400": {

"description": "Bad Request"
}
},
"summary": "Get vehicle details by registration number",
"tags": [
"vehicle"
]
}
}
},
"components": {
"schemas": {

"Vehicle": {
"properties": {
"arrayA": {
"type": "array",
"items": {

}
},

"arrayG": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "integer",
"format": "int32",
"minimum": 12,
"maximum": 24,
"nullable": true,
"exclusiveMinimum": true,
"exclusiveMaximum": true,
"enum": [1, 2],
"default": 1

},
"enum": [
[
[
[1, 2],
[2, 6]
]
]
]
}
},
"arrayH": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "string",
"nullable": true,
"enum": ["1", "2"]

},
"enum": [
["1", "2"],
["3", "2"]
]
}





}
}
}
}
}
}

0 comments on commit 1f9130c

Please sign in to comment.