result.invalidType(location + ".type", "type", "basic|apiKey|oauth2", node); result.extra(location, key, node.get(key));
public String getString(String key, ObjectNode node, boolean required, String location, ParseResult result, Set<String> uniqueValues) { 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()) { result.invalidType(location, key, "string", node); } else { value = v.asText(); if (uniqueValues != null && !uniqueValues.add(value)) { result.unique(location, "operationId"); result.invalid(); } } return value; }
JsonNode pathValue = obj.get(pathName); if(pathName.startsWith("x-")) { result.unsupported(location, pathName, pathValue); result.invalidType(location, pathName, "object", pathValue); } else { ObjectNode path = (ObjectNode) pathValue; for (Operation operation : operationsInAPath) { if (!isPathParamDefined(pathParam, operation.getParameters())) { result.warning(location + ".'" + pathName + "'"," Declared path parameter " + pathParam + " needs to be defined as a path parameter in path or operation level"); break;
result.invalidType(location, "$ref", "string", obj); return null; result.invalidType(location, "enum", "value", n); result.extra(location, key, obj.get(key)); result.extra(location, key, obj.get(key));
public Model definition(ObjectNode node, String location, ParseResult result) { if(result == null) { result = new ParseResult(); result.missing(location, "empty schema"); return null; result.invalidType(location, "enum", "value", n); result.invalidType(location, "properties", "object", propertyNode); result.invalidType(location, "required", "string", n); result.extra(location, key, node.get(key));
result.extra(location, key, node.get(key)); result.invalidType("", "", "object", node); result.invalid(); return null;
result.invalidType(location, "$ref", "object", sub); return null; result.invalidType(location, "allOf[" + pos + "]", "object", part); result.invalidType(location, "allOf", "array", allOf); result.extra(location, key, node.get(key));
result.invalidType(location, "$ref", "string", node); return null; output.responseSchema(schemaProp); } else { result.invalidType(location, "$ref", "string", node); result.extra(location, key, node.get(key));
public Info info(ObjectNode node, String location, ParseResult result) { if(node == null) return null; Info info = new Info(); String value = getString("title", node, true, location, result); info.title(value); value = getString("description", node, false, location, result); info.description(value); value = getString("termsOfService", node, false, location, result); info.termsOfService(value); ObjectNode obj = getObject("contact", node, false, "contact", result); Contact contact = contact(obj, location, result); info.contact(contact); obj = getObject("license", node, false, location, result); License license = license(obj, location, result); info.license(license); value = getString("version", node, false, location, result); info.version(value); // extra keys Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { info.setVendorExtension(key, extension(node.get(key))); } else if(!INFO_KEYS.contains(key)) { result.extra(location, key, node.get(key)); } } return info; }
public List<SecurityRequirement> securityRequirements(ArrayNode node, String location, ParseResult result) { if(node == null) return null; List<SecurityRequirement> output = new ArrayList<SecurityRequirement>(); for(JsonNode item : node) { SecurityRequirement security = new SecurityRequirement(); if(item.getNodeType().equals(JsonNodeType.OBJECT)) { ObjectNode on = (ObjectNode) item; Set<String> keys = getKeys(on); for (String key : keys) { List<String> scopes = new ArrayList<>(); ArrayNode obj = getArray(key, on, false, location + ".security", result); if (obj != null) { for (JsonNode n : obj) { if (n.getNodeType().equals(JsonNodeType.STRING)) { scopes.add(n.asText()); } else { result.invalidType(location, key, "string", n); } } } security.requirement(key, scopes); } } output.add(security); } return output; }
public Tag tag(ObjectNode node, String location, ParseResult result) { Tag tag = null; if(node != null) { tag = new Tag(); Set<String> keys = getKeys(node); String value = getString("name", node, true, location, result); tag.name(value); value = getString("description", node, false, location, result); tag.description(value); ObjectNode externalDocs = getObject("externalDocs", node, false, location, result); ExternalDocs docs = externalDocs(externalDocs, location + "externalDocs", result); tag.externalDocs(docs); // extra keys for(String key : keys) { if(key.startsWith("x-")) { tag.setVendorExtension(key, extension(node.get(key))); } else if(!TAG_KEYS.contains(key)) { result.extra(location + ".externalDocs", key, node.get(key)); } } } return tag; }
public ExternalDocs externalDocs(ObjectNode node, String location, ParseResult result) { ExternalDocs output = null; if(node != null) { output = new ExternalDocs(); Set<String> keys = getKeys(node); String value = getString("description", node, false, location, result); output.description(value); value = getString("url", node, true, location, result); output.url(value); // extra keys for(String key : keys) { if(key.startsWith("x-")) { output.setVendorExtension(key, extension(node.get(key))); } else if(!EXTERNAL_DOCS_KEYS.contains(key)) { result.extra(location + ".externalDocs", key, node.get(key)); } } } return output; }
public License license(ObjectNode node, String location, ParseResult result) { if(node == null) return null; License license = new License(); String value = getString("name", node, true, location, result); license.name(value); value = getString("url", node, false, location, result); license.url(value); // extra keys Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { license.setVendorExtension(key, extension(node.get(key))); } else if(!LICENSE_KEYS.contains(key)) { result.extra(location + ".license", key, node.get(key)); } } return license; }
public RefModel refModel(ObjectNode node, String location, ParseResult result) { RefModel output = new RefModel(); if(node.getNodeType().equals(JsonNodeType.OBJECT)) { String refValue = ((TextNode)node.get("$ref")).textValue(); output.set$ref(refValue); } else { result.invalidType(location, "$ref", "object", node); return null; } // extra keys Set<String> keys = getKeys(node); for(String key : keys) { if(!REF_MODEL_KEYS.contains(key)) { result.extra(location, key, node.get(key)); } } return output; }
public ObjectNode getObject(String key, ObjectNode node, boolean required, String location, ParseResult result) { JsonNode value = node.get(key); ObjectNode on = null; if(value == null) { if(required) { result.missing(location, key); result.invalid(); } } else if(!value.getNodeType().equals(JsonNodeType.OBJECT)) { result.invalidType(location, key, "object", value); if(required) { result.invalid(); } } else { on = (ObjectNode) value; } return on; }
public Boolean getBoolean(String key, ObjectNode node, boolean required, String location, ParseResult result) { Boolean 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.BOOLEAN)) { value = v.asBoolean(); } else if(v.getNodeType().equals(JsonNodeType.STRING)) { String stringValue = v.textValue(); return Boolean.parseBoolean(stringValue); } } return value; }
public Map<String, Property> properties(ObjectNode node, String location, ParseResult result) { if(node == null) { return null; } Map<String, Property> output = new LinkedHashMap<String, Property>(); Set<String> keys = getKeys(node); for(String propertyName : keys) { JsonNode propertyNode = node.get(propertyName); if(propertyNode.getNodeType().equals(JsonNodeType.OBJECT)) { Property property = property((ObjectNode)propertyNode, location, result); output.put(propertyName, property); } else { result.invalidType(location, propertyName, "object", propertyNode); } } return output; }
public Contact contact(ObjectNode node, String location, ParseResult result) { if(node == null) return null; Contact contact = new Contact(); String value = getString("name", node, false, location + ".name", result); contact.name(value); value = getString("url", node, false, location + ".url", result); contact.url(value); value = getString("email", node, false, location + ".email", result); contact.email(value); // extra keys Set<String> keys = getKeys(node); for(String key : keys) { if(!CONTACT_KEYS.contains(key)) { result.extra(location + ".contact", key, node.get(key)); } } return contact; }