Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wirgen/fastify-openapi-generator
Generate API with fastify by OpenAPI specs
https://github.com/wirgen/fastify-openapi-generator
fastify generator openapi swagger
Last synced: 24 days ago
JSON representation
Generate API with fastify by OpenAPI specs
- Host: GitHub
- URL: https://github.com/wirgen/fastify-openapi-generator
- Owner: wirgen
- License: apache-2.0
- Created: 2019-08-31T01:06:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-18T15:55:45.000Z (about 2 months ago)
- Last Synced: 2024-10-13T17:22:04.035Z (about 1 month ago)
- Topics: fastify, generator, openapi, swagger
- Language: JavaScript
- Homepage:
- Size: 378 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-openapi-generator
Fastify routes generator. Used [Swagger](https://swagger.io/) YAML specification. Supports schemas for describe models and validate response.
Supports Fastify versions `>=2.0.0`.
## Install
```shell script
npm i fastify-openapi-generator --save
```
## Usage
Add it to your project with `register` and pass it some basic options, then call the `swagger` api and you are done!```JS
const fastify = require("fastify")();fastify.register(require("fastify-openapi-generator"), {
controllers: require("./controllers"),
routeDocs: "/docs/",
yaml: "swagger.yaml",
template: "swagger.html",
});
```
### register options
#### controllers
Array of handlers for fastify routes. Describe handlers in `operationId` with pattern `.`. For example, you can collect all controllers from folder used `fs`:
```js
const fs = require("fs");
const path = require("path");
const basename = path.basename(__filename);let controllers = {};
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf(".") !== 0) && file !== basename && (file.slice(-3) === ".js");
})
.forEach(file => {
controllers[file.slice(0, -3)] = require(path.join(__dirname, file));
});module.exports = controllers;
```
#### routeDocs
Prefix for swagger documentation. By default, `/docs`. Also, you can get JSON (`/docs/json`) and YAML (`/docs/yaml`) files.
#### yaml
Path for swagger specification file in YAML. By default, `swagger.yaml`.
#### template
Path for custom html template for [Swagger](https://swagger.io/). As start point you can copy `swagger.html` from plugin.
### Security
Global security definitions and route level security provide documentation only. It does not implement authentication nor route security for you. Once your authentication is implemented, along with your defined security, users will be able to successfully authenticate and interact with your API using the user interfaces of the documentation.Licensed under [Apache 2.0](./LICENSE).