0.1.7 • Published 4 years ago

@flitz/swagger v0.1.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

npm supported flitz version last build PRs Welcome

@flitz/swagger

Sets up a flitz instance serving Swagger UI.

Install

Run

npm install --save @flitz/swagger

from the folder, where your package.json is stored.

Usage

const flitz = require('flitz');
const swagger = require('@flitz/swagger');

const run = async () => {
  const app = flitz();

  // UI will be available at http://localhost:3000/swagger in browser
  //
  // you can download the document via:
  //   * JSON: http://localhost:3000/swagger/json
  //   * YAML: http://localhost:3000/swagger/yaml
  swagger(app, {
    // s. https://swagger.io/docs/
    document: {
      "openapi": "3.0.0",
      "info": {
        "title": "Sample API",
        "description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
        "version": "0.1.9"
      },
      "servers": [
        {
          "url": "http://api.example.com/v1",
          "description": "Optional server description, e.g. Main (production) server"
        },
        {
          "url": "http://staging-api.example.com",
          "description": "Optional server description, e.g. Internal staging server for testing"
        }
      ],
      "paths": {
        "/users": {
          "get": {
            "summary": "Returns a list of users.",
            "description": "Optional extended description in CommonMark or HTML.",
            "responses": {
              "200": {
                "description": "A JSON array of user names",
                "content": {
                  "application/json": {
                    "schema": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  });

  await app.listen(3000);
};

run();

Or the TypeScript way:

import flitz from 'flitz';
import { swagger } from '@flitz/swagger';

const run = async () => {
  const app = flitz();

  // UI will be available at http://localhost:3000/swagger in browser
  swagger(app, {
    document: { /* https://swagger.io/docs/ */ }
  });

  await app.listen(3000);
};

run();

TypeScript

TypeScript is optionally supported. The module contains its own definition files.

Credits

The module makes use of:

License

MIT © Marcel Kloubert