WARNING: This is still very much a work in progress. It does not yet fully implement the JSON Schema spec and is missing many critical features. I am currently working directly against master so expect breaking changes at any moment.
ember-cli-json-schema
is provides a service that can load json schemas, create objects from schemas, and validate those objects. This addon will inject a schema
service into your routes that can be used to preform schema related operations. The purpose is to help form authors easily validate and display errors for data conforming to the json schema spec.
This add-on attempts to comply with the JSON Schema. As currently written, it does not support the full specification. It also lacks support for some "simple" schemas. Currently this means that your schema's root object must specify a type of array
or object
.
ember install:addon ember-cli-json-schema
Route:
var schema = {
title: "Person",
type: "object",
properties: {
"firstName": {
type: "string"
},
"lastName": {
type: "string"
},
"age": {
description: "Age in years",
type: "integer"
}
},
required: ["firstName", "lastName"]
}
export default Ember.Route.extend({
model: function(){
this.schema.load('Person', schema );
var model = this.schema.createObject('Person');
return model;
}
})
Handlebars Template:
schema.load(name, schema)
name - string - Name of the schmea to be loaded. You will reference this later to create an object schema - object - This is the schema itself
returns: null
schema.createObject(name)
name - string - Name of the schmea to be used to create the object
returns: schema object instance
schemaObject.errors
returns: array of errors on the current level of the schema object
schemaObject.childErrors
returns: array of errors on below the current level of the schema object
schemaObject.treeErrors
returns: array of errors on the current level or below of the schema object
schemaObject.isValid
returns: boolean. If no errors exist on the current level of the object
schemaObject.isTreeValid
returns: boolean. If no errors exist on or below the current level of the object
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.