Closed bard83 closed 4 years ago
Change inner-schema-definition.json as below, will save the content duplication.
{
"type": "object",
"allOf": [
{
"$ref": "global-schema-definition.json#/definitions/inner-schema-definition"
}
]
}
So I can continue use the previous approach:
var schema = JsonSchemaRegistry.Get($"file://{AppDomain.CurrentDomain.BaseDirectory}/Schemas/inner-schema-definition.json");
My question is still in place.
JsonSchemaRegistry
will only read a file as a whole. It's not going to navigate into the file to find some sub-content. This isn't a feature I'm going to add.
If this is really the way you want to go with it, You have a couple options:
JsonSchema.ResolveSubschema()
with the fragment as a JsonPointer
.JsonPointer
to find the part of the JsonValue
that you want and deserialize that.My suggestion is to go the route of your second comment where you store the subschema as a separate file and reference to it in the first. This is the typical "proper" approach.
Thanks for your reply and for your suggestions.
I'll proceed with my second comment. Also for me makes more sense and there is no reason for JsonSchemaRegistry
to dig into the schema to retrieve part of it.
I'll only invert the dependency. Currently inner-schema-definition.json
depends from global-schema-definition.json
. The other way around is more explicit, global-schema-definition.json
depends from inner-schema-definition.json
, because keeps concerns strictly separated and mostly it won't lead in to temptation to dig into the schemas.
{
"$id": "myurl/global-schema-definition.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["a", "b", "c"],
"properties": {
"a": {
"$ref": "inner-schema-definition.json#/definitions/inner-schema-definition"
},
// followed by definition of b and c
}
}
{
"$id": "myurl/inner-schema-definition.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"inner-schema-definition": {
"$id": "inner-schema-definition",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
// definition of the schema
}
},
"type": "object",
"allOf": [
{
"$ref": "#/definitions/inner-schema-definition"
}
]
}
var schema = JsonSchemaRegistry.Get($"file://{AppDomain.CurrentDomain.BaseDirectory}/Schemas/inner-schema-definition.json");
Thanks. Best Sante
Hi, I'm facing the current scenario, I have a schema file (global-schema-definition.json) that defines under
definitions
another schema, identified by the$id
inner-schema-definition. Below its pseudo definition:I have a second schema file (inner-schema-definition.json) that repeat the content of
definitions/inner-schema-definition
In the application there are two kinds of validator one for
global-schema-definition
(ValidatorGD) and another one forinner-schema-definition
(ValidatorID). I would like to drop the file inner-schema-definition.json in order to point directly to global-schema-definition.json#definitions/inner-schema-definition. Here how the `inner-schema-definition schema is readHere how I'd like to read it
The second case reads the entire content of
global-schema-definition.json
ignoring the#/definitions/inner-schema-definition
part. Obviouslyinner-schema-definition
objects are invalid when they are validated againstschema
.What I'm trying to do is supported by
JsonSchemaRegistry
?