diff --git a/.travis.yml b/.travis.yml index 1455dce..e78b96a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,9 @@ node_js: branches: only: - master -before_install: - - git submodule update --init --recursive + - v1.0.0 + - v2.0.0 + - v3.0.0 script: - "npm run-script cover" - - "npm run-script lint" \ No newline at end of file + - "npm run-script lint" diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f2871..176ee31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,45 +1,7 @@ -### 1.0.0-rc.4 - -* Fixed issue related to [#18](https://github.com/krakenjs/swaggerize-express/issues/18) and [expressjs/body-parser#44](https://github.com/expressjs/body-parser/issues/44). - -### 1.0.0-rc.3 +### 1.0.0 * Fixed issue where generator failed with deeper `path`. - -### 1.0.0-rc.2 - * Improved tests generation. - -### 1.0.0-rc.1 - * __BREAKING CHANGE__: `options.docs` is `options.docspath` and defaults to `/`. - -### 0.1.0-alpha.6 - -* __BREAKING CHANGE__: Reverted to standard express handlers. -* Removed output validation. -* Middleware capability. - -### 0.1.0-alpha.5 - -* Better tests generator. -* Bug fixes. - -### 0.1.0-alpha.4 - -* Only one of `--handlers` or `--models` is necessary in generator, not both. -* Generator now has a `--tests` switch for generating tests. -* Output validation is opt-in via `outputValidation: true`. - -### 0.1.0-alpha.3 - -* `resourcePath` in swagger document is base `mountpath` for routes. -* Added support for path variables in `handlers` directory names. -* Path parameters are always required if defined. -* Fixed trailing commas in handler definitions created by generator. - -### 0.1.0-alpha.2 - -* Added generator for models and handlers stubs. -* Fixed a bug that was not allowing multiple operations under an API definition. -* Fixed bug caused by `res.send` deprecation. +* Better schema validation error output. +* Fixed issue related to [#18](https://github.com/krakenjs/swaggerize-express/issues/18) and [expressjs/body-parser#44](https://github.com/expressjs/body-parser/issues/44). diff --git a/README.md b/README.md index 36399a1..8d4c93f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - **Stability:** `stable` - **Changelog:** [https://github.com/krakenjs/swaggerize-express/blob/master/CHANGELOG.md](https://github.com/krakenjs/swaggerize-express/blob/master/CHANGELOG.md) -`swaggerize-express` is a "spec first" approach to building RESTful services with a [Swagger spec](https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md) +`swaggerize-express` is a "design first" approach to building RESTful services with a [Swagger spec](https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md) and Express. `swaggerize-express` provides the following features: @@ -16,13 +16,13 @@ and Express. - Input model validation. - Models and handlers stubs generator command (`swaggerize`). -### Why "Spec First" +### Why "Design First" There are already a number of modules that help build REST services with express and swagger. However, these modules tend to focus on building the documentation or specification as a side effect of writing the application business logic. -`swaggerize-express` begins with the service specification first. This facilitates writing services that +`swaggerize-express` begins with the service specification. This facilitates writing services that are easier to design, review, and test. ### Usage diff --git a/bin/lib/swaggerize.js b/bin/lib/swaggerize.js index 5f7b013..157efba 100644 --- a/bin/lib/swaggerize.js +++ b/bin/lib/swaggerize.js @@ -6,13 +6,22 @@ var fs = require('fs'), schema = require('swaggerize-builder/lib/schema'), create = require('./create'); -module.exports = function (options) { - var apiPath, modelsPath, handlersPath, testsPath, validation, api; +function usage() { + console.error('swaggerize --api [[--models ] | [--handlers ] | [--tests ]]'); + return 1; +} - function usage() { - console.error('swaggerize --api [[--models ] | [--handlers ] | [--tests ]]'); - return 1; +function printValidationErrors(error) { + console.error('%s (at %s)', error, error.dataPath || '/'); + if (error.subErrors) { + error.subErrors.forEach(function (subError) { + console.error('%s (at %s)', subError, subError.dataPath || '/'); + }); } +} + +module.exports = function (options) { + var apiPath, modelsPath, handlersPath, testsPath, validation, api; apiPath = options.api; modelsPath = options.models; @@ -33,12 +42,7 @@ module.exports = function (options) { validation = schema.validate(api); if (!validation.valid) { - console.error('%s (at %s)', validation.error, validation.error.dataPath); - if (validation.error.subErrors) { - validation.error.subErrors.forEach(function (subError) { - console.error('%s (at %s)', subError, subError.dataPath); - }); - } + printValidationErrors(validation.error); return 1; } diff --git a/lib/expressroutes.js b/lib/expressroutes.js index c2e2dff..bdfcfcc 100644 --- a/lib/expressroutes.js +++ b/lib/expressroutes.js @@ -45,15 +45,16 @@ function expressroutes(router, options) { case 'body': case 'form': value = req.body; - if (parameter.type === 'string') { - //If the type is string and we found an empty object, convert to empty string. - //This is a bug in express's body-parser: https://github.com/expressjs/body-parser/issues/44 - if (thing.isObject(value) && !Object.keys(value).length) { + //If the type is string and we found an empty object, convert to empty string. + //This is a bug in express's body-parser: https://github.com/expressjs/body-parser/issues/44 + if (parameter.type === 'string' && thing.isObject(value)) { + if (!Object.keys(value).length) { req.body = value = ''; - break; } - //Coerce to a string since that's the type we expect and Express magic's it for us. - req.body = value = JSON.stringify(value); + else { + //Coerce to a string since that's the type we expect and Express magic's it for us. + req.body = value = JSON.stringify(value); + } } } diff --git a/package.json b/package.json index 71c7384..d75a41e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "swaggerize-express", - "version": "1.0.0-rc.4", + "version": "1.0.0", "author": "Trevor Livingston ", - "description": "Spec-first REST services with Swagger and Express.", + "description": "Design-first REST services with Swagger and Express.", "keywords": [ "swagger", "swagger-node",