forked from swagger-api/swagger-node
-
Notifications
You must be signed in to change notification settings - Fork 15
/
package.json
executable file
·47 lines (47 loc) · 5.61 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
"name": "swagger-node-restify",
"version": "0.1.2",
"author": {
"name": "Nicolas Mathon",
"email": "nicolas.mathon@gmail.com",
"url": "http://www.early-birds.fr"
},
"contributors": [
{
"name": "Pauh Hill",
"email": "phill@kixeye.com"
}
],
"description": "Wordnik swagger implementation for the restify framework (initially forked from the excellent package written by Tony Tam : https://github.com/wordnik/swagger-node-express)",
"repository": {
"type": "git",
"url": "https://github.com/tmsw/swagger-node-restify"
},
"keywords": [
"http",
"rest",
"swagger",
"server"
],
"main": "index.js",
"directories": {
"lib": "./Common/node"
},
"engines": {
"node": ">= 0.8.x"
},
"dependencies": {
"connect": ">= 1.8.x",
"restify": ">= 2.5.x",
"docco": "0.4.x",
"lodash": "1.3.1"
},
"license": "apache 2.0",
"readme": "This is the Wordnik Swagger code for the restify framework. It's a fork of https://github.com/wordnik/swagger-node-express.git with some fixes to work with Restify. \nFor more on Swagger, please visit http://swagger.wordnik.com. \nFor more on restify, please visit http://mcavage.me/node-restify\n\n## READ MORE about swagger!\n\nSee the [swagger website](http://swagger.wordnik.com) or the [swagger-core wiki](https://github.com/wordnik/swagger-core/wiki), which contains information about the swagger json spec.\n\nTry a sample! The source for a [functional sample](https://github.com/tmsw/swagger-node-restify/blob/master/README.md) is available on github:\n\n\n\n### Adding swagger to your restify-based API\n\nInclude swagger.js in your app and add restify as the app handler:\n\n```js\nvar restify = require(\"restify\")\n , url = require(\"url\")\n , swagger = require(\"swagger-node-restify\");\n\nvar server = restify.createServer();\nserver.use(restify.bodyParser());\nrestify.defaultResponseHeaders = function(data) {\n this.header('Access-Control-Allow-Origin', '*');\n};\n\nswagger.setAppHandler(server);\n```\n\nYou can optionally add a validator function, which is used to filter the swagger json and request operations:\n\n```js\n// This is a sample validator. It simply says that for _all_ POST, DELETE, PUT methods, \n// the header api_key OR query param api_key must be equal to the string literal \n// special-key. All other HTTP ops are A-OK */\n\nswagger.addValidator(\n function validate(req, path, httpMethod) {\n // example, only allow POST for api_key=\"special-key\"\n if (\"POST\" == httpMethod || \"DELETE\" == httpMethod || \"PUT\" == httpMethod) {\n var apiKey = req.headers[\"api_key\"];\n if (!apiKey) {\n apiKey = url.parse(req.url,true).query[\"api_key\"]; }\n if (\"special-key\" == apiKey) {\n return true; \n }\n return false;\n }\n return true;\n }\n);\n\n```\n\nYou 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:\n\n```js\nswagger.addModels(models);\n\n```\n\nNext, 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:\n\n\n```js\nvar findById = {\n 'spec': {\n \"description\" : \"Operations about pets\",\n \"path\" : \"/pet.{format}/{petId}\",\n \"notes\" : \"Returns a pet based on ID\",\n \"summary\" : \"Find pet by ID\",\n \"method\": \"GET\",\n \"params\" : [swagger.pathParam(\"petId\", \"ID of pet that needs to be fetched\", \"string\")],\n \"responseClass\" : \"Pet\",\n \"errorResponses\" : [swagger.errors.invalid('id'), swagger.errors.notFound('pet')],\n \"nickname\" : \"getPetById\"\n },\n 'action': function (req,res) {\n if (!req.params.petId) {\n throw swagger.errors.invalid('id'); }\n var id = parseInt(req.params.petId);\n var pet = petData.getPetById(id);\n\n if(pet) res.send(JSON.stringify(pet));\n else throw swagger.errors.notFound('pet');\n }\n};\n\nswagger.addGet(findById);\n\n```\n\nAdds an API route to restify and provides all the necessary information to swagger.\n\nFinally, configure swagger with a `public` URL and version:\n\n```js\nswagger.configure(\"http://petstore.swagger.wordnik.com\", \"0.1\");\n```\n\nand the server can be started:\n\n```js\napp.listen(8002);\n```\n\nNow 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.\n\n\n### Other Configurations\n\n#### .{format} suffix removal\n\nIf you don't like the .{format} or .json suffix, you can override this before configuring swagger:\n\n```js\nswagger.configureSwaggerPaths(\"\", \"/api-docs\", \"\");\n```\n\nThat 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:\n\n```js\n// note the .{format} is removed from the path!\nvar findById = {\n 'spec': {\n \"description\" : \"Operations about pets\",\n \"path\" : \"/pet/{petId}\",\n \"notes\" : \"Returns a pet based on ID\",\n ...\n```",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/tmsw/swagger-node-restify/issues"
},
"_id": "swagger-node-restify@0.1.1",
"_from": "swagger-node-restify@>= 0.0.1"
}