Skip to content

Instantly share code, notes, and snippets.

@Samsinite
Last active September 26, 2018 08:10
Show Gist options
  • Save Samsinite/d6c8aa56aed2b0c195413d92a8c40ce7 to your computer and use it in GitHub Desktop.
Save Samsinite/d6c8aa56aed2b0c195413d92a8c40ce7 to your computer and use it in GitHub Desktop.
Javascript API Annotation DSL
// app/instance-initializers/schema.js
import fetch from 'fetch'
import { loadSchema } from 'wildland-schema/ember-data';
import ENV from '../config/environment';
// load schema and store to report usage violations
export function initialize(applicationInstance) {
if (ENV.environment === 'development') {
const store = applicationInstance.lookup('service:store');
fetch('/api/v1/schema').then(response => response.json())
.then(jsonSchema => loadSchema(store, jsonSchema));
}
}
// models/baz.js
import DS from 'ember-data';
import Schema from 'wildland-schema/ember-data';
const Baz default DS.Model.extend({
foo: DS.belongsTo('foo'),
oldThing: DS.attr(),
thing: DS.attr(),
bar: DS.attr(),
});
export default Schema(Baz);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment