1.0.13 • Published 7 years ago

swaggernaut v1.0.13

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

Swaggernaut

Automated swagger documentation generator created for micro using microrouter.

More documentation to come, example usage found at ./src/test-spec.js.

/**
 * Test for example use case
 */
import pkg from '../package.json'
import micro from 'micro'
import * as swaggernaut from './index'

// Create a definition, a reference path is returned
const TestResponse = swaggernaut.define('TestResponse', {
  type: 'string'
})
// -- or --
// const TestResponse = swaggernaut.define('TestResponse')({
//   type: 'string'
// })

// Create a spec (all functions are curried)
const testDoc = swaggernaut.document({
  description: 'Get on a simple test routes',
  responses: {
    200: {
      description: 'Congrats you did it',
      schema: {
        // Use definition reference
        $ref: TestResponse
      }
    }
  }
})

// Create a route map
const routes = new swaggernaut.RouteMap([
  // Define a route with Iterable or swaggernaut.Route
  // Wrap handler function with documentation
  ['/test', testDoc((req, res) => 'You did it')],

  // default method is 'get' but can be on of
  // get, post, put, path, delete, head, options
  ['post', '/test', testDoc((req, res) => 'You posted it')],

  // Example use of swagger route (validates input and returns array like above)
  swaggernaut.Route('/another', () => 'another put route'),
  swaggernaut.Route('put', '/another', () => 'another put route')
])

// Add route to existing map (posible for environment logic)
routes.add(
  // Dont document swagger generate doc handler because that
  // that would be silly.
  swaggernaut.Route(
    '/swagger.json',
    swaggernaut.generateDoc(swaggernaut.packageToSpec(pkg), routes)
  )
)

// Start http.Server
micro(routes.router).listen(3000, () =>
  console.log('server is online at http://localhost:3000')
)
1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago