@Override public SwaggerDeserializationResult readWithInfo(JsonNode node) { SwaggerDeserializer ser = new SwaggerDeserializer(); return ser.deserialize(node); }
private List<Operation> getAllOperationsInAPath(Path pathObj) { List<Operation> operations = new ArrayList<>(); addToOperationsList(operations, pathObj.getGet()); addToOperationsList(operations, pathObj.getPut()); addToOperationsList(operations, pathObj.getPost()); addToOperationsList(operations, pathObj.getPatch()); addToOperationsList(operations, pathObj.getDelete()); addToOperationsList(operations, pathObj.getOptions()); addToOperationsList(operations, pathObj.getHead()); return operations; }
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 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 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; }
String value = getString("swagger", on, true, location, result); swagger.setSwagger(value); ObjectNode obj = getObject("info", on, true, "", result); if(obj != null) { Info info = info(obj, "info", result); swagger.info(info); value = getString("host", on, false, location, result); swagger.setHost(value); value = getString("basePath", on, false, location, result); swagger.setBasePath(value); ArrayNode array = getArray("schemes", on, false, location, result); if(array != null) { it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".schemes", result); if (s != null) { Scheme scheme = Scheme.forValue(s); array = getArray("consumes", on, false, location, result); if(array != null) { it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".consumes", result);
return refModel(node, location, result); return allOfModel(node, location, result); String type = getString("type", node, false, location, result); Model m = new ModelImpl(); if("array".equals(type)) { ArrayModel am = new ArrayModel(); ObjectNode propertyNode = getObject("properties", node, false, location, result); Map<String, Property> properties = properties(propertyNode, location, result); am.setProperties(properties); ObjectNode itemsNode = getObject("items", node, false, location, result); Property items = property(itemsNode, location, result); if(items != null) { am.items(items); Integer maxItems = getInteger("maxItems", node, false, location, result); am.setMaxItems(maxItems); Integer minItems = getInteger("minItems", node, false, location, result); am.setMinItems(minItems); Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { am.setVendorExtension(key, extension(node.get(key))); value = getString("default", node, false, location, result);
if(ref != null) { if(ref.getNodeType().equals(JsonNodeType.STRING)) { return refParameter((TextNode) ref, location, result); String value = getString("in", obj, true, location, result); if(value != null) { String type = getString("type", obj, false, location, result); String format = getString("format", obj, false, location, result); AbstractSerializableParameter<?> sp = null; String paramType = getString("type", obj, true, location, result); Map<PropertyBuilder.PropertyId, Object> map = new LinkedHashMap<PropertyBuilder.PropertyId, Object>(); String defaultValue = parameterDefault(obj, paramType, location, result); map.put(DEFAULT, defaultValue); sp.setDefault(defaultValue); BigDecimal bd = getBigDecimal("maximum", obj, false, location, result); if(bd != null) { map.put(MAXIMUM, bd); Boolean bl = getBoolean("exclusiveMaximum", obj, false, location, result); if(bl != null) { map.put(EXCLUSIVE_MAXIMUM, bl); bd = getBigDecimal("minimum", obj, false, location, result); if(bd != null) { map.put(MINIMUM, bd);
ArrayNode array = getArray("tags", obj, false, location, result); List<String> tags = tagStrings(array, location, result); if(tags != null) { output.tags(tags); String value = getString("summary", obj, false, location, result); output.summary(value); value = getString("description", obj, false, location, result); output.description(value); ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result); ExternalDocs docs = externalDocs(externalDocs, location, result); output.setExternalDocs(docs); value = getString("operationId", obj, false, location, result, operationIDs); output.operationId(value); array = getArray("consumes", obj, false, location, result); if(array != null) { if (array.size() == 0) { while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".consumes", result); if (s != null) { output.consumes(s); array = getArray("produces", obj, false, location, result);
return pathRef((TextNode)ref, location, result); Set<String> keys = getKeys(on); for(String key : keys) { result.extra(location, key, on.get(key)); ArrayNode parameters = getArray("parameters", obj, false, location, result); path.setParameters(parameters(parameters, location, result)); ObjectNode on = getObject("get", obj, false, location, result); if(on != null) { Operation op = operation(on, location + "(get)", result); if(op != null) { path.setGet(op); on = getObject("put", obj, false, location, result); if(on != null) { Operation op = operation(on, location + "(put)", result); if(op != null) { path.setPut(op); on = getObject("post", obj, false, location, result); if(on != null) { Operation op = operation(on, location + "(post)", result); if(op != null) { path.setPost(op); on = getObject("head", obj, false, location, result); if(on != null) {
if(ref.getNodeType().equals(JsonNodeType.STRING)) { return refResponse((TextNode) ref, location, result); String value = getString("description", node, true, location, result); output.description(value); ObjectNode schema = getObject("schema", node, false, location, result); if(schema != null) { JsonNode schemaRef = schema.get("$ref"); ObjectNode headersNode = getObject("headers", node, false, location, result); if(headersNode != null) { ObjectNode examplesNode = getObject("examples", node, false, location, result); if(examplesNode != null) { Map<String, Object> examples = Json.mapper().convertValue(examplesNode, Json.mapper().getTypeFactory().constructMapType(Map.class, String.class, Object.class)); Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { output.setVendorExtension(key, extension(node.get(key)));
return refModel((ObjectNode)sub, location, result); for(JsonNode part : allOf) { if(part.getNodeType().equals(JsonNodeType.OBJECT)) { Model segment = definition((ObjectNode) part, location, result); if(segment != null) { model.getAllOf().add(segment); Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { model.setVendorExtension(key, extension(node.get(key))); String value = getString("title", node, false, location, result); model.setTitle(value); value = getString("description", node, false, location, result); model.setDescription(value);
Set<String> pathKeys = getKeys(obj); for(String pathName : pathKeys) { JsonNode pathValue = obj.get(pathName); } else { ObjectNode path = (ObjectNode) pathValue; Path pathObj = path(path, location + ".'" + pathName + "'", result); String[] eachPart = pathName.split("/"); for (String part : eachPart) { if (part.startsWith("{") && part.endsWith("}") && part.length() > 2) { String pathParam = part.substring(1, part.length() - 1); boolean definedInPathLevel = isPathParamDefined(pathParam, pathObj.getParameters()); if (definedInPathLevel) { continue; List<Operation> operationsInAPath = getAllOperationsInAPath(pathObj); 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;
SwaggerDeserializer ser = new SwaggerDeserializer(); result = (T) ser.definition((ObjectNode) tree, definitionPath.replace("/", "."), null); } else { result = DeserializationUtils.deserialize(tree, file, expectedType);
public Map<String, Model> definitions (ObjectNode node, String location, ParseResult result) { if(node == null) return null; Set<String> schemas = getKeys(node); Map<String, Model> output = new LinkedHashMap<String, Model>(); for(String schemaName : schemas) { JsonNode schema = node.get(schemaName); if(schema.getNodeType().equals(JsonNodeType.OBJECT)) { Model model = definition((ObjectNode) schema, location + "." + schemaName, result); if(model != null) { output.put(schemaName, model); } } else { result.invalidType(location, schemaName, "object", schema); } } return output; }
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; }
return null; } else { SwaggerDeserializationResult result = new SwaggerDeserializer().deserialize(rootNode);
String type = getString("type", node, true, location, result); if(type != null) { if(type.equals("basic")) { String position = getString("in", node, true, location, result); String name = getString("name", node, true, location, result); .name(name) .in(in); String description = getString("description", node, false, location, result); output.setDescription(description); Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { output.setVendorExtension(key, extension(node.get(key)));
node.set("info", info); node.set("paths", paths); SwaggerDeserializationResult result = new SwaggerDeserializer().deserialize(node); if (result.getMessages().isEmpty()) {