Package Exports
- @flitz/swagger
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@flitz/swagger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@flitz/swagger
Sets up a flitz instance serving Swagger UI.
Install
Run
npm install --save @flitz/swaggerfrom 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:
- js-yaml by Nodeca
- swagger-ui-dist by Swagger
License
MIT © Marcel Kloubert