use of io.swagger.v3.oas.models.OpenAPI in project vertx-web by vert-x3.
the class OpenApi3Utils method replaceRef.
private static void replaceRef(ObjectNode n, ObjectNode root, OpenAPI oas) {
/**
* If a ref is found, the structure of the schema is circular. The oas parser don't solve circular refs.
* So I bundle the schema:
* 1. I update the ref field with a #/definitions/schema_name uri
* 2. If #/definitions/schema_name is empty, I solve it
*/
String oldRef = n.get("$ref").asText();
Matcher m = COMPONENTS_REFS_MATCHER.matcher(oldRef);
if (m.lookingAt()) {
String schemaName = m.group(1);
String newRef = m.replaceAll(COMPONENTS_REFS_SUBSTITUTION);
n.remove("$ref");
n.put("$ref", newRef);
if (!root.has("definitions") || !root.get("definitions").has(schemaName)) {
Schema s = oas.getComponents().getSchemas().get(schemaName);
ObjectNode schema = ObjectMapperFactory.createJson().convertValue(s, ObjectNode.class);
// We need to search inside for other refs
if (!root.has("definitions")) {
ObjectNode definitions = JsonNodeFactory.instance.objectNode();
definitions.set(schemaName, schema);
root.putObject("definitions");
} else {
((ObjectNode) root.get("definitions")).set(schemaName, schema);
}
walkAndSolve(schema, root, oas);
}
} else
throw new RuntimeException("Wrong ref! " + oldRef);
}
Aggregations