com.xliic.openapi.bundler.Mapping Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-bundler Show documentation
Show all versions of openapi-bundler Show documentation
Bundles multiple OpenAPI files (in JSON or YAML formats) using external references into one JSON file.
package com.xliic.openapi.bundler;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
public class Mapping {
Location value = null;
HashMap children = new HashMap<>();
public Location find(String pointer) throws UnsupportedEncodingException {
Mapping current = this;
JsonPath path = new JsonPointer(pointer).getJsonPath();
int i = 0;
for (; i < path.size() && current.children.containsKey(path.get(i)); i++) {
current = current.children.get(path.get(i));
}
Location value = current.value;
if (value == null) {
// mapping wasn't found
return null;
}
if (i < path.size()) {
JsonPath remaining = new JsonPath(path.subList(i, path.size()));
return new Location(value.file, value.pointer + remaining.toPointer());
}
return value;
}
public static class Location {
public final String file;
public final String pointer;
public Location(String file, JsonPointer pointer) {
this.file = file;
this.pointer = pointer.getValue();
}
public Location(String file, String pointer) {
this.file = file;
this.pointer = pointer;
}
}
}