baucis-swagger2
Advanced tools
Comparing version 0.3.15 to 0.3.16
@@ -50,3 +50,3 @@ // This is a Controller mixin to add methods for generating Swagger data. | ||
} | ||
// TODO other errors (400, 403, etc. ) | ||
// Add other errors if needed: (400, 403, 412 etc. ) | ||
responses['404'] = { | ||
@@ -88,3 +88,3 @@ description: (isInstance) ? | ||
var isInstance = (mode === 'instance'); | ||
var resourceKey = utils.capitalize(resourceName); | ||
var resourceKey = utils.capitalize(resourceName); | ||
var res = { | ||
@@ -96,5 +96,5 @@ //consumes: ['application/json'], //if used overrides global definition | ||
}; | ||
if (res.parameters.length === 0) { | ||
delete(res.parameters); | ||
} | ||
if (res.parameters.length === 0) { | ||
delete(res.parameters); | ||
} | ||
var sec = buildSecurityFor(); | ||
@@ -104,4 +104,14 @@ if (sec) { | ||
} | ||
if (isInstance) { | ||
if ('get' === verb) { | ||
return buildBaseOperationInstance(verb, res, resourceKey, resourceName); | ||
} | ||
else { | ||
//collection | ||
return buildBaseOperationCollection(verb, res, resourceKey, pluralName); | ||
} | ||
} | ||
function buildBaseOperationInstance(verb, res, resourceKey, resourceName) { | ||
if ('get' === verb) { | ||
return buildOperationInfo(res, | ||
@@ -123,6 +133,6 @@ 'get' + resourceKey + 'ById', | ||
'Deletes an existing ' + resourceName + ' by its ID' + '.'); | ||
} | ||
} else { | ||
//collection | ||
if ('get' === verb) { | ||
} | ||
} | ||
function buildBaseOperationCollection(verb, res, resourceKey, pluralName) { | ||
if ('get' === verb) { | ||
return buildOperationInfo(res, | ||
@@ -144,5 +154,3 @@ 'query' + resourceKey, | ||
'Delete all ' + pluralName + ' matching the specified query.'); | ||
} | ||
} | ||
return res; | ||
} | ||
} | ||
@@ -161,14 +169,21 @@ | ||
if (!type) { return null; } | ||
if (type === String) { return 'string'; } | ||
if (type === Number) { return 'number'; } | ||
if (type === Date) { return 'string'; } | ||
if (type === Boolean) { return 'boolean'; } | ||
if (type === mongoose.Schema.Types.ObjectId) { return 'string'; } | ||
if (type === mongoose.Schema.Types.Oid) { return 'string'; } | ||
if (type === mongoose.Schema.Types.Array) { return 'array'; } | ||
if (Array.isArray(type) || type.name === "Array") { return 'array'; } | ||
if (type === Object) { return null;} | ||
if (type instanceof Object) { return null; } | ||
if (type === mongoose.Schema.Types.Mixed) { return null; } | ||
if (type === mongoose.Schema.Types.Buffer) { return null; } | ||
if (type === String || | ||
type === Date || | ||
type === mongoose.Schema.Types.ObjectId || | ||
type === mongoose.Schema.Types.Oid) { | ||
return 'string'; | ||
} | ||
if (type === mongoose.Schema.Types.Array || | ||
Array.isArray(type) || | ||
type.name === "Array") { | ||
return 'array'; | ||
} | ||
if (type === Object || | ||
type instanceof Object || | ||
type === mongoose.Schema.Types.Mixed || | ||
type === mongoose.Schema.Types.Buffer) { | ||
return null; | ||
} | ||
throw new Error('Unrecognized type: ' + type); | ||
@@ -178,5 +193,7 @@ } | ||
if (!type) { return null; } | ||
if (type === String) { return null; } | ||
if (type === Number) { return 'double'; } | ||
if (type === Date) { return 'date-time'; } | ||
/* | ||
if (type === String) { return null; } | ||
if (type === Boolean) { return null; } | ||
@@ -191,2 +208,3 @@ if (type === mongoose.Schema.Types.ObjectId) { return null; } | ||
if (type === mongoose.Schema.Types.Buffer) { return null; } | ||
*/ | ||
return null; | ||
@@ -203,3 +221,3 @@ } | ||
} | ||
// TODO is _id always included unless explicitly excluded? | ||
// _id always included unless explicitly excluded? | ||
@@ -275,13 +293,13 @@ // If it's excluded, skip this one. | ||
if (path.enumValues && path.enumValues.length > 0) { | ||
// TODO: property.allowableValues = { valueType: 'LIST', values: path.enumValues }; | ||
// Pending: property.allowableValues = { valueType: 'LIST', values: path.enumValues }; | ||
} | ||
// Set allowable values range if min or max is present | ||
if (!isNaN(path.options.min) || !isNaN(path.options.max)) { | ||
// TODO: property.allowableValues = { valueType: 'RANGE' }; | ||
// Pending: property.allowableValues = { valueType: 'RANGE' }; | ||
} | ||
if (!isNaN(path.options.min)) { | ||
// TODO: property.allowableValues.min = path.options.min; | ||
// Pending: property.allowableValues.min = path.options.min; | ||
} | ||
if (!isNaN(path.options.max)) { | ||
// TODO: property.allowableValues.max = path.options.max; | ||
// Pending: property.allowableValues.max = path.options.max; | ||
} | ||
@@ -318,4 +336,4 @@ */ | ||
function isArrayOfRefs(type) { | ||
return (type && type.length > 0 && type[0].ref && | ||
type[0].type && type[0].type.name === 'ObjectId'); | ||
return (type && type.length > 0 && type[0] && type[0].ref && | ||
type[0].type && type[0].type.name === 'ObjectId'); | ||
} | ||
@@ -322,0 +340,0 @@ function warnInvalidType(name, path) { |
{ | ||
"name": "baucis-swagger2", | ||
"version": "0.3.15", | ||
"version": "0.3.16", | ||
"description": "Generate customizable swagger version 2.0 definitions for your Baucis REST API.", | ||
@@ -46,3 +46,3 @@ "homepage": "https://github.com/icinetic/baucis-swagger2", | ||
"baucis": "~1.6.2", | ||
"codeclimate-test-reporter": "~0.1.1", | ||
"codeclimate-test-reporter": "^0.3.0", | ||
"expect.js": "~0.3.1", | ||
@@ -49,0 +49,0 @@ "express": "~4.13.3", |
@@ -122,3 +122,2 @@ //Module with helper functions for building Swagger parameters metadata | ||
function getParamDocument(isPost, controller) { | ||
// TODO post body can be single or array | ||
return { | ||
@@ -131,2 +130,4 @@ name: 'document', | ||
schema: { | ||
// Pending: post body in baucis can be single or array: Polymorphic: not able to express this overload in Swagger 2.0 | ||
// Document as single | ||
$ref: '#/definitions/' + utils.capitalize(controller.model().singular()), | ||
@@ -133,0 +134,0 @@ }, |
@@ -8,2 +8,3 @@ baucis-swagger2 | ||
[![Dependency Status](https://david-dm.org/icinetic/baucis-swagger2.svg)](https://david-dm.org/icinetic/baucis-swagger2) | ||
[![bitHound Overall Score](https://www.bithound.io/github/Icinetic/baucis-swagger2/badges/score.svg)](https://www.bithound.io/github/Icinetic/baucis-swagger2) | ||
[![npm version](https://badge.fury.io/js/baucis-swagger2.svg)](http://badge.fury.io/js/baucis-swagger2) | ||
@@ -10,0 +11,0 @@ |
@@ -438,3 +438,3 @@ var expect = require('expect.js'); | ||
}; | ||
fixtures.vegetable.controller.swagger2.definitions['BestVegetable'] = { | ||
fixtures.vegetable.controller.swagger2.definitions.BestVegetable = { | ||
required: [], | ||
@@ -498,3 +498,3 @@ properties: { | ||
expect(instanceResponses['200'].description).to.be('Sucessful response. Single resource.'); | ||
expect(instanceResponses['200'].schema['$ref']).to.be('#/definitions/Vegetable'); | ||
expect(instanceResponses['200'].schema.$ref).to.be('#/definitions/Vegetable'); | ||
expect(instanceResponses['default'].description).to.be('Unexpected error.'); | ||
@@ -501,0 +501,0 @@ expect(instanceResponses['default'].schema.type).to.be('string'); |
Sorry, the diff of this file is not supported yet
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
84812
1921
116