Orange-OpenSource / its-client

This Intelligent Transportation Systems (ITS) MQTT client based on the JSon ETSI specification transcription provides a ready to connect project for the mobility (connected and autonomous vehicles, road side units, vulnerable road users,...). Let's connect your device or application to our Intelligent Transport Systems (ITS) platform!
MIT License
7 stars 8 forks source link

Import schema element using URI reference #200

Open nbuffon opened 3 weeks ago

nbuffon commented 3 weeks ago

It is possible to reference schema definitions using URI but questions are:

nbuffon commented 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:

  1. 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"]
       }
     }
    }
  2. 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"]
    }

Referencing Details

This approach provides a modular setup where each schema can leverage shared definitions, making it more manageable and consistent across multiple schema files.