Skip to content

Commit

Permalink
Merge pull request #26 from tlivings/v1.0.0
Browse files Browse the repository at this point in the history
Prepare for release.
  • Loading branch information
tlivings committed Sep 12, 2014
2 parents bc49daf + b4e8319 commit 4a31243
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 67 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
- "npm run-script lint"
44 changes: 3 additions & 41 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
26 changes: 15 additions & 11 deletions bin/lib/swaggerize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <swagger document> [[--models <models dir>] | [--handlers <handlers dir>] | [--tests <tests dir>]]');
return 1;
}

function usage() {
console.error('swaggerize --api <swagger document> [[--models <models dir>] | [--handlers <handlers dir>] | [--tests <tests dir>]]');
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;
Expand All @@ -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;
}

Expand Down
15 changes: 8 additions & 7 deletions lib/expressroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "swaggerize-express",
"version": "1.0.0-rc.4",
"version": "1.0.0",
"author": "Trevor Livingston <[email protected]>",
"description": "Spec-first REST services with Swagger and Express.",
"description": "Design-first REST services with Swagger and Express.",
"keywords": [
"swagger",
"swagger-node",
Expand Down

0 comments on commit 4a31243

Please sign in to comment.