Item:OSWf4a9514baed04859a4c6c374a7312f10: Difference between revisions

update from wiki-dev
(Update package: OSW Docs - Core)
(update from wiki-dev)
Tag: 2017 source edit
 
Line 126: Line 126:
==JSON-SCHEMA: Reference==
==JSON-SCHEMA: Reference==
How to define a JSON-SCHEMA?
How to define a JSON-SCHEMA?
*We want to levearge the power of typing and validation
*We want to leverage the power of typing and validation
*Therefore, our defined key(word):value pairs need to become JSON objects, specifying a type!
*Therefore, our defined key(word):value pairs need to become JSON objects, specifying a type!
*JSON (object) properties posses a keyword, which is used for reference
*JSON (object) properties posses a keyword, which is used for reference
Line 572: Line 572:
}
}
</syntaxhighlight>
</syntaxhighlight>
</div>
==JSON-SCHEMA: References and Pointers ==
JSON Pointers and References can be used to reuse schema definitions [https://json-schema.org/understanding-json-schema/structuring]
<div style="column-count: 3;">
<div style="break-inside: avoid;"> MyCommonSchema.json
<syntaxhighlight lang="json">
{
    "type": "object",
    "properties": {
        "text": { "type": "string" },
        "number": { "type": "number" },
        "array": { "type": "array" }
    }
}
</syntaxhighlight>
</div>
<div style="break-inside: avoid;"> MySchema.json
<syntaxhighlight lang="json">
{
    "type": "object",
    "allOf": {"$ref": "MyCommonSchema.json"},
    "$defs": {
        "name": { "type": "string" }
    },
    "properties": {
        "my_property": { "$ref": "#/$defs/name" }
    }
}
</syntaxhighlight>
</div>
<div style="break-inside: avoid;"> Result
<syntaxhighlight lang="json">
{
    "type": "object",
    "properties": {
        "text": { "type": "string" },
        "number": { "type": "number" },
        "array": { "type": "array" },
        "my_property": { "type": "string" }
    }
}
</syntaxhighlight>
</div>
</div>
</div>