-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
possible to rewrite a schema with no $ref? #49
Comments
@fmaritato |
@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 |
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!
The text was updated successfully, but these errors were encountered: