Skip to content
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

$id field is not being preserved #327

Closed
snaum opened this issue Sep 5, 2019 · 2 comments
Closed

$id field is not being preserved #327

snaum opened this issue Sep 5, 2019 · 2 comments

Comments

@snaum
Copy link

snaum commented Sep 5, 2019

"$id" field in the schema is being converted to "id".
This is a side effect that is not expected and not documented.

IMO, schema.toString() should use the version to determine whether to print "id" or "$id"
Please see the below unit test to reproduce.

`

public void testPreserveID(){
final JSONObject validSchema1JSON = new JSONObject(validSchema1);
SchemaLoader loader = SchemaLoader.builder().schemaJson(validSchema1JSON).draftV7Support().build();
Schema schema = loader.load().build();

	JSONObject resultSchemaJSON = new JSONObject(schema.toString());
	JSONObject originalSchemaJSON = new JSONObject(validSchema1);

	assertEquals(originalSchemaJSON.get("$id"),resultSchemaJSON.get("id"));
} 

`

@erosb
Copy link
Contributor

erosb commented Sep 5, 2019

Hello @snaum currently the in-memory Schema objects don't track the draft version based on which they were created. I will think about options to overcome this. Thank you for reporting the problem.

erosb added a commit to erosb/everit-json-schema that referenced this issue Sep 18, 2019
added generic visitSchema() to `Visitor`, which is called by all visit* methods accepting any `Schema` instance
initial ToStringVisitor - moved BooleanSchema handling and started ArraySchema
made `SpecificationVersion` public so that ToStringVisitor can choose between `"id"` and `"$id"` - requested in everit-org#327
erosb added a commit to erosb/everit-json-schema that referenced this issue Sep 19, 2019
Fixing issue everit-org#327 (determining id/$id depending on schema spec version). The $schema value is preserved after parsing as an
unprocessedProperty so we use that. The deduced spec version is stored in a visitor field, so the first found $schema value
is considered as the spec version for the entire schema document.

Also:
 * printing common properties for EnumSchema
 * changing ToStringVisitor to use its own #printSchemaMap() because the previously used JSONPrinter#printSchemaMap() created
@erosb
Copy link
Contributor

erosb commented Sep 20, 2019

This is now fixed and released in version 1.12.0.

@erosb erosb closed this as completed Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants