Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)