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 @@ -1153,27 +1153,32 @@ public ExternalDocumentation getExternalDocs(ObjectNode node, String location, P

public String getString(String key, ObjectNode node, boolean required, String location, ParseResult
result, Set<String> uniqueValues, boolean noInvalidError) {
String value = null;
JsonNode v = node.get(key);
if (node == null || v == null) {
if (required) {
result.missing(location, key);
result.invalid();
}
} else if (!v.isValueNode()) {
if (!noInvalidError) {
result.invalidType(location, key, "string", node);
}
} else if (!v.isNull()) {
value = v.asText();
if (uniqueValues != null && !uniqueValues.add(value)) {
result.unique(location, "operationId");
result.invalid();
}
}
return value;
return getString(key, node, required, location, result, uniqueValues, noInvalidError, false);
}

public String getString(String key, ObjectNode node, boolean required, String location, ParseResult
result, Set<String> uniqueValues, boolean noInvalidError, boolean missingForNullNode) {
String value = null;
JsonNode v = node.get(key);
if (node == null || v == null || (v.isNull() && missingForNullNode)) {
if (required) {
result.missing(location, key);
result.invalid();
}
} else if (!v.isValueNode()) {
if (!noInvalidError) {
result.invalidType(location, key, "string", node);
}
} else if (!v.isNull()) {
value = v.asText();
if (uniqueValues != null && !uniqueValues.add(value)) {
result.unique(location, "operationId");
result.invalid();
}
}
return value;
}

public String getString(String key, ObjectNode node, boolean required, String location, ParseResult
result, Set<String> uniqueValues) {
return getString(key, node, required, location, result, uniqueValues, false);
Expand Down Expand Up @@ -1289,7 +1294,7 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) {
info.setLicense(license);
}

value = getString("version", node, true, location, result);
value = getString("version", node, true, location, result, null, false, true);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
info.setVersion(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3421,4 +3421,12 @@ public void testStyleAndExplodeExplicit(){
assertEquals(openAPI.getPaths().get("/test").getPost().getRequestBody().getContent().get("multipart/form-data").getEncoding().get("fileWithout").getStyle().toString(), "form");
assertNull(openAPI.getPaths().get("/test").getPost().getRequestBody().getContent().get("multipart/form-data").getEncoding().get("fileWithout").getExplode());
}

@Test(description = "null version should cause a message")
public void testVersion(){
ParseOptions options = new ParseOptions();
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
SwaggerParseResult parseResult = openApiParser.readLocation("version-missing.yaml", null, options);
assertEquals(parseResult.getMessages().get(0), "attribute info.version is missing");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
openapi: 3.0.3
info:
title: Example API with Style and Explode
version:
paths: {}
Loading