Frontend implementation of Json Schema
>$ git clone [email protected]:dmitriy.tselinko/adstream-json-schema.git
or
>$ npm install git+https://[email protected]/dmitriy.tselinko/adstream-json-schema.git --save
Insert that script into your application
<script type="text/javascript" src="<path-to-scripts>/adstream-json-schema/build/adstream-json-schema.angular.js"></script>
Inside your-module.js add dependency:
angular.module('my-module', [
'adstreamJsonSchema'
]);
Into your service:
angular.module('my-module')
.service("my-service",
[
'JsonSchema',
function(JsonSchema){
var params = {
schemaName: 'traffic',
filters: {
agency: "<agency-id>",
market: "<market-id>"
},
args: {
uid: "<uid>"
}
},
config = {
host: "http://10.20.30.40:3000",
decorate: {
Path: {
prefix: "some.prefix",
fieldsMap: {
"_cm.fieldA": "^fieldA.path", // some.prefix.fieldA.path
"_cm.fieldB": "fieldB", // fieldB
...
}
}
}
};
jsonSchema = new JsonSchema(params, config);
jsonSchema.ready(function(schema){
// Here you can work with schema
});
}
]
);
Test Express.js application.
var express = require('express'),
JsonSchema = require('adstream-json-schema'),
app = express();
app.get('/test-schema', function (req, res) {
var params = {
schemaName: 'traffic',
filters: {
agency: "<agency-id>",
market: "<market-id>"
},
args: {
uid: "<uid>"
}
},
jsonSchema = new JsonSchema(params, {
parseRoot: true,
host: "10.0.26.5:8080"
});
jsonSchema.ready(function(schema){
res.send(schema);
});
});
var server = app.listen(3000, function () {
console.log('Example app listening at http://%s:%s', server.address().address, server.address().port);
});
- improved error handling(it's critical for Node.js version, because it was difficult to debug errors earlier);
- implemented logger;
- implemented tests (used jasmine-node for it);
- supported parsing of fields with type 'array';
- implemented caching (and it's possible to clean it, if it's needed);
Basic implementation of schema parser .