Skip to content
Open
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 @@ -1903,6 +1903,29 @@ public Integer getInteger(String key, ObjectNode node, boolean required, String
return value;
}

private Number getInteger32or64(String key, ObjectNode node, boolean required, String location, ParseResult result) {
Number value = null;
JsonNode v = node.get(key);
if (node == null || v == null) {
if (required) {
result.missing(location, key);
result.invalid();
}
} else if (v.getNodeType().equals(JsonNodeType.NUMBER)) {
if (v.isInt()) {
value = v.intValue();
}
JsonNode format = node.get("format");
if (format != null && format.asText().equals("int64") && v.isLong()) {
value = v.longValue();
}
} else if (!v.isValueNode()) {
result.invalidType(location, key, "integer", node);
}
return value;
}


public Map<String, Parameter> getParameters(ObjectNode obj, String location, ParseResult result,
boolean underComponents) {
if (obj == null) {
Expand Down Expand Up @@ -2312,7 +2335,7 @@ public Object getAnyType(String nodeKey, ObjectNode node, String location, Parse
return getString(nodeKey, node, false, location, result);
}
if (example.getNodeType().equals(JsonNodeType.NUMBER)) {
Integer integerExample = getInteger(nodeKey, node, false, location, result);
Number integerExample = getInteger32or64(nodeKey, node, false, location, result);
if (integerExample != null) {
return integerExample;
} else {
Expand Down Expand Up @@ -2973,7 +2996,7 @@ at the moment path passed as string (basePath) from upper components can be both
schema.setDefault(object);
}
} else if (schema.getType().equals("integer")) {
Integer number = getInteger("default", node, false, location, result);
Number number = getInteger32or64("default", node, false, location, result);
if (number != null) {
schema.setDefault(number);
}
Expand Down Expand Up @@ -3043,7 +3066,7 @@ protected void getCommonSchemaFields(ObjectNode node, String location, ParseResu
schema.setMinimum(bigDecimal);
}

Integer integer = getInteger("minLength", node, false, location, result);
Integer integer = getInteger("minLength", node, false, location, result);
if (integer != null) {
schema.setMinLength(integer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,21 @@ public void testOneOfExternalRefConflictName() {
}

@Test
public void int64ExampleWithoutOverflow() {
public void int64WithoutOverflow() {
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/int64example.yaml");
IntegerSchema date = ((IntegerSchema) openAPI.getPaths().get("/foo").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getProperties().get("date"));
Assert.assertEquals(date.getExample().toString(), "1516042231144");
Operation get = openAPI.getPaths().get("/foo").getGet();
IntegerSchema exampleProperty = ((IntegerSchema) get.getResponses().get("200").getContent().get("application/json").getSchema().getProperties().get("exampleProperty"));
Assert.assertEquals(exampleProperty.getExample().toString(), "1516042231144");

Parameter parameter = get.getParameters().get(0);
String maxLong = "9223372036854775807";
Assert.assertEquals(parameter.getExample().toString(), maxLong);

IntegerSchema parameterInt64 = ((IntegerSchema) parameter.getSchema());
Assert.assertEquals(parameterInt64.getExample().toString(), maxLong);
Assert.assertEquals(parameterInt64.getMinimum().toString(), maxLong);
Assert.assertEquals(parameterInt64.getMaximum().toString(), maxLong);
Assert.assertEquals(parameterInt64.getDefault().toString(), maxLong);
}

@Test
Expand Down
15 changes: 13 additions & 2 deletions modules/swagger-parser-v3/src/test/resources/int64example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ info:
paths:
/foo:
get:
parameters:
- in: query
name: int64
example: 9223372036854775807
schema:
type: integer
format: int64
default: 9223372036854775807
example: 9223372036854775807
minimum: 9223372036854775807
maximum: 9223372036854775807
responses:
'200':
description: OK
Expand All @@ -13,9 +24,9 @@ paths:
schema:
type: object
properties:
date:
exampleProperty:
type: integer
format: int64
example: 1516042231144
required:
- date
- exampleProperty