diff --git a/.gitignore b/.gitignore
index 42ff7ce9..2d6664e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,47 +1,32 @@
-# Compiled source #
-###################
-*.com
-*.class
-*.dll
-*.exe
-*.o
-*.so
-
-# Packages #
-############
-# it's better to unpack these files and commit the raw source
-# git has its own built in compression methods
-*.7z
-*.dmg
-*.gz
-*.iso
-*.jar
-*.rar
-*.tar
-*.zip
-
-# Logs and databases #
-######################
-*.log
-*.sql
-*.sqlite
-
-# OS generated files #
-######################
-.DS_Store
-.DS_Store?
-._*
-.Spotlight-V100
-.Trashes
-Icon?
-ehthumbs.db
-Thumbs.db
-
-# Project Specific #
-####################
-node_modules/
-
-# IDE #
-#######
-*.iml
+# IDE files
.idea
+.vscode
+
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# Commenting this out is preferred by some people, see
+# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
+node_modules
+
+# Users Environment Variables
+.lock-wscript
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 52cf6368..00000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "swagger-ui"]
- path = swagger-ui
- url = https://github.com/wordnik/swagger-ui.git
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 00000000..e21f1655
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,24 @@
+{
+ "bitwise":true,
+ "curly":true,
+ "eqeqeq":true,
+ "forin":true,
+ "newcap":true,
+ "noarg":true,
+ "noempty":true,
+ "nonew":true,
+ "undef":true,
+ "strict":true,
+ "node":true,
+ "indent":2,
+ "expr":true,
+ "globals" : {
+ /* MOCHA */
+ "describe" : false,
+ "it" : false,
+ "before" : false,
+ "beforeEach" : false,
+ "after" : false,
+ "afterEach" : false
+ }
+}
diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index c5316eeb..00000000
--- a/.npmignore
+++ /dev/null
@@ -1,4 +0,0 @@
-sample-application/
-swagger-ui-*/
-.gitmodules
-*-project
diff --git a/.travis.yml b/.travis.yml
index 20fd86b6..86850598 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,5 @@
language: node_js
node_js:
- - 0.10
+ - "stable"
+ - "4"
+sudo: false
diff --git a/LICENSE b/LICENSE
index 9f93e067..01abb442 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,11 +1,201 @@
-Copyright 2014 Reverb Technologies, Inc.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2020 SmartBear Software Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
index 222e6ca8..f6b98835 100644
--- a/README.md
+++ b/README.md
@@ -1,236 +1,118 @@
-# Swagger for Express and Node.js
+# Archived
-[](https://travis-ci.org/wordnik/swagger-node-express)
+This GitHub repository has been archived.
+The npmjs package `swagger` may be re-used at a later date for a different project.
+https://swagger.io/ may have similar or alternative functionality if you depend(ed) on this project.
-This is a [Swagger](https://github.com/wordnik/swagger-spec) module for the [Express](http://expressjs.com) web application framework for Node.js.
-Try a sample! The source for a [functional sample](https://github.com/wordnik/swagger-node-express/blob/master/SAMPLE.md) is available on github.
+[](https://travis-ci.org/swagger-api/swagger-node)
+[](http://badge.fury.io/js/swagger)
+[](https://david-dm.org/swagger-api/swagger-node)
+[](https://david-dm.org/swagger-api/swagger-node#info=devDependencies)
-## What's Swagger?
-The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swager removes the guesswork in calling the service.
+The `swagger` module provides tools for designing and building Swagger-compliant APIs entirely in Node.js. It integrates with popular Node.js servers, including Express, Hapi, Restify, and Sails, as well as any Connect-based middleware. With `swagger`, you can specify, build, and test your API from the very beginning, on your laptop. It allows you to change and iterate your design without rewriting the logic of your implementation.
+
-Check out [Swagger-Spec](https://github.com/wordnik/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
+Remember, one great thing about this approach is that all of the Swagger validation logic is handled for you, and all of the routing logic is managed through the Swagger configuration. You don't have to code (or recode!) any of that stuff yourself.
-## Installation
+# Your swagger API in five steps
-Using NPM, include the `swagger-node-express` module in your `package.json` dependencies.
-
-```json
-{
- ...
- "dependencies": {
- "swagger-node-express": "~2.0",
- ...
- }
-}
-```
+## 1. Install the swagger module
+Install using npm. For complete instructions, see the [install](./docs/install.md) page.
-## Adding Swagger to an Express Application
-
-```js
-// Load module dependencies.
-var express = require("express")
- , url = require("url")
- , swagger = require("swagger-node-express");
-
-// Create the application.
-var app = express();
-app.use(express.json());
-app.use(express.urlencoded());
-
-// Couple the application to the Swagger module.
-swagger.setAppHandler(app);
+```bash
+$ npm install -g swagger
```
-You can optionally add a validator function, which is used to filter the swagger json and request operations:
+## 2. Create a new swagger project
-```js
-// This is a sample validator. It simply says that for _all_ POST, DELETE, PUT methods,
-// the header api_key OR query param api_key must be equal to the string literal
-// special-key. All other HTTP ops are A-OK */
-
-swagger.addValidator(
- function validate(req, path, httpMethod) {
- // example, only allow POST for api_key="special-key"
- if ("POST" == httpMethod || "DELETE" == httpMethod || "PUT" == httpMethod) {
- var apiKey = req.headers["api_key"];
- if (!apiKey) {
- apiKey = url.parse(req.url,true).query["api_key"];
- }
- if ("special-key" == apiKey) {
- return true;
- }
- return false;
- }
- return true;
- }
-);
+Use the [CLI](./docs/cli.md) to create and manage projects. Learn more on the [quick start](./docs/quick-start.md) page.
+```bash
+$ swagger project create hello-world
```
-You now add models to the swagger context. Models are described in a JSON format, per the [swagger model specification](https://github.com/wordnik/swagger-core/wiki/Datatypes). Most folks keep them in a separate file (see [here](https://github.com/wordnik/swagger-node-express/blob/master/Apps/petstore/models.js) for an example), or you can add them as such:
+## 3. Design your API in the Swagger Editor
-```js
-swagger.addModels(models);
+The interactive, browser-based [Swagger Editor](http://editor.swagger.io/) is built in. It provides Swagger 2.0 validation and endpoint routing, generates docs on the fly, and consumes easy-to-read YAML.
+```bash
+$ swagger project edit
```
-Next, add some resources. Each resource contains a swagger spec as well as the action to execute when called. The spec contains enough to describe the method, and adding the resource will do the rest. For example:
+
+## 4. Write controller code in Node.js
-```js
-var findById = {
- 'spec': {
- "description" : "Operations about pets",
- "path" : "/pet.{format}/{petId}",
- "notes" : "Returns a pet based on ID",
- "summary" : "Find pet by ID",
- "method": "GET",
- "parameters" : [swagger.pathParam("petId", "ID of pet that needs to be fetched", "string")],
- "type" : "Pet",
- "errorResponses" : [swagger.errors.invalid('id'), swagger.errors.notFound('pet')],
- "nickname" : "getPetById"
- },
- 'action': function (req,res) {
- if (!req.params.petId) {
- throw swagger.errors.invalid('id');
- }
- var id = parseInt(req.params.petId);
- var pet = petData.getPetById(id);
-
- if (pet) {
- res.send(JSON.stringify(pet));
- } else {
- throw swagger.errors.notFound('pet');
- }
- }
-};
-
-swagger.addGet(findById);
-
-```
-
-Adds an API route to express and provides all the necessary information to swagger.
-
-Finally, configure swagger with a `public` URL and version (note, this must be called after all the other swagger API calls):
-
-```js
-swagger.configure("http://petstore.swagger.wordnik.com", "0.1");
-```
-
-and the server can be started:
+Code your API's business logic in Node.js.
```js
-app.listen(8002);
-```
-
-Now you can open up a [swagger-ui](https://github.com/wordnik/swagger-ui) and browse your API, generate a client with [swagger-codegen](https://github.com/wordnik/swagger-codegen), and be happy.
-
-
-## Additional Configurations
-
-### .{format} suffix removal
-
-If you don't like the .{format} or .json suffix, you can override this before configuring swagger:
-
-```js
-swagger.configureSwaggerPaths("", "/api-docs", "");
+function hello(req, res) {
+ var name = req.swagger.params.name.value || 'stranger';
+ var hello = util.format('Hello, %s!', name);
+ res.json({ "message": hello });
+}
```
-That will put the resource listing under `/api-docs`, and ditch the `.{format}` on each of the apis you're adding to. Make sure to set the paths correctly in your spec configuration though, like such:
+If you look at the Swagger file in the editor (shown in step 3 above), the `x-swagger-router-controller` element (line 17 in the editor screenshot) specifies the name of the controller file associated with the `/hello` path. For example:
-```js
-// note the .{format} is removed from the path!
-var findById = {
- 'spec': {
- "description" : "Operations about pets",
- "path" : "/pet/{petId}",
- "notes" : "Returns a pet based on ID",
- ...
+```yaml
+ paths:
+ /hello:
+ x-swagger-router-controller: hello_world
```
-### Mapping swagger to subpaths
+Controller source code is always placed in `./api/controllers`. So, the controller source file for this project is `./api/controllers/hello_world.js`.
-To add a subpath to the api (i.e. list your REST api under `/api` or `/v1`), you can configure express as follows:
+The `operationId` element specifies which controller function to call. In this case (line 19), it is a function called `hello`. Learn [more](./docs/controllers.md).
-```js
-var app = express();
-var subpath = express();
+## 5. Run the server
-app.use(express.json());
-app.use(express.urlencoded());
-app.use("/v1", subpath);
+Run the project server.
-swagger.setAppHandler(subpath);
+```bash
+$ swagger project start
```
-Now swagger and all apis configured through it will live under the `/v1` path (i.e. `/v1/api-docs`).
+## Now, call the API!
-### Allows special headers
+It just works!
-If you want to modify the default headers sent with every swagger-managed method, you can do so as follows:
-
-```js
-swagger.setHeaders = function setHeaders(res) {
- res.header("Access-Control-Allow-Headers", "Content-Type, X-API-KEY");
- res.header("Content-Type", "application/json; charset=utf-8");
-};
+```bash
+$ curl http://127.0.0.1:10010/hello?name=Scott
+{ "message": "Hello, Scott!" }
```
-If you have a special name for an api key (such as `X-API-KEY`, per above), this is where you can inject it.
-### Enabling cors support using cors library
+# Installing the swagger module
-To enable cors support using cors express npm module (https://npmjs.org/package/cors) add the following to your app.
+See the [Installing swagger](./docs/install.md) for details.
-```js
-var cors = require('cors');
-
-var corsOptions = {
- credentials: true,
- origin: function(origin,callback) {
- if(origin===undefined) {
- callback(null,false);
- } else {
- // change wordnik.com to your allowed domain.
- var match = origin.match("^(.*)?.wordnik.com(\:[0-9]+)?");
- var allowed = (match!==null && match.length > 0);
- callback(null,allowed);
- }
- }
-};
-
-app.use(cors(corsOptions));
+# Using the swagger module
-```
+Go to the [swagger module doc page](./docs/README.md). It includes all the information you need to get started.
-### Configuring the Resource Listing Information
+# About this project
-The Swagger `info` node of the resource listing can be configured using the `configureDeclaration` method:
+This initiative grew out of Apigee-127, an API design-first development framework using Swagger.
+Apigee donated the code to create the swagger-node project in 2015.
-```js
-swagger.configureDeclaration('pet', {
- description: 'Operations about Pets',
- authorizations : ["oauth2"],
- protocols : ["http"],
- consumes: ['application/json'],
- produces: ['application/json']
-});
-```
+ >Copyright 2016 Apigee Corporation
-## License
+ >Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
-Copyright 2014 Reverb Technologies, Inc.
+ >http://www.apache.org/licenses/LICENSE-2.0
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
+ >Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
+---
+
diff --git a/SAMPLE.md b/SAMPLE.md
deleted file mode 100644
index bc6b1f41..00000000
--- a/SAMPLE.md
+++ /dev/null
@@ -1,86 +0,0 @@
-This is the Wordnik Swagger code for the express framework. For more on Swagger, please visit http://swagger.wordnik.com. For more on express, please visit https://github.com/visionmedia/express
-
-### To run the sample App
-
-You must first install dependencies:
-
-```js
-npm install
-```
-
-To run the sample server:
-```js
-node Apps/petstore/main.js
-```
-
-Then visit the server directly from your browser:
-
-```
-http://localhost:8002/api-docs
-```
-
-or from [swagger UI](https://github.com/wordnik/swagger-ui), mounted at `/docs`: [http://localhost:8002/docs](http://localhost:8002/docs).
-
-### How it works
-
-The swagger.js file is included when configuring the express server. There
-are a few additional steps to get the api to declare the swagger spec:
-
-
Define your input/output models in JSON schema format
-
-
Define a specification for operations against the API
-
-For the sample app, the models are defined here: [Apps/petstore/models.js](https://github.com/wordnik/swagger-node-express/blob/master/Apps/petstore/models.js)
-
-You could load this from a static file or generate them programatically as in the
-sample.
-
-The operations and the callback functions are defined in this file: [Apps/petstore/petResources.js](https://github.com/wordnik/swagger-node-express/blob/master/Apps/petstore/petResources.js)
-
-Each spec defines input/output params with helper functions to generate the swagger
-metadata.
-
-When the routes are added (see petstore.js: addGet, addPost...), the params
-are validated and added to the schema. If they fail validation, the failure
-will be logged to the console and they will not be added to the server.
-
-### Other notes
-
-The swagger.js code wraps exceptions and turns them into the appropriate HTTP
-error response. To take advantage of this, you can throw exceptions as follows:
-
-```js
-try{
- // some dangerous function
-}
-catch(ex){
- throw {
- "code":401,
- "description":"You forgot to log in!"
- }
-}
-```
-
-Also, the "Access-Control-Allow-Origin" is hard-coded to "*" to allow access from
-localhost. This will become a configuration option at some point.
-
-#### Security
-
-You can secure the API by adding your own validator. These methods can read the
-request object and extract cookies, headers, api-keys, etc. They also have
-access to the HTTP method and path being requested. You can then decide for
-yourself it the caller should have access to the resource. See the petstore.js
-example:
-
-```js
-swagger.addValidator(
- function validate(req, path, httpMethod) {
- ...
-```
-
-
-### Current limitations
-
-
Only JSON is supported
-
-
- There are probably (many) others
diff --git a/bin/swagger-project.js b/bin/swagger-project.js
new file mode 100755
index 00000000..1647ac5a
--- /dev/null
+++ b/bin/swagger-project.js
@@ -0,0 +1,81 @@
+#!/usr/bin/env node
+/****************************************************************************
+ Copyright 2016 Apigee Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ****************************************************************************/
+'use strict';
+
+var app = require('commander');
+var project = require('../lib/commands/project/project');
+var cli = require('../lib/util/cli');
+var execute = cli.execute;
+var frameworks = Object.keys(project.frameworks).join('|');
+var assertiontypes = project.assertiontypes.join('|');
+var testmodules = project.testmodules.join('|');
+
+app
+ .command('create [name]')
+ .description('Create a folder containing a Swagger project')
+ .option('-f, --framework ', 'one of: ' + frameworks)
+ .action(execute(project.create));
+
+app
+ .command('start [directory]')
+ .description('Start the project in this or the specified directory')
+ .option('-d, --debug [port]', 'start in remote debug mode')
+ .option('-b, --debug-brk [port]', 'start in remote debug mode, wait for debugger connect')
+ .option('-m, --mock', 'start in mock mode')
+ .option('-o, --open', 'open browser as client to the project')
+ .option('-n, --node-args ', 'run node with extra arguments (like --node-args \"--harmony\")')
+ .action(execute(project.start));
+
+app
+ .command('verify [directory]')
+ .description('Verify that the project is correct (swagger, config, etc)')
+ .option('-j, --json', 'output as JSON')
+ .action(execute(project.verify));
+
+app
+ .command('edit [directory]')
+ .description('open Swagger editor for this project or the specified project directory')
+ .option('-s, --silent', 'do not open the browser')
+ .option('--host ', 'the hostname the editor is served from')
+ .option('-p, --port ', 'the port the editor is served from')
+ .action(execute(project.edit));
+
+app
+ .command('open [directory]')
+ .description('open browser as client to the project')
+ .action(execute(project.open));
+
+app
+ .command('test [directory_or_file]')
+ .description('Run project tests')
+ .option('-d, --debug [port]', 'start in remote debug mode')
+ .option('-b, --debug-brk [port]', 'start in remote debug mode, wait for debugger connect')
+ .option('-m, --mock', 'run in mock mode')
+ .action(execute(project.test));
+
+app
+ .command('generate-test [directory]')
+ .description('Generate the test template')
+ .option('-p, --path-name [path]', 'a specific path of the api, also supports regular expression')
+ .option('-f, --test-module ', 'one of: ' + testmodules)
+ .option('-t, --assertion-format ', 'one of: ' + assertiontypes)
+ .option('-o, --force', 'allow overwriting of all existing test files matching those generated')
+ .option('-l, --load-test [path]', 'generate load-tests for specified operations')
+ .action(execute(project.generateTest));
+
+app.parse(process.argv);
+cli.validate(app);
diff --git a/bin/swagger.js b/bin/swagger.js
new file mode 100755
index 00000000..211da4a1
--- /dev/null
+++ b/bin/swagger.js
@@ -0,0 +1,52 @@
+#!/usr/bin/env node
+/****************************************************************************
+ Copyright 2016 Apigee Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ****************************************************************************/
+'use strict';
+
+var app = require('commander');
+var browser = require('../lib/util/browser');
+var rootCommands = require('../lib/commands/commands');
+var cli = require('../lib/util/cli');
+var execute = cli.execute;
+
+app.version(require('../lib/util/cli').version());
+
+app
+ .command('project ', 'project actions');
+
+app
+ .command('docs')
+ .description('open Swagger documentation')
+ .action(function() {
+ browser.open('https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md', function() {
+ process.exit(0);
+ });
+ });
+
+app
+ .command('validate [swaggerFile]')
+ .description('validate a Swagger document (supports unix piping)')
+ .option('-j, --json', 'output as JSON')
+ .action(execute(rootCommands.validate));
+
+app
+ .command('convert [apiDeclarations...]')
+ .description('Converts Swagger 1.2 documents to a Swagger 2.0 document')
+ .option('-o, --output-file ', 'specify an output-file to write to')
+ .action(execute(rootCommands.convert));
+
+app.parse(process.argv);
+cli.validate(app);
\ No newline at end of file
diff --git a/config/index.js b/config/index.js
new file mode 100644
index 00000000..38908e51
--- /dev/null
+++ b/config/index.js
@@ -0,0 +1,80 @@
+/****************************************************************************
+ Copyright 2016 Apigee Corporation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ****************************************************************************/
+'use strict';
+
+var path = require('path');
+var _ = require('lodash');
+var debug = require('debug')('swagger');
+
+var config = {
+ rootDir: path.resolve(__dirname, '..'),
+ userHome: process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'],
+ debug: !!process.env.DEBUG
+};
+config.nodeModules = path.resolve(config.rootDir, 'node_modules');
+
+module.exports = config;
+
+// swagger editor //
+
+config.swagger = {
+ fileName: 'api/swagger/swagger.yaml',
+ editorDir: path.resolve(config.nodeModules, 'swagger-editor'),
+ editorConfig: {
+ analytics: { google: { id: null } },
+ disableCodeGen: true,
+ disableNewUserIntro: true,
+ examplesFolder: '/spec-files/',
+ exampleFiles: [],
+ autocompleteExtension: {},
+ useBackendForStorage: true,
+ backendEndpoint: '/editor/spec',
+ backendHealthCheckTimeout: 5000,
+ useYamlBackend: true,
+ disableFileMenu: true,
+ enableTryIt: true,
+ headerBranding: false,
+ brandingCssClass: null,
+ schemaUrl: '/schema/swagger.json',
+ importProxyUrl: 'https://cors-it.herokuapp.com/?url='
+ }
+};
+
+// project //
+
+config.project = {
+ port: process.env.PORT || 10010,
+ skeletonsDir: path.resolve(__dirname, '..', 'project-skeletons')
+};
+
+// load env vars //
+
+_.each(process.env, function(value, key) {
+ var split = key.split('_');
+ if (split[0] === 'swagger') {
+ var configItem = config;
+ for (var i = 1; i < split.length; i++) {
+ var subKey = split[i];
+ if (i < split.length - 1) {
+ if (!configItem[subKey]) { configItem[subKey] = {}; }
+ configItem = configItem[subKey];
+ } else {
+ configItem[subKey] = value;
+ }
+ }
+ debug('loaded env var: %s = %s', split.slice(1).join('.'), value);
+ }
+});
diff --git a/docs/README.md b/docs/README.md
new file mode 100644
index 00000000..400afa25
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1,20 @@
+
+
+
+## Welcome to Swagger!
+
+
+
+* [Introduction](./introduction.md)
+* [Installation](./install.md)
+* [Quick start](./quick-start.md)
+* [Configuration](./configuration.md)
+* [CLI reference](./cli.md)
+* [About Swagger](./swagger-about.md)
+* [About the swagger.yaml file](./swagger-file.md)
+* [Adding paths](./adding-paths.md)
+* [Writing controllers](./controllers.md)
+* [Using mock mode](./mock-mode.md)
+* [Modules and dependencies](./modules.md)
+* [Reporting issues](./report-issues.md)
+* [Release Notes](./release-notes.md)
diff --git a/docs/adding-paths.md b/docs/adding-paths.md
new file mode 100644
index 00000000..feace925
--- /dev/null
+++ b/docs/adding-paths.md
@@ -0,0 +1,255 @@
+
+
+## Anatomy of a path
+
+This topic looks at how paths are constructed and wired to response objects in a Swagger project's Swagger configuration file.
+
+* [Simple path example](#simple)
+* [More about route handling](#more)
+* [Request and response models](#models)
+* [Next steps](#nextstep)
+
+### Simple path example
+
+The `/hello` path in the original Quick Start example looks like this:
+
+```yaml
+ paths:
+ /hello:
+ # binds swagger app logic to a route
+ x-swagger-router-controller: hello_world
+ get:
+ description: Returns 'Hello' to the caller
+ # used as the method name of the controller
+ operationId: hello
+ parameters:
+ - name: name
+ in: query
+ description: The name of the person to whom to say hello
+ required: false
+ type: string
+ responses:
+ "200":
+ description: Success
+ schema:
+ # a pointer to a definition
+ $ref: #/definitions/HelloWorldResponse
+ # responses may fall through to errors
+ default:
+ description: Error
+ schema:
+ $ref: "#/definitions/ErrorResponse"
+```
+
+The parts of the path definition include:
+
+* `x-swagger-router-controller` is a custom Swagger extension to the Swagger model that maps a path to a controller file. For instance, `/weather` gets mapped to `api/controller/weather.js`. See [More about route handling]() below.
+
+* `operationId` maps to a method name in the controller file.
+
+* `security:` can be used to apply security schemes such as OAuth, Basic authentication, and API keys.
+
+* `parameters:` specifies any parameters used by the path. They can be passed as query or form parameters, or headers.
+
+* The other keys conform to the Swagger 2.0 [specifications](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md). The parameters is a YAML array that defines all the parameters required for the call. The responses object defines the response specifications for response codes.
+
+### More about route handling
+
+As noted previously, `the x-swagger-router-controller` maps a path to a controller file. You can specify a router handler either at the path level or operation level in the Swagger file. For example, at the path level, like this:
+
+```yaml
+paths:
+ /hello:
+ x-swagger-router-controller: hello_world
+ get:
+ description: Returns 'Hello' to the caller
+ # used as the method name of the controller
+ operationId: hello
+```
+
+or at the operation level, like this:
+
+```yaml
+paths:
+ /hello:
+ get:
+ x-swagger-router-controller: hello_world
+ description: Returns 'Hello' to the caller
+ # used as the method name of the controller
+ operationId: hello
+```
+
+Routers applied at the operation level override routers specified at the path level.
+
+When you call your API with a given path, like `GET /hello`, the middleware checks to make sure there is an operation (e.g., "get") defined for that path. If not, then a 405 code is returned. If the path does have a corresponding operation defined, then a 200 response is returned. If you are running in mock mode, you'll get back a mock response, otherwise, you'll get back whatever response is returned by the controller. If you hit a path that is not specified in the Swagger file at all, then that's a 404.
+
+When you call your API, the middleware attempts to match a route defined in the Swagger file to a corresponding controller method. When you test your API, one of three possible results can occur:
+
+* A route defined in the Swagger file matches a controller file, and the controller has a method for the operation. In this case, either the route method is executed or, if you are in mock mode, a mock response is returned.
+
+* A route defined in the Swagger file matches a controller file, but there is no method in the controller for the operation. In this case, a 405 HTTP code is returned.
+
+* The requested route is not present in the Swagger file. In this case, a 404 code is returned.
+
+### Request and response models
+
+The OpenAPI Specification allows you to define both request and the response models (also called schemas). The `path` definition described in the previous section is an example of a request model.
+
+Here's an example of a weather API that returns a relatively complex object.
+
+The Open Weather API returns an object that looks like the following:
+
+ ```json
+ {
+ "coord": {
+ "lon": -77.58,
+ "lat": 35.27
+ },
+ "sys": {
+ "type": 1,
+ "id": 1786,
+ "message": 0.1057,
+ "country": "United States of America",
+ "sunrise": 1409913972,
+ "sunset": 1409959883
+ },
+ "weather": [
+ {
+ "id": 500,
+ "main": "Rain",
+ "description": "light rain",
+ "icon": "10n"
+ },
+ {
+ "id": 211,
+ "main": "Thunderstorm",
+ "description": "thunderstorm",
+ "icon": "11n"
+ }
+ ],
+ "base": "cmc stations",
+ "main": {
+ "temp": 78.58,
+ "pressure": 1021,
+ "humidity": 88,
+ "temp_min": 73.4,
+ "temp_max": 82.4
+ },
+ "wind": {
+ "speed": 5.62,
+ "deg": 40
+ },
+ "clouds": {
+ "all": 90
+ },
+ "dt": 1409876198,
+ "id": 4474436,
+ "name": "Kinston",
+ "cod": 200
+ }
+ ```
+
+
+To wire the path to the schema, you use the `responses` element to refer to the schema definition. In this example, we specify two responses, a 200 and an Error response. Note that you use `$ref` syntax to refer to each specific schema definition, listed in the `#/definitions` section (which we describe below).
+
+>Note: You must use explicit references of the form $ref: #/definitions/. For example: $ref: #/definitions/WeatherResponse.
+
+>Note: In this case, all other responses that are not 200 will be referred to the Error response schema.
+
+```yaml
+ paths:
+ /weather:
+ ...
+ responses:
+ "200":
+ description: Success
+ schema:
+ $ref: #/definitions/WeatherResponse
+ default:
+ description: Error
+ schema:
+ $ref: #/definitions/ErrorResponse
+```
+
+Then in the `#/definitions` section of the Swagger document we define the `WeatherResponse` schemas that we referenced from the `/paths` section. Here is the schema that represents the JSON returned by the weather API (shown previously). These schemas are primarily used to provide response objects for mock mode:
+
+```yaml
+definitions:
+ WeatherResponse:
+ type: "object"
+ properties:
+ base:
+ type: "string"
+ clouds:
+ type: "object"
+ properties:
+ all:
+ type: "number"
+ cod:
+ type: "number"
+ coord:
+ type: "object"
+ properties:
+ lat:
+ type: "number"
+ lon:
+ type: "number"
+ dt:
+ type: "number"
+ id:
+ type: "number"
+ main:
+ type: "object"
+ properties:
+ humidity:
+ type: "number"
+ pressure:
+ type: "number"
+ temp_max:
+ type: "number"
+ temp_min:
+ type: "number"
+ temp:
+ type: "number"
+ name:
+ type: "string"
+ sys:
+ type: "object"
+ properties:
+ country:
+ type: "string"
+ id:
+ type: "number"
+ message:
+ type: "number"
+ sunrise:
+ type: "number"
+ sunset:
+ type: "number"
+ type:
+ type: "number"
+ weather:
+ type: "array"
+ items:
+ type: "object"
+ properties:
+ description:
+ type: "string"
+ icon:
+ type: "string"
+ id:
+ type: "number"
+ main:
+ type: "string"
+ wind:
+ type: "object"
+ properties:
+ deg:
+ type: "number"
+ speed:
+ type: "number"
+```
+
+### Next steps
+
+Now that you know have added a path, its time to [implement the actual controller](./controllers.md)
diff --git a/docs/cli.md b/docs/cli.md
new file mode 100644
index 00000000..693a3e16
--- /dev/null
+++ b/docs/cli.md
@@ -0,0 +1,152 @@
+
+
+
+## Command-line interface reference
+
+Create, run, and manage Swagger projects from the command line.
+
+* [swagger](#swagger)
+* [project create](#create)
+* [project start](#start)
+* [project verify](#verify)
+* [project edit](#edit)
+* [project open](#open)
+* [project test](#test)
+* [docs](#docs)
+
+#### swagger
+
+Options:
+
+* -h, --help: Outputs usage information.
+* -V, --version: Outputs the swagger cli version number.
+
+Example:
+
+ swagger -V
+ 0.2.0
+
+
+#### swagger project create [options] [name]
+
+Creates a folder with the specified [name] containing a new Swagger project. A project skeleton is downloaded from GitHub and installed in the new folder.
+
+Options:
+
+* -h, --help: Outputs usage information.
+* -f, --framework : Specifies an API framework to use with the project. Choices are connect, express, hapi, restify, or sails.
+
+Example:
+
+ swagger project create -f express sn-express
+ ls sn-express
+ README.md api app.js config node_modules package.json test
+
+
+#### swagger project start [options] [directory]
+
+Starts the Swagger project in the current (or specified) directory. The server automatically restarts when you make changes to the project. You can also force a restart by typing `rs` on the server command line.
+
+Options:
+
+* -h, --help: Outputs usage information.
+* -d, --debug : Start in remote debug mode so you can connect to it with a debugger.
+* -b, --debug-brk : Start in remote debug mode, wait for debugger.
+* -m, --mock: Start in mock mode. For more information, see [Running in mock mode](./mock-mode.md).
+* -o, --open: Open the default browser as a client to the project.
+* -n, --node-args : Pass extra arguments to node. E.g. `swagger project start --node-args "--harmony"` will run node with [ES6 a.k.a harmony features](https://github.com/joyent/node/wiki/ES6-%28a.k.a.-Harmony%29-Features-Implemented-in-V8-and-Available-in-Node) enabled.
+
+Example:
+
+ cd ./myproject
+ swagger project start -m
+
+
+#### swagger project verify [options] [project root directory]
+
+Verifies that the project in the current (or specified) directory is correct. Reports errors and warnings from the Swagger model, project configuration, etc.
+
+Options:
+
+* -h, --help: Outputs usage information.
+* -j, --json: Output information in JSON format.
+
+Example:
+
+ cd ./myproject
+ swagger project verify
+ Project Errors
+ --------------
+ #/: Missing required property: paths
+ #/: Additional properties not allowed: aths
+ Results: 2 errors, 0 warnings
+
+
+
+#### swagger project edit [options] [directory]
+
+Opens the project in the current (or specified) directory in the [Swagger Editor](https://github.com/swagger-api/swagger-editor).
+
+
+
+Options:
+
+* -h, --help: Outputs usage information.
+* -s, --silent: Do not open the browser.
+* --host : The hostname the editor is served from (default: 127.0.0.1).
+* -p, --port : The port the editor is served from (default: random port).
+
+Example:
+
+ cd ./myproject
+ swagger project edit
+
+
+#### swagger project open [directory]
+
+Opens the browser as a client to the current or specified project.
+
+Options:
+
+* -h, --help: Outputs usage information.
+
+Example:
+
+`swagger project open ./myproject`
+
+
+
+#### swagger project test [options] [directory-or-file]
+
+Runs project tests.
+
+Options:
+
+* -h, --help: Outputs usage information.
+* -d, --debug : Start in remote debug mode so you can connect to it with a debugger.
+* -b, --debug-brk : Start in remote debug mode, wait for debugger.
+* -m, --mock: Start in mock mode. For more information, see [Running in mock mode](./mock-mode.md).
+
+Example:
+
+ `swagger project test`
+
+ controllers
+ hello_world
+ GET /hello
+ ✓ should return a default string
+ ✓ should accept a name parameter
+ 2 passing (27ms)
+
+
+##### swagger docs
+
+Opens the OpenAPI 2.0 Specification in your browser.
+
+Example:
+
+ swagger docs
+
+
+
+
diff --git a/docs/configuration.md b/docs/configuration.md
new file mode 100644
index 00000000..fc804b22
--- /dev/null
+++ b/docs/configuration.md
@@ -0,0 +1,110 @@
+## Configuration
+
+** NOTE: The following applies to swagger-node apps replying on swagger-node-runner 0.5.x and better. (ie. Any app using swagger-connect 0.1.0, swagger-express-mw 0.1.0, swagger-hapi 0.1.0, swagger-restify 0.1.0, or swagger-sails 0.1.0 - or higher versions of the same.) **
+
+Swagger-Node application configuration is driven by the file `default.yaml` (by default) in the application's `config` directory. Configuration is driven by the [config](https://github.com/lorenwest/node-config/wiki/Configuration-Files) module, so reference its documentation to understand how you may set up configuration per environment and perform configuration overrides. By default, the configuration file looks something like this:
+
+```yaml
+# swagger configuration file
+
+# values in the swagger hash are system configuration for swagger-node
+swagger:
+
+ fittingsDirs: [ api/fittings, node_modules ]
+ defaultPipe: null
+ swaggerControllerPipe: swagger_controllers # defines the standard processing pipe for controllers
+
+ # values defined in the bagpipes key are the bagpipes pipes and fittings definitions
+ # (see https://github.com/apigee-127/bagpipes)
+ bagpipes:
+
+ _router:
+ name: swagger_router
+ mockMode: false
+ mockControllersDirs: [ api/mocks ]
+ controllersDirs: [ api/controllers ]
+
+ _swagger_validate:
+ name: swagger_validator
+ validateResponse: true
+
+ # pipe for all swagger-node controllers
+ swagger_controllers:
+ - onError: json_error_handler
+ - cors
+ - swagger_security
+ - _swagger_validate
+ - express_compatibility
+ - _router
+
+ # pipe to serve swagger (endpoint is in swagger.yaml)
+ swagger_raw:
+ name: swagger_raw
+
+# any other values in this file are just loaded into the config for application access...
+```
+
+Important things to note:
+
+* All configuration for the Swagger-Node system is under the `swagger` key
+* Overall system behavior is driven by configuring the [Bagpipes](https://github.com/apigee-127/bagpipes) library
+* You may include other values and sections as you wish, they will just be loaded into the config for your application
+ to access.
+
+Let's walk through the configuration:
+
+### fittingsDirs
+
+Defines the directories Bagpipes will search for fittings that are defined or used in the bagpipes section below. Fittings are extension plugins that can either be installed (eg. https://www.npmjs.com/package/volos-swagger-oauth and https://www.npmjs.com/package/volos-swagger-apply) or written into your application directly.
+
+### defaultPipe
+
+If no pipe is explicitly declared for a path or operation, this pipe will be played when that endpoint is hit.
+
+### swaggerControllerPipe
+
+This names the standard pipe that plays for the swagger-node controllers (declared in the swagger.yaml with the
+extension `x-swagger-router-controller`). We'll look at how that's defined in a second.
+
+### bagpipes
+
+This block is the configuration passed to the [bagpipes](https://github.com/apigee-127/bagpipes) underlying the application. As you can see, it defines not only the flow, but also the configuration of the elements.
+
+#### _router
+
+This configures the standard swagger-node router (currently swagger-tools). It tells it how to find your controllers, your mock controllers, and whether to run in mock mode.
+
+#### _swagger_validate
+
+This configures the swagger validator (currently swagger-tools). You can turn response validation on and off here.
+
+#### swagger_controllers
+
+Because this is specified as your controller pipe (in the `swaggerControllerPipe` setting above), this pipe plays for all paths and operations where you've specified a controller extension (`x-swagger-router-controller`).
+
+The default pipe is as follows:
+
+1. set an error handler that converts all errors to JSON
+2. run the [cors](https://www.npmjs.com/package/cors) module
+3. execute swagger security (currently swagger-tools)
+4. run swagger validator (currently swagger-tools)
+5. add a few commonly used Express functions (if not already present) to request (path, query, get) and response (json,
+ get, set, status).
+6. run the router (currently swagger-tools)
+
+As you can see, you have full control over the pipeline and may add or remove elements you need for your specific application and environment.
+
+#### swagger_raw
+
+This serves your swagger file - on the path that is defined in your `api/swagger/swagger.yaml` and tagged with the `x-swagger-pipe` extension. It looks like this:
+
+```yaml
+ /swagger:
+ x-swagger-pipe: swagger_raw
+```
+
+Note: This automatically filters out all sections that are swagger extensions (`x-*`) by using a predefined regular expression: `/^(?!x-.*)/`.
+
+Naturally, if you don't wish to serve your swagger on this path or at all, you may change or remove this.
+
+This also conveniently serves as an example of how to map a path in your Swagger to a pipe. You may, of course, define and use any pipes you wish using any of the Bagpipes operations or add your own in your fittings directory.
diff --git a/docs/controllers.md b/docs/controllers.md
new file mode 100644
index 00000000..552f7587
--- /dev/null
+++ b/docs/controllers.md
@@ -0,0 +1,118 @@
+
+## About controllers
+
+* [Implementing a controller](#implementing)
+* [Using query parameters](#query)
+* [Weather API example](#weather)
+
+### Implementing a controller
+
+This topic explains how to implement a controller. The `x-swagger-router-controller` Swagger extension element is used to specify the name of a controller file. The quick start example defines a `hello_world` controller file, which is by default in `api/controllers/hello_world.js`.
+
+```yaml
+paths:
+ /hello:
+ # binds swagger app logic to a route
+ x-swagger-router-controller: hello_world
+```
+
+By default, controller method names map to the HTTP operation names, like get() or post(). But you can specify any name you wish with the `operationId` element. In the following example, a GET request results in calling the hello() method in the controller.
+
+```yaml
+ get:
+ description: Returns 'Hello' to the caller
+ # used as the method name of the controller
+ operationId: hello
+```
+
+Here is the `hello_world.js` implementation for the quick start example. It retrieves the query parameter value and returns a response.
+
+```javascript
+ var util = require('util');
+
+ module.exports = {
+ hello: hello
+ };
+
+ function hello(req, res) {
+ var name = req.swagger.params.name.value || 'stranger';
+ var hello = util.format('Hello, %s!', name);
+ res.json({ "message": hello });
+ }
+```
+
+### Using query parameters
+
+In the controller code, we obtained the value of a query parameter and echoed it back in the response. We used the `req.swagger` object to obtain access to the query parameters. You declare query parameters in the paths section of the project's Swagger definition. For example:
+
+```yaml
+ parameters:
+ - name: name
+ in: query
+ description: The name of the person to whom to say hello
+ required: false
+ type: string
+```
+
+The req.swagger object is populated by the swagger-tools middleware component of swagger. To read more about this object, see the [Swagger tools middleware documentation](https://github.com/apigee-127/swagger-tools/blob/master/docs/Middleware.md).
+
+### Weather API example
+
+Let's look at an example controller for a simple weather API.
+
+The Weather API requires a controller function that takes in request and response objects, queries the Open Weather Map API using the `city` query parameter and returns the current weather conditions.
+
+Note that Open Weather returns a JSON object. Also, we'll need to export the controller function so that it is available to the outside world.
+
+We will use the `request` library to make the request. So, ensure it is installed and added to `package.json`:
+
+ ```
+npm install request --save
+ ```
+
+>Note: If a controller requires additional Node.js modules, be sure to add them to your `package.json` file and execute `npm install`.
+
+In the Swagger file, you can see that when a GET is performed on `/weather`, the target controller file is `api/controllers/weather.js`, and the target method to call is `getWeatherByCity()`:
+
+```yaml
+ paths:
+ /weather:
+ x-swagger-router-controller: weather
+ get:
+ description: "Returns current weather in the specified city to the caller"
+ operationId: getWeatherByCity
+ parameters:
+ - name: city
+ in: query
+ description: "The city you want weather for in the form city,state,country"
+ required: true
+ type: "string"
+```
+
+Here is the controller implementation for the `getWeatherByCity` function:
+
+```javascript
+ 'use strict';
+
+ var util = require('util');
+ var request = require('request');
+
+ module.exports = {
+ getWeatherByCity: getWeatherByCity
+ }
+
+ function getWeatherByCity(req, res) {
+ var city = req.swagger.params.city.value;
+ var url = "http://api.openweathermap.org/data/2.5/weather?q="+city+"&units=imperial";
+ console.log('Executing request: '+url);
+ request.get(url).pipe(res);
+ };
+```
+
+
+Here is how you call the Weather API, which returns data for a specified city.
+
+ ```bash
+ curl http://localhost:10010/weather\?city\=San%20Jose,CA
+ ```
+
diff --git a/docs/docco.css b/docs/docco.css
deleted file mode 100644
index c36fdb41..00000000
--- a/docs/docco.css
+++ /dev/null
@@ -1,193 +0,0 @@
-/*--------------------- Layout and Typography ----------------------------*/
-body {
- font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
- font-size: 15px;
- line-height: 22px;
- color: #252519;
- margin: 0; padding: 0;
-}
-a {
- color: #261a3b;
-}
- a:visited {
- color: #261a3b;
- }
-p {
- margin: 0 0 15px 0;
-}
-h1, h2, h3, h4, h5, h6 {
- margin: 0px 0 15px 0;
-}
- h1 {
- margin-top: 40px;
- }
-hr {
- border: 0 none;
- border-top: 1px solid #e5e5ee;
- height: 1px;
- margin: 20px 0;
-}
-#container {
- position: relative;
-}
-#background {
- position: fixed;
- top: 0; left: 525px; right: 0; bottom: 0;
- background: #f5f5ff;
- border-left: 1px solid #e5e5ee;
- z-index: -1;
-}
-#jump_to, #jump_page {
- background: white;
- -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
- -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
- font: 10px Arial;
- text-transform: uppercase;
- cursor: pointer;
- text-align: right;
-}
-#jump_to, #jump_wrapper {
- position: fixed;
- right: 0; top: 0;
- padding: 5px 10px;
-}
- #jump_wrapper {
- padding: 0;
- display: none;
- }
- #jump_to:hover #jump_wrapper {
- display: block;
- }
- #jump_page {
- padding: 5px 0 3px;
- margin: 0 0 25px 25px;
- }
- #jump_page .source {
- display: block;
- padding: 5px 10px;
- text-decoration: none;
- border-top: 1px solid #eee;
- }
- #jump_page .source:hover {
- background: #f5f5ff;
- }
- #jump_page .source:first-child {
- }
-table td {
- border: 0;
- outline: 0;
-}
- td.docs, th.docs {
- max-width: 450px;
- min-width: 450px;
- min-height: 5px;
- padding: 10px 25px 1px 50px;
- overflow-x: hidden;
- vertical-align: top;
- text-align: left;
- }
- .docs pre {
- margin: 15px 0 15px;
- padding-left: 15px;
- }
- .docs p tt, .docs p code {
- background: #f8f8ff;
- border: 1px solid #dedede;
- font-size: 12px;
- padding: 0 0.2em;
- }
- .pilwrap {
- position: relative;
- }
- .pilcrow {
- font: 12px Arial;
- text-decoration: none;
- color: #454545;
- position: absolute;
- top: 3px; left: -20px;
- padding: 1px 2px;
- opacity: 0;
- -webkit-transition: opacity 0.2s linear;
- }
- td.docs:hover .pilcrow {
- opacity: 1;
- }
- td.code, th.code {
- padding: 14px 15px 16px 25px;
- width: 100%;
- vertical-align: top;
- background: #f5f5ff;
- border-left: 1px solid #e5e5ee;
- white-space: nowrap;
- }
- pre, tt, code {
- font-size: 12px; line-height: 18px;
- font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
- margin: 0; padding: 0;
- }
-
-
-/*---------------------- Syntax Highlighting -----------------------------*/
-td.linenos { background-color: #f0f0f0; padding-right: 10px; }
-span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
-body .hll { background-color: #ffffcc }
-body .c { color: #408080; font-style: italic } /* Comment */
-body .err { border: 1px solid #FF0000 } /* Error */
-body .k { color: #954121 } /* Keyword */
-body .o { color: #666666 } /* Operator */
-body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
-body .cp { color: #BC7A00 } /* Comment.Preproc */
-body .c1 { color: #408080; font-style: italic } /* Comment.Single */
-body .cs { color: #408080; font-style: italic } /* Comment.Special */
-body .gd { color: #A00000 } /* Generic.Deleted */
-body .ge { font-style: italic } /* Generic.Emph */
-body .gr { color: #FF0000 } /* Generic.Error */
-body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
-body .gi { color: #00A000 } /* Generic.Inserted */
-body .go { color: #808080 } /* Generic.Output */
-body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
-body .gs { font-weight: bold } /* Generic.Strong */
-body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
-body .gt { color: #0040D0 } /* Generic.Traceback */
-body .kc { color: #954121 } /* Keyword.Constant */
-body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
-body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
-body .kp { color: #954121 } /* Keyword.Pseudo */
-body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
-body .kt { color: #B00040 } /* Keyword.Type */
-body .m { color: #666666 } /* Literal.Number */
-body .s { color: #219161 } /* Literal.String */
-body .na { color: #7D9029 } /* Name.Attribute */
-body .nb { color: #954121 } /* Name.Builtin */
-body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
-body .no { color: #880000 } /* Name.Constant */
-body .nd { color: #AA22FF } /* Name.Decorator */
-body .ni { color: #999999; font-weight: bold } /* Name.Entity */
-body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
-body .nf { color: #0000FF } /* Name.Function */
-body .nl { color: #A0A000 } /* Name.Label */
-body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
-body .nt { color: #954121; font-weight: bold } /* Name.Tag */
-body .nv { color: #19469D } /* Name.Variable */
-body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
-body .w { color: #bbbbbb } /* Text.Whitespace */
-body .mf { color: #666666 } /* Literal.Number.Float */
-body .mh { color: #666666 } /* Literal.Number.Hex */
-body .mi { color: #666666 } /* Literal.Number.Integer */
-body .mo { color: #666666 } /* Literal.Number.Oct */
-body .sb { color: #219161 } /* Literal.String.Backtick */
-body .sc { color: #219161 } /* Literal.String.Char */
-body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
-body .s2 { color: #219161 } /* Literal.String.Double */
-body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
-body .sh { color: #219161 } /* Literal.String.Heredoc */
-body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
-body .sx { color: #954121 } /* Literal.String.Other */
-body .sr { color: #BB6688 } /* Literal.String.Regex */
-body .s1 { color: #219161 } /* Literal.String.Single */
-body .ss { color: #19469D } /* Literal.String.Symbol */
-body .bp { color: #954121 } /* Name.Builtin.Pseudo */
-body .vc { color: #19469D } /* Name.Variable.Class */
-body .vg { color: #19469D } /* Name.Variable.Global */
-body .vi { color: #19469D } /* Name.Variable.Instance */
-body .il { color: #666666 } /* Literal.Number.Integer.Long */
\ No newline at end of file
diff --git a/docs/images/overview.png b/docs/images/overview.png
new file mode 100644
index 00000000..e9ba37b5
Binary files /dev/null and b/docs/images/overview.png differ
diff --git a/docs/images/overview2.png b/docs/images/overview2.png
new file mode 100644
index 00000000..cc238649
Binary files /dev/null and b/docs/images/overview2.png differ
diff --git a/docs/images/project-call.png b/docs/images/project-call.png
new file mode 100644
index 00000000..6f997982
Binary files /dev/null and b/docs/images/project-call.png differ
diff --git a/docs/images/project-controller.png b/docs/images/project-controller.png
new file mode 100644
index 00000000..9a815797
Binary files /dev/null and b/docs/images/project-controller.png differ
diff --git a/docs/images/project-create.png b/docs/images/project-create.png
new file mode 100644
index 00000000..cabc0a1b
Binary files /dev/null and b/docs/images/project-create.png differ
diff --git a/docs/images/project-editor.png b/docs/images/project-editor.png
new file mode 100644
index 00000000..bac439a2
Binary files /dev/null and b/docs/images/project-editor.png differ
diff --git a/docs/images/project-hello.png b/docs/images/project-hello.png
new file mode 100644
index 00000000..fd56fc5d
Binary files /dev/null and b/docs/images/project-hello.png differ
diff --git a/docs/images/project-server.png b/docs/images/project-server.png
new file mode 100644
index 00000000..ce0def85
Binary files /dev/null and b/docs/images/project-server.png differ
diff --git a/docs/images/project-start-editor.png b/docs/images/project-start-editor.png
new file mode 100644
index 00000000..f5518cf1
Binary files /dev/null and b/docs/images/project-start-editor.png differ
diff --git a/docs/images/project-start.png b/docs/images/project-start.png
new file mode 100644
index 00000000..54d5f722
Binary files /dev/null and b/docs/images/project-start.png differ
diff --git a/docs/images/swagger-editor.png b/docs/images/swagger-editor.png
new file mode 100644
index 00000000..71ba5757
Binary files /dev/null and b/docs/images/swagger-editor.png differ
diff --git a/docs/images/swagger-icon.png b/docs/images/swagger-icon.png
new file mode 100644
index 00000000..ce2150ce
Binary files /dev/null and b/docs/images/swagger-icon.png differ
diff --git a/docs/images/swagger-install.png b/docs/images/swagger-install.png
new file mode 100644
index 00000000..3388c38e
Binary files /dev/null and b/docs/images/swagger-install.png differ
diff --git a/docs/install.md b/docs/install.md
new file mode 100644
index 00000000..7d20a4c7
--- /dev/null
+++ b/docs/install.md
@@ -0,0 +1,77 @@
+
+## Installing swagger
+
+* [Prerequisites](#prereqs)
+* [Installing with npm](#install)
+* [Using npm without sudo](#nosudo)
+* [Configuring the default browser in Linux](#defaultbrowser)
+
+### Prerequisites
+
+* [Node.js](http://nodejs.org/download/) (v0.10.24+)
+* [npm](https://docs.npmjs.com/getting-started/installing-node) (v1.3.0+)
+
+### Installing with npm
+
+The `swagger` module is designed for Node.js and is available through npm.
+
+#### Installing on Linux / Mac
+
+Here's how you install with `sudo`. If you do not wish to use `sudo`, see [Using npm without sudo](#nosudo) below.
+
+1. Open a terminal.
+2. Run the install:
+
+ `sudo npm install -g swagger`
+
+**Note**: `sudo` may or may not be required with the `-g` option depending on your configuration. If you do not use `-g`, you may need to add the `swagger/bin` directory to your PATH manually. On Unix-based machines
+the bin directory will often be found here: `/usr/local/lib/node_modules/swagger/bin`.
+
+#### Installing on Windows
+
+1. Open a terminal.
+2. Run the install:
+
+ `npm install -g swagger`
+
+## Using npm without sudo
+
+If you don't want to use sudo to install swagger on your system, follow the instructions in this section.
+
+#### Overview
+
+By default npm will place 'global' modules installed with the `-g` flag in `/usr/local/lib/node_modules` using the default prefix of `/usr/local`. Global executables would be placed in `/usr/local/bin` using the same default prefix, thereby putting them on the default PATH in most cases. In order to write to both of these directories root permissions are required.
+
+Many Node.js developers choose to use a different prefix such that they do not need to use root permissions to install modules using the `-g` flag (rightfully so - you should always be wary about things that 'require root permissions'!). Using root permissions is effectively a shortcut. In order to use executables installed using a different prefix you need to add an element to your path.
+
+#### Steps
+
+1. Set the 'prefix' for npm by using the following command (documented here: [npm-config](https://www.npmjs.org/doc/misc/npm-config.html). This will create a file `~/.npmrc` that contains configuration information for npm.
+
+```bash
+ npm set prefix ~/npm
+```
+
+2. Edit your `.bash_profile` or the appropriate shell initialization script to add `~/npm` to your `PATH` by adding the following line (or placing the single line in the new file if it does not exist):
+
+ ```bash
+ PATH=~/npm/bin:$PATH
+ ```
+
+ This will enable you to easily use executable scripts installed using `-g` through npm - both for swagger and for other tools as well!
+
+###Configuring the default browser on Linux
+
+On Linux platforms, you need to specify your browser path before using the Swagger editor.
+
+1. Create or open the following file in a text editor:
+
+ `~/.a127/config.js`
+
+2. Add the following contents to the file:
+
+ ```javascript
+ module.exports = {
+ browser: 'the/path/to/your/browser'
+ };
+ ```
diff --git a/docs/introduction.md b/docs/introduction.md
new file mode 100644
index 00000000..8532b295
--- /dev/null
+++ b/docs/introduction.md
@@ -0,0 +1,46 @@
+## What is the swagger module?
+The swagger module provides tools for designing and building APIs entirely in Node.js. It integrates with popular Node.js servers, including Express, hapi, restify, and Sails, as well as any Connect-based middleware. With swagger, you can specify, build, and test your API from the very beginning, and it allows you to make changes to your design without rewriting the logic of your implementation. It explicitly isolates the design of your interfaces from writing your controller code, leading to a much better software development lifecycle.
+
+* [The API-First Development Process](#sdlc)
+* [Reporting issues](#gethelp)
+
+### The API-First Development Process
+API design is a discovery process. Swagger development begins with design tooling, and it expects that you will evolve your interface over time. It gracefully handles the routing of interfaces to controllers so that you can make changes to your interfaces without clobbering any of your implementation logic.
+
+Designing an API specification is like writing a contract. As you write the spec in YAML using [Swagger 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md), your API documentation is generated in real-time, allowing the client and server teams to agree on how their systems will work together.
+
+Once you have defined your first operation, it drives a mock server, which enables client development happen in parallel with server development. As you build the client, you will discover further changes you'll need to make to your APIs, meaning another iteration of the specification.
+
+* Defining your API specification using the Swagger Editor (included with swagger).
+
+*The Swagger Editor*
+
+
+Write your specification in YAML on the left, and see the API documentation in real-time on the right. Auto-completion makes it easy to learn the syntax, and validation helps you correct any syntactic or semantic errors you might make along the way.
+
+* Use the `x-swagger-router-controller` extension to annotating your paths and operations. This maps the interface onto the name of the controller file that implements the logic behind the operation. For example:
+
+```yaml
+paths:
+ /hello:
+ x-swagger-router-controller: "hello_world"
+```
+
+* Use the operationId property to specify which controller method to call for the given path:
+
+```yaml
+ get:
+ description: "Returns 'Hello' to the caller"
+ operationId: "hello"
+```
+
+* Implement your controller files in Node.js and place them in `/api/controllers`. For example: `/api/controllers/hello_world.js`
+
+* Behind the scenes, swagger wires up your app, routing HTTP requests to specific Node.js controller files.
+
+* At runtime swagger-tools middleware validates the request before sending it to the `hello` operation of the `hello_world` controller.
+
+* Finally, the controller logic associated with the requested path is executed.
+
+### Reporting issues
+Have an issue to report? See the [Reporting issues](./report-issues.md).
diff --git a/docs/main.html b/docs/main.html
deleted file mode 100644
index 4465df04..00000000
--- a/docs/main.html
+++ /dev/null
@@ -1,53 +0,0 @@
- main.js
This is a sample validator. It simply says that for all POST
-methods, the header api_key OR query param api_key must be equal
-to the string literal special-key. All other HTTP ops are A-OK
diff --git a/docs/mock-mode.md b/docs/mock-mode.md
new file mode 100644
index 00000000..f9066fd1
--- /dev/null
+++ b/docs/mock-mode.md
@@ -0,0 +1,349 @@
+## Running in mock mode
+
+Mock mode lets you "mock up" API routes/paths and response objects in the Swagger editor and test them without writing any controller code. By default, mock mode responses are system-generated; however, you can optionally implement custom mock controllers to return custom responses.
+
+* [When to use mock mode](#whentouse)
+* [Starting a project in mock mode](#starting)
+* [Quick example: mock mode in action](#quickexample)
+* [Building and testing an API in mock mode](#buildtest)
+* [Implementing mock controllers](#mockcontrollers)
+* [Wiring up and implementing the API controller](#wireup)
+
+### When to use mock mode
+
+Mock mode is useful when you are designing your API model in the Swagger editor, but you're not ready to implement the API's handler/controllers. For example, you might use mock mode when you're trying to decide which API routes you need and what kind of data each API operation should return. Basically, mock mode let's you perfect your API design without writing any Node.js code.
+
+When you're happy with the overall API design, then you can implement your controller methods.
+
+### Starting a project in mock mode
+
+To start an swagger project in mock mode, use the `-m` flag:
+
+`swagger project start -m`
+
+
+### Quick example: mock mode in action
+
+Here's a simple example where the API definition only has one path (`/weather`) and a response object called WeatherResponse. In this case, the WeatherResponse object returns a simple message of type string. Here's the Swagger YAML:
+
+
+```yaml
+swagger: '2.0'
+info:
+ version: "0.0.1"
+ title: Mock mode test
+host: localhost
+basePath: /
+schemes:
+ - http
+consumes:
+ - application/json
+produces:
+ - application/json
+paths:
+ /weather:
+ x-swagger-router-controller: weather
+ get:
+ responses:
+ "200":
+ description: Success
+ schema:
+ $ref: "#/definitions/WeatherResponse"
+definitions:
+ WeatherResponse:
+ required:
+ - message
+ properties:
+ message:
+ type: string
+```
+
+
+To test this API configuration in mock mode, start your swagger project with the mock mode "-m" flag:
+
+`swagger project start -m`
+
+When you call the API, like this:
+
+`curl -i http://localhost:10010/weather`
+
+Mock mode returns this system-generated response:
+
+
+```json
+ {
+ "message": "Sample text"
+ }
+```
+
+If you change the response object to return an integer...
+
+```yaml
+ WeatherResponse:
+ required:
+ - message
+ properties:
+ message:
+ type: integer
+```
+
+The mock response is an integer:
+
+```json
+ {
+ "message": 1
+ }
+```
+
+
+### Building and testing your API model in mock mode
+
+An actual weather API isn't only going to return a string; it's going to return a more complex response object consisting of objects, strings, and numbers. As you build your API, you can model and test the intended behavior entirely in mock mode.
+
+For example, here's a WeatherResponse object for a weather API. It's got strings, numbers, arrays, and objects representing various aspects of weather data.
+
+```yaml
+ WeatherResponse:
+ properties:
+ base:
+ type: "string"
+ clouds:
+ type: "object"
+ properties:
+ all:
+ type: "number"
+ cod:
+ type: "number"
+ coord:
+ type: "object"
+ properties:
+ lat:
+ type: "number"
+ lon:
+ type: "number"
+ dt:
+ type: "number"
+ id:
+ type: "number"
+ main:
+ type: "object"
+ properties:
+ humidity:
+ type: "number"
+ pressure:
+ type: "number"
+ temp_max:
+ type: "number"
+ temp_min:
+ type: "number"
+ temp:
+ type: "number"
+ name:
+ type: "string"
+ sys:
+ type: "object"
+ properties:
+ country:
+ type: "string"
+ id:
+ type: "number"
+ message:
+ type: "number"
+ sunrise:
+ type: "number"
+ sunset:
+ type: "number"
+ type:
+ type: "number"
+ weather:
+ type: "array"
+ items:
+ type: "object"
+ properties:
+ description:
+ type: "string"
+ icon:
+ type: "string"
+ id:
+ type: "number"
+ main:
+ type: "string"
+ wind:
+ type: "object"
+ properties:
+ deg:
+ type: "number"
+ speed:
+ type: "number"
+```
+
+
+If you call this API in mock mode, it returns the following JSON. Objects, arrays, strings, and numbers are all "mocked up" with mock values of the appropriate data type:
+
+```yaml
+ {
+ "base": "Sample text",
+ "clouds": {
+ "all": 1
+ },
+ "cod": 1,
+ "coord": {
+ "lat": 1,
+ "lon": 1
+ },
+ "dt": 1,
+ "id": 1,
+ "main": {
+ "humidity": 1,
+ "pressure": 1,
+ "temp": 1,
+ "temp_max": 1,
+ "temp_min": 1
+ },
+ "name": "Sample text",
+ "sys": {
+ "country": "Sample text",
+ "id": 1,
+ "message": 1,
+ "sunrise": 1,
+ "sunset": 1,
+ "type": 1
+ },
+ "weather": [
+ {
+ "description": "Sample text",
+ "icon": "Sample text",
+ "id": 1,
+ "main": "Sample text"
+ }
+ ],
+ "wind": {
+ "deg": 1,
+ "speed": 1
+ }
+ }
+```
+
+
+### Implementing mock mode controllers
+
+By default, mock mode returns programmed responses, like "Sample text" for a string, a number for an integer, and so on.
+
+But you can also create mock controllers with handler methods that return custom responses.
+
+Place these custom "mock" controllers in the `/api/mock` directory.
+
+Here's an example that returns some data whenever the `search()` handler method is called:
+
+
+```javascript
+ 'use strict';
+
+ module.exports = {
+ search: search
+ };
+
+ function search(req, res, next) {
+
+ res.json([{ user: 'mock', created: new Date(), text: 'this'}]);
+ }
+```
+
+### Wiring up and implementing the API controller
+
+After you're happy with your API design, you're ready to implement wire up the controller for the `/weather` path.
+
+You simply specify in the OpenAPI spec the route handler (`x-swagger-router-controller`) file, which method to call in the controller (`operationId`), and any query parameters you wish to pass:
+
+In weather sample's `swagger.yaml` file, it looks like this:
+
+```yaml
+ paths:
+ /weather:
+ x-swagger-router-controller: weather
+ get:
+ description: "Returns current weather in the specified city to the caller"
+ operationId: getWeatherByCity
+ parameters:
+ - name: city
+ in: query
+ description: "The city you want weather for in the form city,state,country"
+ required: true
+ type: "string"
+```
+
+Finally, implement the route's operation -- the `getWeatherByCity()` method in `api/controllers/weather.js` -- which calls the back-end service and returns the response.
+
+Here is the sample controller implementation for a weather API:
+
+```javascript
+'use strict';
+
+var util = require('util');
+var request = require('request');
+
+module.exports = {
+ getWeatherByCity: getWeatherByCity
+}
+
+function getWeatherByCity(req, res) {
+ var city = req.swagger.params.city.value;
+ var url = "http://api.openweathermap.org/data/2.5/weather?q="+city+"&units=imperial";
+ console.log('Executing request: '+url);
+ request.get(url).pipe(res);
+ };
+```
+
+In the case of this sample weather API, the controller calls the back-end service (the [OpenWeatherMap](http://openweathermap.org/) API). When you call the API like this:
+
+`curl http://localhost:10010/weather?city=Boulder,CO`
+
+The same response object that you previously modeled and tested in mock mode is filled in with the correct values:
+
+
+```json
+ {
+ "base": "cmc stations",
+ "clouds": {
+ "all": 40
+ },
+ "cod": 200,
+ "coord": {
+ "lat": 40.02,
+ "lon": -105.28
+ },
+ "dt": 1411077635,
+ "id": 5574991,
+ "main": {
+ "humidity": 27,
+ "pressure": 1016,
+ "temp": 87.62,
+ "temp_max": 91.99,
+ "temp_min": 80.01
+ },
+ "name": "",
+ "sys": {
+ "country": "United States of America",
+ "id": 538,
+ "message": 0.0175,
+ "sunrise": 1411044334,
+ "sunset": 1411088663,
+ "type": 1
+ },
+ "weather": [
+ {
+ "description": "scattered clouds",
+ "icon": "03d",
+ "id": 802,
+ "main": "Clouds"
+ }
+ ],
+ "wind": {
+ "deg": 160,
+ "speed": 7.78
+ }
+ }
+```
+
+
+
diff --git a/docs/modules.md b/docs/modules.md
new file mode 100644
index 00000000..0093ae81
--- /dev/null
+++ b/docs/modules.md
@@ -0,0 +1,69 @@
+## swagger modules and dependencies
+
+This topic briefly describes the relevant Node.js modules on which a swagger project depends.
+
+* [swagger](#swagger)
+* [skeleton](#skeleton)
+* [swagger-editor](#swagger-editor)
+* [swagger-tools](#swagger-tools)
+
+### swagger
+
+The `swagger` npm module provides everything you need to create new projects, including the Swagger editor, Swagger Tools middleware, sample project skeletons, and the `swagger` command-line tools.
+
+#### Installation
+For installation instructions, see "[Installation](./install.md)".
+
+#### Documentation
+
+The main source of documentation for the swagger module and related components is in the swagger-node repository on GitHub.
+
+#### Installation
+
+The swagger command-line tools are installed with swagger.
+
+#### Documentation
+
+[swagger command-line reference](./cli.md)
+
+
+### skeleton
+
+A basic, "hello world" swagger project. This project automatically cloned when you create a new swagger project by executing `swagger project create`. Skeleton projects are implemented for specific API frameworks, such as express, restify, or others.
+
+#### Documentation
+
+See the swagger "[Quick start](./quick-start.md)" to see how easy it is to get a new swagger API project up and running.
+
+### swagger-editor
+
+The Swagger Editor lets you design your API specification and interactively preview its documentation for your swagger API project.
+
+#### Installation
+
+Standard npm install. Installed with swagger.
+
+#### Documentation
+
+See "[Swagger Editor](https://github.com/swagger-api/swagger-editor)" on GitHub.
+
+### swagger-tools
+
+Middleware for Node.js including Message Validation, Authorization and Routing.
+
+#### Installation
+
+Standard npm install. Installed with swagger.
+
+#### Documentation
+
+See the `swagger-tools` [README](https://github.com/apigee-127/swagger-tools) on GitHub.
+
+
+#### Swagger Tools middleware components
+
+Swagger tools provides these middleware components. They provide services for message validation, authorization, and routing.
+
+* swagger-metadata
+* swagger-router
+* swagger-validator
diff --git a/docs/paramTypes.html b/docs/paramTypes.html
deleted file mode 100644
index d37cc811..00000000
--- a/docs/paramTypes.html
+++ /dev/null
@@ -1 +0,0 @@
- paramTypes.js
\ No newline at end of file
diff --git a/docs/quick-start.md b/docs/quick-start.md
new file mode 100644
index 00000000..162590e3
--- /dev/null
+++ b/docs/quick-start.md
@@ -0,0 +1,80 @@
+## Quick start
+
+Let's see how easily and quickly you can get a simple API up and running using swagger.
+
+* [Get an API up and running](#upandrunning)
+* [Check out the main Node.js app file](#main)
+* [Open the Swagger editor](#openeditor)
+* [Windows users](#windows)
+
+### Get an API up and running
+
+First, we create a new swagger project and test a simple "hello world" API.
+
+1. Install swagger, as described in the [installation guide](install.md).
+
+2. Create swagger project directory and cd to it. This is where you'll create your first project.
+
+3. Execute the project create command:
+
+ `swagger project create hello-world`
+
+4. Pick the API framework you want to use. We're going to pick express, but you can pick any of the listed frameworks:
+ ```
+ ? Framework? (Use arrow keys)
+ connect
+ ❯ express
+ hapi
+ restify
+ sails
+ ```
+ Note: You must enter the number of the option.
+
+5. swagger creates a skeleton project that's pre-configured to use your selected framework (in this example, Express). It then runs `npm install` to pick up the dependencies.
+
+ Note: Windows users see the [note below](#windows-note) regarding npm.
+
+6. Change to the new project directory: `cd hello-world`
+
+7. Type `swagger project start` to start your API. You now have an API running with swagger!
+
+8. In another terminal, run this command:
+
+ `curl http://127.0.0.1:10010/hello?name=Scott`
+
+ And, you'll get back the response `{ "message": "Hello, Scott!" }`.
+
+That's it - You have now created, started and tested your first API project with swagger!
+
+### Check out the main Node.js app file
+
+Open /app.js in an editor. This is the main Node.js app that installs middleware and requires the API framework that you chose when you created your project.
+
+The middleware modules perform tasks like OpenAPI Specification validation and endpoint routing. For more information, see [swagger modules and dependencies](./modules.md).
+
+### Open the Swagger editor
+
+The Swagger editor lets you design and test your API interactively. While you design and test, the API documentation is generated automatically for you.
+
+Now that we've got our basic API running, let's open the Swagger editor.
+
+1. Be sure you're in your project root directory: `./hello-world`.
+
+2. Fire up the editor: `swagger project edit`
+
+*The Swagger editor*
+
+
+### Running Swagger Node in a Deployment
+
+When you run a swagger-node based application in a proper deployment, you should use `node ` (typically, `node app.js`) as opposed to using the swagger cli tooling.
+
+### Windows users
+For some versions of npm on Windows will have problems on the `npm install` step of `swagger project create`. They are related to a `debug` module on npm not being managed properly. The following steps should resolve this issue:
+
+1. In the project directory, execute the following commands:
+ 1. `npm install yamljs`
+ 2. `npm install debug`
+ 3. `npm install swagger-tools`
+
+Now, when you run `swagger project start` your project should start successfully.
diff --git a/docs/release-notes.md b/docs/release-notes.md
new file mode 100644
index 00000000..717208be
--- /dev/null
+++ b/docs/release-notes.md
@@ -0,0 +1,34 @@
+## Release Notes
+
+### swagger-node 0.7.0, swagger-node-runner 0.5.0
+
+#### New features
+
+ * Request handing pipeline is now fully configurable
+ * Application configuration is now driven by the [config module](https://github.com/lorenwest/node-config/wiki/Configuration-Files) to allow a ton of flexibility in setting up configurations and routes based on environment.
+ * Supports plugins such as [volos-swagger-oauth](https://www.npmjs.com/package/volos-swagger-oauth) and [volos-swagger-apply](https://www.npmjs.com/package/volos-swagger-apply)
+ * Custom security handlers can be declared in config in app.js. Example:
+
+ ```javascript
+ config.swaggerSecurityHandlers = {
+ oauth2: function securityHandler1(req, authOrSecDef, scopesOrApiKey, cb) {
+ // your security code
+ cb();
+ }
+ };
+ ```
+
+#### Bug Fixes
+
+ * json_error_handler should work in all container environments (mapErrorsToJson did not)
+
+#### Breaking Changes
+
+ * `mapErrorsToJson` config option is now configured as an onError handler: `onError: json_error_handler`
+ * `docEndpoints` raw config option is now declared in Swagger and handled via a pipe: `swagger_raw`
+
+#### Converting From Previous Version
+
+ 1. Update your package.json to use the new middleware versions: "^0.1.0". (eg. `"swagger-express-mw": "^0.1.0"`)
+ 2. Update your application dependencies: `npm update`.
+ 3. Existing config should generally work, but you should update your config to the [new format](https://github.com/swagger-api/swagger-node/blob/master/docs/cli.md/configuration.md).
diff --git a/docs/report-issues.md b/docs/report-issues.md
new file mode 100644
index 00000000..e7782b72
--- /dev/null
+++ b/docs/report-issues.md
@@ -0,0 +1,14 @@
+
+
+## Reporting issues with swagger
+
+swagger is an open source project and we use GitHub issues for tracking problems with the code:
+
+### Swagger Editor
+**Issue Tracker:** https://github.com/wordnik/swagger-editor/issues
+
+### Swagger Tools
+**Issue Tracker:** https://github.com/apigee-127/swagger-tools/issues
+
+### Swagger Command Line
+**Issue Tracker:** https://github.com/swagger-api/swagger-node/issues
diff --git a/docs/swagger-about.md b/docs/swagger-about.md
new file mode 100644
index 00000000..e8f46400
--- /dev/null
+++ b/docs/swagger-about.md
@@ -0,0 +1,47 @@
+## About swagger
+
+* [What is Swagger?](#whatisswagger)
+* [How does the swagger module use Swagger?](#howdoes)
+* [Help me with YAML](#helpwith)
+* [Next step](#nextstep)
+
+
+### What is Swagger?
+
+[Swagger™ ](http://swagger.io) is a specification and framework implementation for describing, producing, consuming, and visualizing RESTful web services.
+
+To read more about Swagger, refer to:
+
+* [The Swagger website](http://swagger.io)
+* [Swagger on GitHub](https://github.com/swagger-api)
+
+
+### How does the swagger module use Swagger?
+
+The Swagger Editor lets you design your API specification and preview its documentation for your swagger API. The editor is installed with swagger.
+
+A swagger.yaml file is installed into every new swagger project, and lives in `/api/swagger/swagger.yaml`. It conforms to the [OpenAPI 2.0 Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).
+
+Behind the scenes, Swagger middleware validates and processes the Swagger configuration file, and routes API operation endpoints to controller files. All **you** need to do is implement your custom API controller logic.
+
+>Note: The editor is served locally and automatically saves your work *as you edit*. In addition, if the project is running (`swagger project start`), it is automatically restarted each time the editor saves. Just be careful if you kill the editor, that you do not lose unsaved work.
+
+**Try it:**
+
+1. `swagger project create test-project`
+2. `cd test-project`
+2. `swagger project edit`
+
+*The Swagger editor*
+
+
+
+### Help me with YAML
+
+YAML is a data serialization/representation standard. If you're new to YAML, check out [www.yaml.org](http://www.yaml.org). Another excellent introduction is the [Wikipedia YAML entry](http://en.wikipedia.org/wiki/YAML).
+
+YAML is intended to be easy for humans to read. Every swagger project includes a Swagger 2.0 compliant configuration file that is written in YAML.
+
+### Next step
+
+For a more detailed look the Swagger configurations, see "[The OpenAPI Specification file](./swagger-file.md)".
diff --git a/docs/swagger-config.png b/docs/swagger-config.png
deleted file mode 100644
index f42b56e4..00000000
Binary files a/docs/swagger-config.png and /dev/null differ
diff --git a/docs/swagger-file.md b/docs/swagger-file.md
new file mode 100644
index 00000000..2f12da62
--- /dev/null
+++ b/docs/swagger-file.md
@@ -0,0 +1,84 @@
+## Understanding the OpenAPI Specification file
+
+* [Intro](#intro)
+* [Default swagger project file](#default)
+* [OpenAPI Specification elements](#reference)
+
+### Intro
+
+When you execute `swagger project create myproject`, a default Swagger model is placed in `myproject/api/swagger/swagger.yaml`. This model conforms to the [OpenAPI 2.0 Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).
+
+>Note: For a quick intro to swagger, see "[What is Swagger](./swagger-about.md)".
+
+### Default swagger project file
+
+Here is the entire `swagger.yaml` file that is provisioned for a new swagger project:
+
+```yaml
+ swagger: "2.0"
+ info:
+ version: "0.0.1"
+ title: Hello World App
+ # during dev, should point to your local machine
+ host: localhost
+ # basePath prefixes all resource paths
+ basePath: /
+ #
+ schemes:
+ # tip: remove http to make production-grade
+ - http
+ - https
+ # format of bodies a client can send (Content-Type)
+ consumes:
+ - application/json
+ # format of the responses to the client (Accepts)
+ produces:
+ - application/json
+ paths:
+ /hello:
+ # binds swagger app logic to a route
+ x-swagger-router-controller: hello_world
+ get:
+ description: Returns 'Hello' to the caller
+ # used as the method name of the controller
+ operationId: hello
+ parameters:
+ - name: name
+ in: query
+ description: The name of the person to whom to say hello
+ required: false
+ type: string
+ responses:
+ "200":
+ description: Success
+ schema:
+ # a pointer to a definition
+```
+
+
+### OpenAPI Specification elements
+
+The Swagger file includes a number of standard OpenAPI 2.0 Specification elements. You can read about them in the [OpenAPI 2.0 Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).
+
+Here's a brief description of the elements in a swagger project file:
+
+* **swagger: 2.0** - (Required) Identifies the version of the OpenAPI Specification (2.0).
+
+* **info:** - (Required) Provides metadata about the API.
+
+* **host:** - (Optional) The host serving the API. By default, a new project connects to a server running locally on port 10010.
+
+* **basePath:** - (Optional) The base path on which the API is served, which is relative to the host.
+
+* **schemes:** - (Optional) A list of transfer protocol(s) of the API.
+
+* **consumes:** - (Optional) A list of MIME types the APIs can consume.
+
+* **produces:** - (Optional) A list of MIME types the APIs can produce.
+
+* **paths:** - (Required) Defines the available operations on the API. You'll spend most of your time configuring the paths part of the file. You can read about the path element in the [OpenAPI 2.0 Specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md). In general, the paths section specifies an operation's verb (like `get`), the endpoint for an API operation (like `/hello`), query parameters, and responses.
+
+* **definitions:** - (Optional) These represent the structure of complex objects such as request and response bodies. For example, you might have a collection of `/users` that returns an array of `user` objects. You would describe these with two definitions: 1) to describe the `User` object, and 2) the definition of the `Users` array. Swagger uses [JSON-schema](http://json-schema.org/).
+
+* **x-swagger-router-controller:** - (Optional) This extension specifies the name of the controller file (hello_world.js) that will execute when this API operation is called. Controller files reside in `apis/controllers` in your swagger project. This extension is provided through the [`swagger-tools`](https://github.com/apigee-127/swagger-tools) middleware module.
+
diff --git a/docs/swagger.html b/docs/swagger.html
deleted file mode 100644
index 244d2f23..00000000
--- a/docs/swagger.html
+++ /dev/null
@@ -1,388 +0,0 @@
- swagger.js