major update to latest yang-js/yang-express to now support hot-pluggable data models during runtime. also enable complete event-propagation for changes to the data models on a per-model basis. fixes #2 and #3. documentation updated to reflect initial support for openapi/swagger 2.0 specification auto-generation. near-complete support for websocket/socket.io will enable dynamic change push to the client application
diff --git a/README.md b/README.md
index 490c6f5..d555b27 100644
--- a/README.md
+++ b/README.md
@@ -26,12 +26,21 @@
```bash
$ npm start
-> yang-cord@1.0.1 start /home/peter/yang-cord
-> node lib/server.js
+> yang-cord@1.0.8 start /home/plee/hack/yang-cord
+> node lib/api/server.js
-mounted 'cord-core' model
-mounted 'xos-core' model
-[cord-core] calling GET on /cord-core:subscriber
+[yang-express] start of a new journey
+[openapi] enabling...
+[openapi] enabled ok
+[restjson] enabling...
+[restjson] enabled ok
+[websocket] enabling...
+[yang-express] registering a new link
+[yang-express] registered 'link:cord-core'
+[yang-express] registering a new link
+[yang-express] registered 'link:xos-core'
+[websocket] binding to server
+[websocket] enabled ok
```
_An option `--port` is provided to specify the port to listen on, it can be used with:_
diff --git a/package.json b/package.json
index 66e8fa1..8125046 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "yang-cord",
- "version": "1.0.7",
+ "version": "1.0.8",
"description": "YANG model-driven CORD",
"author": "Peter K. Lee <peter@corenova.com>",
"license": "Apache-2.0",
@@ -32,8 +32,8 @@
"minimist": "^1.2.0",
"node-uuid": "^1.4.7",
"superagent": "^2.0.0",
- "yang-express": "^0.2.9",
- "yang-js": "^0.15.5"
+ "yang-express": "^0.3.0",
+ "yang-js": "^0.15.7"
},
"optionalDependencies": {
"corenova": "^1.0.0"
@@ -43,13 +43,15 @@
"config": "^1.19.0",
"mocha": "~2.0.1",
"rimraf": "^2.5.2",
- "should": "~3.1.3"
+ "should": "~3.1.3",
+ "webpack": "^1.13.1"
},
"main": "./lib/cord-core.js",
"scripts": {
"clean": "rimraf dist/* lib/*",
"prebuild": "npm run clean -s && mkdir -p dist",
"build:src": "coffee -o lib -c src",
+ "build:web": "webpack -p",
"build": "npm run build:src",
"prepublish": "npm run build",
"pretest": "npm run build",
diff --git a/src/api/README.md b/src/api/README.md
index 4a6f405..3858028 100644
--- a/src/api/README.md
+++ b/src/api/README.md
@@ -18,7 +18,7 @@
[YANG-JSON](https://datatracker.ietf.org/doc/draft-ietf-netmod-yang-json)
specifications for representing configuration data in JSON.
-Below is the complete snippet from [server.coffee](./server.coffee)
+Below is the primary snippet from [server.coffee](./server.coffee)
demonstrating how to use
[yang-express](http://github.com/corenova/yang-express) middleware
framework to fire up a web server instance capable of serving up the
@@ -26,21 +26,16 @@
```coffeescript
yang = require('yang-js')
-argv = require('minimist')(process.argv.slice(2))
-
-app = require('yang-express') {
- models: [
- yang.require 'cord-core'
- yang.require 'xos-core'
- ]
- controllers: [
- 'restjson'
- 'socket-io'
- ]
- views: []
- data: require '../../sample-data.json'
-}
-app.run argv.port || 5050
+app = require('yang-express') ->
+ @set 'pkginfo', require('../../package.json')
+ @set 'initial state', require('../../sample-data.json')
+ @enable 'openapi', 'restjson', 'websocket'
+
+ cord = @link yang.require('cord-core')
+ xos = @link yang.require('xos-core')
+
+ cord.on 'update', (prop) ->
+ console.log "[#{prop.path}] got updated, should consider persisting the change somewhere"
```
Yep, it's really that simple.
@@ -54,6 +49,23 @@
point in time. Basically, it performs *adaptive* API routing and
rendering.
+### Open-API Specification (Swagger 2.0)
+
+Initial partial-support for dynamic **openapi** specification
+generation has been introduced with the latest
+[yang-express](http://github.com/corenova/yang-express) middleware
+framework. It can send back JSON or YAML based specification output
+depending on the requesting client's `Accept` header. It defaults to
+JSON output.
+
+You can give it a try by issuing one of the following:
+```bash
+$ curl localhost:5050/swagger.spec
+$ curl localhost:5050/swagger.spec -H 'accept: text/yaml'
+```
+
+We'll plan to fully support the **openapi** specification along the way.
+
### View Subscribers
Valid URIs:
diff --git a/src/api/server.coffee b/src/api/server.coffee
index 0d68b7d..e9dbd4e 100644
--- a/src/api/server.coffee
+++ b/src/api/server.coffee
@@ -8,20 +8,23 @@
#
yang = require('yang-js')
-argv = require('minimist')(process.argv.slice(2))
-app = require('yang-express') {
- models: [
- yang.require 'cord-core'
- yang.require 'xos-core'
- ]
- controllers: [
- 'restjson'
- 'socket-io'
- ]
- views: [
+app = require('yang-express') ->
+ @set 'pkginfo', require('../../package.json')
+ @set 'initial state', require('../../sample-data.json')
+ @enable 'openapi', 'restjson', 'websocket'
+
+ cord = @link yang.require('cord-core')
+ xos = @link yang.require('xos-core')
+
+ cord.on 'update', (prop) ->
+ console.log "[#{prop.path}] got updated, should consider persisting the change somewhere"
+
+module.exports = app
- ]
- data: require '../../sample-data.json'
-}
-app.run argv.port || 5050
+# only start if directly invoked
+if require.main is module
+ path = require('path')
+ argv = require('minimist')(process.argv.slice(2))
+ argv.port ?= 5050
+ app.listen argv.port
diff --git a/webpack.config.js b/webpack.config.js
new file mode 100644
index 0000000..92b0c18
--- /dev/null
+++ b/webpack.config.js
@@ -0,0 +1,5 @@
+var path = require('path');
+
+module.exports = {
+ entry: "./lib/client/entry.js"
+};