Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manju4ever/fastity-swagger-generate
Generate Swagger or OpenAPI Specification (JSON/YML) for Fastify server routes without running the server
https://github.com/manju4ever/fastity-swagger-generate
fastify fastify-swagger openapi-spec swagger-api swagger-docs
Last synced: 6 days ago
JSON representation
Generate Swagger or OpenAPI Specification (JSON/YML) for Fastify server routes without running the server
- Host: GitHub
- URL: https://github.com/manju4ever/fastity-swagger-generate
- Owner: manju4ever
- License: mit
- Created: 2022-03-29T17:56:37.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-22T14:50:31.000Z (about 2 years ago)
- Last Synced: 2024-10-12T01:10:40.876Z (3 months ago)
- Topics: fastify, fastify-swagger, openapi-spec, swagger-api, swagger-docs
- Language: JavaScript
- Homepage:
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-swagger-generate
Generate Swagger/OpenAPI definitions without running fastify app !
- [fastify-swagger-generate](#fastify-swagger-generate)
- [Install](#install)
- [Disclaimer](#disclaimer)
- [Usage](#usage)
- [API](#api)
- [Options](#options)## Install
`npm i fastify-swagger-generate`
## Disclaimer
- Only supports configuration based routes, i.e collection of route definitions
- This library has no new content added
- This library has just tweaked the original [fastify-swagger](https://github.com/fastify/fastify-swagger)## Usage
1. Create a `generate.js` file which looks like
```javascript
const fastifySwagGen = require("fastify-swagger-generate");
const Routes = require("./routes");
const opts = {};// generate swagger definitions
fastifySwagGen(opts, Routes, (err, definitions) => {
// Write to a file
require("fs")
.createWriteStream("./app.swag.json")
.write(JSON.stringify(definitions));
});
```2. Let's say you have routes defined in `routes.js`
```javascript
const routes = [
{
url: "/users/:id",
method: "GET",
schema: {
params: {
type: "object",
properties: {
id: {
type: "number",
},
},
},
},
},
];module.exports = routes; // should be an iterable routes
```## API
### Options
[Refer here for more](https://github.com/fastify/fastify-swagger#register-options)