diff --git a/.eslintignore b/.eslintignore index a629ef76..d4fab12d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,2 @@ **/node_modules -lib/swagger-ui +lib/swagger-ui \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 8d6a6816..cd390207 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,4 +6,4 @@ "no-use-before-define": [2, "nofunc"], "quotes": [2, "single"] } -} +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 646ac519..58b805fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .DS_Store -node_modules/ +node_modules/ \ No newline at end of file diff --git a/.npmignore b/.npmignore index b6c79547..cc0b317e 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,3 @@ .DS_Store .git* -example/ +example/ \ No newline at end of file diff --git a/example/app.js b/example/app.js index f9e555f5..bc643cd0 100644 --- a/example/app.js +++ b/example/app.js @@ -1,26 +1,26 @@ 'use strict'; var express = require('express'), - routes = require('./routes'), - swagger = require('..'); + routes = require('./routes'), + swagger = require('..'); var app = express(); swagger.init(app, { - apiDocs: '/api.json', - swaggerUi: '/api', - info: { - title: 'Hello World', - version: '1.0.0' - }, - apis: ['./routes.js'] + apiDocs: '/api.json', + swaggerUi: '/api', + info: { + title: 'Hello World', + version: '1.0.0' + }, + apis: ['./routes.js'] }); routes.setup(app); var server = app.listen(3000, function () { - var host = server.address().address; - var port = server.address().port; + var host = server.address().address; + var port = server.address().port; - console.log('Example app listening at http://%s:%s', host, port); -}); + console.log('Example app listening at http://%s:%s', host, port); +}); \ No newline at end of file diff --git a/example/routes.js b/example/routes.js index 583de5c2..8bb2d93d 100644 --- a/example/routes.js +++ b/example/routes.js @@ -6,17 +6,17 @@ */ module.exports.setup = function (app) { - /** - * @swagger + /** + * @swagger * /: * get: * responses: * 200: * description: hello world - */ - app.get('/', rootHandler); + */ + app.get('/', rootHandler); - /** + /** * @swagger * /login: * post: @@ -24,7 +24,7 @@ module.exports.setup = function (app) { * 200: * description: login */ - app.get('/login', loginHandler); + app.get('/login', loginHandler); }; function rootHandler(req, res) { @@ -32,8 +32,8 @@ function rootHandler(req, res) { } function loginHandler(req, res) { - var user = {}; - user.username = req.param('username'); - user.password = req.param('password'); - res.json(user); -} + var user = {}; + user.username = req.param('username'); + user.password = req.param('password'); + res.json(user); +} \ No newline at end of file diff --git a/index.js b/index.js index bb0a047c..4cc88b35 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -module.exports = require('./lib'); +module.exports = require('./lib'); \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index a19c2f63..d5871468 100644 --- a/lib/index.js +++ b/lib/index.js @@ -70,8 +70,7 @@ function parseApiFile(file) { if (fileExtension === '.js') { parseJsFile(file); - } - else { + } else { throw new Error('Unsupported extension \'' + fileExtension + '\'.'); } } @@ -81,7 +80,9 @@ function parseApiFile(file) { * @param {string} file - File to parse */ function parseJsFile(file) { - var sourceCode = fs.readFileSync(file, { encoding: 'utf8' }); + var sourceCode = fs.readFileSync(file, { + encoding: 'utf8' + }); var jsDocComments = parseJsDoc(sourceCode); var swaggerJsDocComments = filterSwaggerTags(jsDocComments); @@ -110,7 +111,9 @@ function parseJsDoc(jsSourceCode) { if (fragments) { for (var i = 0; i < fragments.length; i++) { var fragment = fragments[i]; - var jsDoc = doctrine.parse(fragment, { unwrap: true }); + var jsDoc = doctrine.parse(fragment, { + unwrap: true + }); jsDocs.push(jsDoc); } } @@ -137,4 +140,4 @@ function filterSwaggerTags(jsDocs) { } return swaggerJsDocs; -} +} \ No newline at end of file diff --git a/swagger-example.json b/swagger-example.json index 3a53115a..01a650ba 100644 --- a/swagger-example.json +++ b/swagger-example.json @@ -1,226 +1,224 @@ { - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "Swagger Petstore", - "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", - "termsOfService": "http://swagger.io/terms/", - "contact": { - "name": "Swagger API Team" + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team" + }, + "license": { + "name": "MIT" + } }, - "license": { - "name": "MIT" - } - }, - "host": "petstore.swagger.io", - "basePath": "/api", - "schemes": [ + "host": "petstore.swagger.io", + "basePath": "/api", + "schemes": [ "http" ], - "consumes": [ + "consumes": [ "application/json" ], - "produces": [ + "produces": [ "application/json" ], - "paths": { - "/pets": { - "get": { - "description": "Returns all pets from the system that the user has access to", - "operationId": "findPets", - "produces": [ + "paths": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to", + "operationId": "findPets", + "produces": [ "application/json", "application/xml", "text/xml", "text/html" ], - "parameters": [ - { - "name": "tags", - "in": "query", - "description": "tags to filter by", - "required": false, - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv" + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv" }, - { - "name": "limit", - "in": "query", - "description": "maximum number of results to return", - "required": false, - "type": "integer", - "format": "int32" + { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" } ], - "responses": { - "200": { - "description": "pet response", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Pet" - } - } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/ErrorModel" - } - } - } - }, - "post": { - "description": "Creates a new pet in the store. Duplicates are allowed", - "operationId": "addPet", - "produces": [ + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "produces": [ "application/json" ], - "parameters": [ - { - "name": "pet", - "in": "body", - "description": "Pet to add to the store", - "required": true, - "schema": { - "$ref": "#/definitions/PetInput" - } + "parameters": [ + { + "name": "pet", + "in": "body", + "description": "Pet to add to the store", + "required": true, + "schema": { + "$ref": "#/definitions/PetInput" + } } ], - "responses": { - "200": { - "description": "pet response", - "schema": { - "$ref": "#/definitions/Pet" - } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/ErrorModel" + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } } - } - } - } - }, - "/pets/{id}": { - "get": { - "description": "Returns a user based on a single ID, if the user does not have access to the pet", - "operationId": "findPetById", - "produces": [ + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "findPetById", + "produces": [ "application/json", "application/xml", "text/xml", "text/html" ], - "parameters": [ - { - "name": "id", - "in": "path", - "description": "ID of pet to fetch", - "required": true, - "type": "integer", - "format": "int64" + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "type": "integer", + "format": "int64" } ], - "responses": { - "200": { - "description": "pet response", - "schema": { - "$ref": "#/definitions/Pet" - } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/ErrorModel" - } - } - } - }, - "delete": { - "description": "deletes a single pet based on the ID supplied", - "operationId": "deletePet", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "ID of pet to delete", - "required": true, - "type": "integer", - "format": "int64" + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "type": "integer", + "format": "int64" } ], - "responses": { - "204": { - "description": "pet deleted" - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/definitions/ErrorModel" + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/ErrorModel" + } + } + } } - } } - } - } - }, - "definitions": { - "Pet": { - "required": [ + }, + "definitions": { + "Pet": { + "required": [ "id", "name" ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } }, - "tag": { - "type": "string" - } - } - }, - "PetInput": { - "allOf": [ - { - "$ref": "#/definitions/Pet" + "PetInput": { + "allOf": [ + { + "$ref": "#/definitions/Pet" }, - { - "required": [ + { + "required": [ "name" ], - "properties": { - "id": { - "type": "integer", - "format": "int64" - } - } + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } } ] - }, - "ErrorModel": { - "required": [ + }, + "ErrorModel": { + "required": [ "code", "message" ], - "properties": { - "code": { - "type": "integer", - "format": "int32" - }, - "message": { - "type": "string" + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } } - } } - } -} -Status API Training Shop Blog About -© 2015 GitHub, Inc. Terms Privacy Security Contact +} \ No newline at end of file