Comparing version 0.0.8 to 0.0.9
var express = require('express') | ||
, flair = require('./index') | ||
, flair = require('./lib/index') | ||
, joi = require('joi') | ||
@@ -24,8 +24,9 @@ , flairui = require('flair-ui') | ||
//register our schema with flair | ||
flair.addContentType( | ||
"application/vnd.cheese+json", | ||
{ | ||
id: "cheese", | ||
type: "object", | ||
properties: { | ||
flair.addContentTypes([ | ||
{ | ||
type: "application/vnd.cheese+json", | ||
schema: { | ||
id: "cheese", | ||
type: "object", | ||
properties: { | ||
name: { | ||
@@ -36,24 +37,25 @@ description: "The name of the cheese", | ||
}, | ||
id: { | ||
description: "The id of the cheese", | ||
type: "integer", | ||
required: false //if a cheese has no id, we'll generate one | ||
id: { | ||
description: "The id of the cheese", | ||
type: "integer", | ||
required: false //if a cheese has no id, we'll generate one | ||
} | ||
}, | ||
//no null or undefined cheeses, thank you | ||
required: true | ||
} | ||
}, | ||
{ | ||
type: "application/vnd.cheese-list+json", | ||
schema: { | ||
id: "cheeseList", | ||
type: "Array", | ||
items: { | ||
//this reference will work in swagger, but not | ||
//real json-schema | ||
"$ref": "cheese" | ||
} | ||
}, | ||
//no null or undefined cheeses, thank you | ||
required: true | ||
} | ||
); | ||
flair.addContentType( | ||
"application/vnd.cheese-list+json", | ||
{ | ||
id: "cheeseList", | ||
type: "Array", | ||
items: { | ||
//this reference will work in swagger, but not | ||
//real json-schema | ||
"$ref": "cheese" | ||
} | ||
} | ||
); | ||
]); | ||
@@ -60,0 +62,0 @@ app.get( |
{ | ||
"name": "flair-doc", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Swagger-compliant REST API documentation generator", | ||
"main": "index.js", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "mocha" |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
/* jshint expr:true */ | ||
var should = require('should') | ||
@@ -5,3 +7,3 @@ , supertest = require('supertest') | ||
, joi = require('joi') | ||
, flair = require('../index') | ||
, flair = require('../lib/index') | ||
; | ||
@@ -19,7 +21,7 @@ | ||
it('should expect an express app to document', function() { | ||
(function() { flair.swagger(); }).should.throw(); | ||
(function() { flair.swagger(); }).should.throwError(); | ||
}); | ||
it('should expect an express app with routes', function() { | ||
(function() { flair.swagger(express()); }).should.throw(); | ||
(function() { flair.swagger(express()); }).should.throwError(); | ||
}); | ||
@@ -143,2 +145,3 @@ | ||
.end(function(err, res) { | ||
/* jshint maxstatements:15 */ | ||
if (err) done(err); | ||
@@ -259,4 +262,6 @@ res.body.apiVersion.should.equal("1.0"); | ||
res.body.apis[0].operations[0].errorResponses.should.have.length(1); | ||
res.body.apis[0].operations[0].errorResponses[0].code.should.equal(400); | ||
res.body.apis[0].operations[0].errorResponses[0].reason.should.equal('Invalid parameters specified'); | ||
res.body.apis[0].operations[0].errorResponses[0].should.eql({ | ||
code: 400, | ||
reason: 'Invalid parameters specified' | ||
}); | ||
done(err); | ||
@@ -412,3 +417,5 @@ }); | ||
res.body.apis[0].operations[0].errorResponses.should.have.length(1); | ||
res.body.apis[0].operations[0].errorResponses[0].should.eql({ code: 400, reason: 'Invalid content-type' }); | ||
res.body.apis[0].operations[0].errorResponses[0].should.eql( | ||
{ code: 400, reason: 'Invalid content-type' } | ||
); | ||
done(err); | ||
@@ -422,2 +429,3 @@ }); | ||
/* jshint maxstatements:15 */ | ||
flair.addContentType( | ||
@@ -498,3 +506,3 @@ "application/vnd.thing+json", | ||
it('should not specify the responseClass in the operation section of the api', function(done) { | ||
it('should not specify the responseClass in the operation', function(done) { | ||
supertest(flairedApp) | ||
@@ -501,0 +509,0 @@ .get('/api-doc/pants') |
@@ -0,3 +1,5 @@ | ||
"use strict"; | ||
/* jshint expr:true */ | ||
var should = require('should') | ||
, flair = require('../index') | ||
, flair = require('../lib/index') | ||
, joi = flair.joi | ||
@@ -35,7 +37,2 @@ ; | ||
//not entirely sure what to do here. | ||
//but I agree, in principle. | ||
//array-valued items maybe? | ||
it('should pick up multiple values'); | ||
describe('joi integers/longs', function() { | ||
@@ -60,4 +57,4 @@ var intValidator = flair.validate({ | ||
it('should pick up required and optional', function() { | ||
intValidator.params[0].required.should.be.true; | ||
intValidator.params[1].required.should.be.false; | ||
intValidator.params[0].required.should.equal(true); | ||
intValidator.params[1].required.should.equal(false); | ||
}); | ||
@@ -83,4 +80,4 @@ it('should pick up allowable values', function() { | ||
it('should pick up required and optional', function() { | ||
stringValidator.params[0].required.should.be.true; | ||
stringValidator.params[1].required.should.be.false; | ||
stringValidator.params[0].required.should.equal(true); | ||
stringValidator.params[1].required.should.equal(false); | ||
}); | ||
@@ -107,4 +104,4 @@ it('should pick up allowed values', function() { | ||
it('should pick up required and optional', function() { | ||
booleanValidator.params[0].required.should.be.false; | ||
booleanValidator.params[1].required.should.be.true; | ||
booleanValidator.params[0].required.should.equal(false); | ||
booleanValidator.params[1].required.should.equal(true); | ||
}); | ||
@@ -125,5 +122,5 @@ }); | ||
it('should pick up required and optional', function() { | ||
doubleValidator.params[0].required.should.be.true; | ||
doubleValidator.params[1].required.should.be.false; | ||
doubleValidator.params[2].required.should.be.false; | ||
doubleValidator.params[0].required.should.equal(true); | ||
doubleValidator.params[1].required.should.equal(false); | ||
doubleValidator.params[2].required.should.equal(false); | ||
}); | ||
@@ -155,8 +152,61 @@ it('should pick up min and max', function() { | ||
it('should pick up required and optional', function() { | ||
dateValidator.params[0].required.should.be.false; | ||
dateValidator.params[1].required.should.be.true; | ||
dateValidator.params[0].required.should.equal(false); | ||
dateValidator.params[1].required.should.equal(true); | ||
}); | ||
}); | ||
describe('Array', function() { | ||
var validate = flair.validate({ | ||
list: joi.types.Array(), | ||
another: joi.types.Array().description("more things").required(), | ||
onemore: joi.types.Array().includes(joi.types.Number().integer()), | ||
specificValues: joi.types.Array().includes( | ||
joi.types.String().valid('cheese', 'biscuits', 'lemons') | ||
), | ||
minMax: joi.types.Array().includes( | ||
joi.types.Number().integer().min(5).max(20) | ||
) | ||
}); | ||
it('should pick up multiple values with sensible defaults', function() { | ||
validate.params[0].should.eql({ | ||
dataType: "string", | ||
paramType: "query", | ||
name: "list", | ||
description: "", | ||
required: false, | ||
allowMultiple: true | ||
}); | ||
}); | ||
it('should pick up required', function() { | ||
validate.params[1].required.should.equal(true); | ||
validate.params[0].required.should.equal(false); | ||
}); | ||
it('should pick up description', function() { | ||
validate.params[1].description.should.equal('more things'); | ||
}); | ||
/* | ||
These two tests are pending, waiting for joi to handle Array | ||
constraints properly | ||
*/ | ||
it('should pick up the data type'/*, function() { | ||
validate.params[0].dataType.should.equal('string'); | ||
validate.params[1].dataType.should.equal('string'); | ||
validate.params[2].dataType.should.equal('int'); | ||
validate.params[3].dataType.should.equal('string'); | ||
}*/); | ||
it('should pick up allowableValues'/*, function() { | ||
validate.params[3].allowableValues.should.eql({ | ||
valueType: "LIST", | ||
values: [ 'cheese', 'biscuits', 'lemons' ] | ||
}); | ||
}*/); | ||
}); | ||
}); | ||
}); |
@@ -0,5 +1,6 @@ | ||
"use strict"; | ||
var should = require('should') | ||
, supertest = require('supertest') | ||
, express = require('express') | ||
, flair = require('../index') | ||
, flair = require('../lib/index') | ||
, joi = flair.joi; | ||
@@ -6,0 +7,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52538
16
1530