Comparing version
Baucis Change Log | ||
================= | ||
v0.8.0 | ||
------ | ||
More Swagger! | ||
Add custom API definitions to a controller with `controller.addSwaggerApi`. Other minor Swagger fixes. | ||
v0.7.0 | ||
@@ -5,0 +11,0 @@ ------ |
@@ -36,2 +36,5 @@ // This is a Controller mixin to add methods for generating Swagger data. | ||
// __Private Members__ | ||
var customApis = []; | ||
// __Public Members__ | ||
@@ -119,5 +122,5 @@ | ||
paramType: 'header', | ||
name: 'X-Baucis-Push', | ||
description: 'May be used with PUT to update the document using $push rather than $set', | ||
dataType: 'boolean', | ||
name: 'X-Baucis-Update-Operator', | ||
description: '**BYPASSES VALIDATION** May be used with PUT to update the document using $push, $pull, or $set.', | ||
dataType: 'string', | ||
required: false, | ||
@@ -147,2 +150,20 @@ allowMultiple: false | ||
}); | ||
parameters.push({ | ||
paramType: 'query', | ||
name: 'count', | ||
description: 'Set to true to return count instead of documents.', | ||
dataType: 'boolean', | ||
required: false, | ||
allowMultiple: false | ||
}); | ||
parameters.push({ | ||
paramType: 'query', | ||
name: 'conditions', | ||
description: 'Set the conditions used to find or remove the document(s).', | ||
dataType: 'string', | ||
required: false, | ||
allowMultiple: false | ||
}); | ||
} | ||
@@ -153,11 +174,2 @@ | ||
paramType: 'query', | ||
name: 'count', | ||
description: 'Set to true to return count instead of documents.', | ||
dataType: 'boolean', | ||
required: false, | ||
allowMultiple: false | ||
}); | ||
parameters.push({ | ||
paramType: 'query', | ||
name: 'select', | ||
@@ -181,11 +193,2 @@ description: 'Select which paths will be returned by the query.', | ||
paramType: 'query', | ||
name: 'conditions', | ||
description: 'Set the conditions used to find or remove the document(s).', | ||
dataType: 'string', | ||
required: false, | ||
allowMultiple: false | ||
}); | ||
parameters.push({ | ||
paramType: 'query', | ||
name: 'sort', | ||
@@ -227,2 +230,4 @@ description: 'Set the fields by which to sort.', | ||
// TODO other errors (400, 403, etc. ) | ||
// Error rosponses for singular operations | ||
@@ -287,2 +292,8 @@ if (!plural) { | ||
this.addSwaggerApi = function (api) { | ||
if (!api) throw new Error('Must provide an API definition.') | ||
customApis.push(api); | ||
return this; | ||
}; | ||
// A method used to generate a Swagger API definition for a controller | ||
@@ -301,4 +312,8 @@ this.generateApiDefinition = function (options) { | ||
// Model | ||
// TODO embedded models | ||
definition.models[modelName] = this.generateModelDefinition(); | ||
// Any custom routes | ||
customApis.forEach(definition.apis.push.bind(definition.apis)); | ||
// Instance route | ||
@@ -305,0 +320,0 @@ definition.apis.push({ |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/wprl/baucis", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "scripts": { |
@@ -1,3 +0,3 @@ | ||
baucis v0.6.29 | ||
============== | ||
baucis v0.8.0 | ||
============= | ||
@@ -240,2 +240,2 @@ Baucis is Express middleware that creates configurable REST APIs using Mongoose schemata. | ||
© 2012-2013 William P. Riley-Land | ||
© 2012-2014 William P. Riley-Land |
@@ -64,3 +64,3 @@ // __Dependencies__ | ||
controller = baucis.rest({ | ||
controller = fixture.controller = baucis.rest({ | ||
singular: 'vegetable', | ||
@@ -67,0 +67,0 @@ lastModified: 'lastModified', |
var expect = require('expect.js'); | ||
var mongoose = require('mongoose'); | ||
var express = require('express'); | ||
var passport = require('passport') | ||
var LocalStrategy = require('passport-local').Strategy; | ||
var request = require('request'); | ||
var baucis = require('..'); | ||
var parselinks = require('parse-links'); | ||
@@ -115,3 +110,30 @@ var fixtures = require('./fixtures'); | ||
it('should allow adding custom APIs', function (done) { | ||
fixtures.vegetable.controller.addSwaggerApi({ | ||
'path': '/vegetables/best', | ||
'description': 'Operations on the best vegetable.', | ||
'operations': [ | ||
{ | ||
'httpMethod': 'GET', | ||
'nickname': 'getBestVegetable', | ||
'responseClass': 'Vegetable', | ||
'summary': 'Get the best vegetable' | ||
} | ||
] | ||
}); | ||
var options = { | ||
url: 'http://127.0.0.1:8012/api/v1/api-docs/vegetables', | ||
json: true | ||
}; | ||
request.get(options, function (err, response, body) { | ||
if (err) return done(err); | ||
expect(response).to.have.property('statusCode', 200); | ||
expect(body.apis[0]).to.have.property('path', '/vegetables/best'); | ||
done(); | ||
}); | ||
}); | ||
it('should generate models correctly'); | ||
it('should generate embedded models correctly'); | ||
it('should generate documentation for each controller'); | ||
@@ -118,0 +140,0 @@ it('should keep paths deselected in the schema private'); |
609888
0.2%3512
0.89%