Comparing version 0.0.3 to 0.0.4
51
index.js
@@ -15,2 +15,3 @@ var express = require('express') | ||
exports.jsonBodyParser = jsonBodyParser; | ||
exports.joi = joi; | ||
@@ -221,2 +222,16 @@ function api(options, routes) { | ||
function minOrMax(swagger, joiType, index, minOrMax) { | ||
swagger.allowableValues = swagger.allowableValues || {}; | ||
swagger.allowableValues.valueType = "RANGE"; | ||
swagger.allowableValues[minOrMax] = joiType.__args[index][0]; | ||
} | ||
var converters = { | ||
"float": function(swagger) { swagger.dataType = "double"; }, | ||
"integer": function(swagger) { swagger.dataType = "int"; }, | ||
"date": function(swagger) { swagger.dataType = "Date"; }, | ||
"min": minOrMax, | ||
"max": minOrMax | ||
}; | ||
function convertJoiTypesToSwagger(schema) { | ||
@@ -227,12 +242,38 @@ var params = []; | ||
, swaggerParam = { | ||
paramType: joiType.notes || "query", | ||
paramType: (typeof joiType.notes == 'string' ? joiType.notes : "query"), | ||
name: param, | ||
description: joiType.description | ||
description: (typeof joiType.description == 'string' ? joiType.description : "") | ||
}; | ||
if (joiType.__checks.indexOf('integer') >= 0) { | ||
swaggerParam.dataType = "integer"; | ||
if (joiType.type === "String") { | ||
swaggerParam.dataType = "string"; | ||
} | ||
if (joiType.notes && joiType.notes === "path") { | ||
if (joiType.type === "Boolean") { | ||
swaggerParam.dataType = "boolean"; | ||
} | ||
joiType.__checks.forEach(function(check, index) { | ||
if (converters[check]) { | ||
converters[check](swaggerParam, joiType, index, check); | ||
} | ||
}); | ||
if (joiType.__valids._values.indexOf(undefined) > -1) { | ||
swaggerParam.required = false; | ||
} | ||
joiType.__valids._values.forEach(function(validValue) { | ||
if (validValue !== undefined) { | ||
swaggerParam.allowableValues = swaggerParam.allowableValues || {}; | ||
swaggerParam.allowableValues.valueType = "LIST"; | ||
swaggerParam.allowableValues.values = swaggerParam.allowableValues.values || []; | ||
swaggerParam.allowableValues.values.push(validValue); | ||
} | ||
}); | ||
swaggerParam.required = (joiType.__modifiers._values.indexOf("required") > -1); | ||
if (swaggerParam.paramType !== "query") { | ||
swaggerParam.required = true; | ||
@@ -239,0 +280,0 @@ swaggerParam.allowMultiple = false; |
{ | ||
"name": "flair-doc", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Swagger-compliant REST API documentation generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -228,3 +228,3 @@ var should = require('should') | ||
description: "pant id", | ||
dataType: "integer", | ||
dataType: "int", | ||
required: true, | ||
@@ -231,0 +231,0 @@ allowMultiple: false |
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
40297
7
1143