Open fmaritato opened 4 years ago
@fmaritato I am not sure what you exactly want to do, but have you tried Schema Resolver in the Justify Examples? That example shows how to resolve external schemas and establish a link from the referencing schema to the referenced schema while loading the referencing schema.
@leadpony I want to take a json schema file, dereference all the $refs and rewrite the file with the actual type definitions inline. Hopefully this makes sense lol
The reason I want to do this is because I'd like to upload my schemas into confluent's schema registry, but it can't seem to resolve the $refs that point to definitions outside of the current file.
@fmaritato Thank you for quick response. I grasped your request. Sorry but there is no such feature in Justify. Your request is the same as Issue #6
My request is just for internal refs - I don't need to deference HTTP. Justify already did figure out internal references. This is really bad code I wrote to create a map that I could use to dereference the schema manually:
private Map<String, JsonValue> refs = new HashMap<>();
JsonSchema schema;
JsonObject schemaJson;
val service = JsonValidationService.newInstance();
val factory = service.createSchemaReaderFactoryBuilder().withDefaultSpecVersion(SpecVersion.DRAFT_07).withSpecVersionDetection(false).build();
try (val reader = factory.createSchemaReader(cdmPath)) {
schema = reader.read().asObjectJsonSchema();
schemaJson = Utilities.cast(schema.toJson());
// TODO: HACK HACK HACK
for (val ref : (Collection<?>) FieldUtils.readField(reader, "references", true)) {
SchemaReference schemaRef = Utilities.cast(FieldUtils.readField(ref, "reference", true));
refs.put(schemaRef.getTargetId().toString(), schemaRef.getReferencedSchema().asObjectJsonSchema().toJson());
}
}
is there a better way to dereference $ref using public APIs and not reflection?
In order to reuse certain definitions, I have many $refs in my schemas that point to definitions in a common.json file. Is there a way to use justify to resolve all these references and rewrite a version of the schema with all the resolutions?
So instead of
the rewritten schema file would have:
Thanks!