Skip to content

Commit

Permalink
Swagger stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Luce authored and dougluce committed Dec 20, 2015
1 parent 62aaedd commit 271e987
Show file tree
Hide file tree
Showing 39 changed files with 27,168 additions and 21 deletions.
56 changes: 36 additions & 20 deletions lib/api.ls
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ require! {
'prelude-ls': {map}
fs
npid
'swagger-doc'
'node-restify-validation': restifyValidation
'node-restify-swagger': restifySwagger
}

errors =
Expand Down Expand Up @@ -42,12 +43,7 @@ resolve = (params, facts) ->
return newparams

makeroutes = (server, logger) ->
swaggerDoc.configure server, do
version: "0.1"
basePath: 'localhost:8080'
docs = swaggerDoc.createResource "/swag"
for commandname, command of commands

if command.params
httpparams = []
for param in command.params
Expand All @@ -72,15 +68,19 @@ makeroutes = (server, logger) ->

params = ht.map( (x) -> \: + x ).join '/'
params := '/' + params if params
server.get "/#commandname#params" handler
server.post "/#commandname" handler

# docs.get "/#commandname#params", "Does something", do
# notes: "Notes right here"
# nickname: "Nick right here"
# parameters:
# {name:"id", description: "Id of payment", required:true, dataType: "string", paramType: "path"}

docparams = {}
for parm in cm.params
docparams[parm.name] = parm
server.get do
url: "/#commandname#params"
swagger:
description: 'descripton'
notes: 'My hello call notes'
nickname: 'sayHelloCall'
validation: docparams
, handler
server.post "/#commandname" handler

web_proxy = (req, res, next) ->
res.setHeader
Expand All @@ -99,9 +99,31 @@ export init = (server, logobj) ->
logger = logobj
server.use setHeader
server.use restify.bodyParser!
server.use restify.CORS!
server.use restify.fullResponse!
server.use restifyValidation.validationPlugin errorsAsArray: false
restifySwagger.configure server, do
info:
contact: '[email protected]'
description: 'Description text'
license: 'MIT'
licenseUrl: 'http://opensource.org/licenses/MIT'
termsOfServiceUrl: 'http://opensource.org/licenses/MIT'
title: 'Node Restify Swagger Demo'
apiDescriptions:
get: 'GET-Api Resources'
post: 'POST-Api Resources'

server.get /^(|\/|\/index.html|\/w.*)$/ web_proxy
commands.init!
makeroutes server, logger
restifySwagger.loadRestifyRoutes!

server.get /^\/docs\/?.*/ restify.serveStatic directory: './swagger-ui'
server.get '/docs', (req, res, next) ->
res.header 'Location' '/docs/index.html'
res.send 302
next false
req, res, route, err <- server.on 'uncaughtException'
throw err

Expand Down Expand Up @@ -166,12 +188,6 @@ export standalone = ->

init server, logger

# sre.init server, do
# resourceName: 'swag'
# server: 'restify'
# httpMethods: ['GET', 'POST']
# basePath: 'http://localhost:8080'

<- server.listen if is_prod then 80 else 8080
cli.start_upgrader server # Allow upgrades to CLI
logger.info '%s listening at %s', server.name, server.url
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
"dtrace-provider": "^0.4.0",
"ipv6": "^3.1.1",
"ipware": "0.0.5",
"node-restify-swagger": "^0.1.8",
"node-restify-validation": "^1.0.4",
"npid": "^0.4.0",
"prelude-ls": "^1.1.1",
"request": "^2.55.0",
"restify": "^3.0.2",
"swagger-doc": "^0.2.0"
"swagger-doc": "^0.2.0",
"swagger-ui": "^2.1.4-M2"
},
"devDependencies": {
"benchmark": "^1.0.0",
Expand Down
Loading

0 comments on commit 271e987

Please sign in to comment.