Open nbuffon opened 3 weeks ago
Et sinon pour nos histoires de ref inter schéma JSON:
You can create a JSON Schema file that defines objects (like a library of reusable definitions), and then reference those definitions from other JSON Schema files. This is commonly done using the $ref
keyword to refer to definitions within the same file or across different files.
Here's how it can be structured:
Primary Schema File (definitions.json): This file contains the shared object definitions.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Person": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name", "age"]
}
}
}
Other Schema File (schema_using_definitions.json): This file references the definitions from definitions.json
.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"author": { "$ref": "definitions.json#/definitions/Person" },
"title": { "type": "string" }
},
"required": ["author", "title"]
}
$ref
value "definitions.json#/definitions/Person"
points to the Person
definition in the definitions.json
file.This approach provides a modular setup where each schema can leverage shared definitions, making it more manageable and consistent across multiple schema files.
It is possible to reference schema definitions using URI but questions are: