From a95f95f751b96be6b9dc8eae84dcbb4ed6c3c32c Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 26 Dec 2013 11:15:55 -0800 Subject: [PATCH] Added some examples --- JSON-Schema.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/JSON-Schema.md b/JSON-Schema.md index b989ef9..4afb266 100644 --- a/JSON-Schema.md +++ b/JSON-Schema.md @@ -8,4 +8,67 @@ Probably one of the least known tools in our kit, but also one of the most centr * __Automated Population__. Schemas can specify how to resolve references from one document to another. So when loading everything required for a Level, all related Components, ThangTypes, and Articles are loaded as a matter of course by the SuperModel which utilizes the schemas to figure out how to get the data. * __Definition__. There is a universal place for data to be defined, which can be used by you, the Archmages, to see how a given document ought to be structured, and in the future for potential API clients to tap into our existing data structures. -It's important if you are working with data in any way on CodeCombat to understand how JSON-Schema relates to your work. Change to a schema affect every layer of the software stack. Look for further opportunities to use it to automate complex but repeated processes. \ No newline at end of file +It's important if you are working with data in any way on CodeCombat to understand how JSON-Schema relates to your work. Change to a schema affect every layer of the software stack. Look for further opportunities to use it to automate complex but repeated processes. + +## Why It's Awesome With [Treema](https://github.com/codecombat/treema) + +The schema returned by [http://codecombat.com/db/level_component/schema](http://codecombat.com/db/level_component/schema) is too long to include here, but basically it lets us generate a UI like this: + +![Treema for the LevelComponent schema](https://dl.dropboxusercontent.com/u/138899/GitHub%20Wikis/level_component_treema.png) + +See the "Configuration Schema" part toward the bottom? We can use the Treema GUI to generate another JSON Schema that then can be made into another Treema GUI which can let anyone configure anything with a GUI! + +## Examples + +Here's the schema returned by [http://codecombat.com/db/thang_component/schema](http://codecombat.com/db/thang_component/schema): + +```json +{ + "type": "object", + "additionalProperties": false, + "properties": { + "original": { + "type": [ + "object", + "string" + ], + "title": "Original", + "description": "A reference to the original Component being configured.", + "format": "hidden" + }, + "config": { + "type": "object", + "additionalProperties": true, + "properties": {}, + "title": "Configuration", + "description": "Component-specific configuration properties.", + "format": "thang-component-configuration" + }, + "majorVersion": { + "title": "Major Version", + "description": "Which major version of the Component is being used.", + "type": "integer", + "minimum": 0, + "default": 0, + "format": "hidden" + } + }, + "title": "Component", + "description": "Configuration for a Component that this Thang uses.", + "format": "thang-component", + "required": [ + "original", + "majorVersion" + ], + "default": { + "majorVersion": 0, + "config": {} + }, + "links": [ + { + "rel": "db", + "href": "/db/level.component/{(original)}/version/{(majorVersion)}" + } + ] +} +``` \ No newline at end of file