# fastify-swagger-generate

> Generate Swagger/OpenAPI definition objects for fastify routes

Latest version **0.1.3** (published 2022-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-swagger-generate
pnpm add fastify-swagger-generate
yarn add fastify-swagger-generate
bun add fastify-swagger-generate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2022-12-22 |
| First published | 2022-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 43.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Manjunath Desappa - @manju4ever |
| Maintainers | manju4ever |
| Keywords | fastify, swagger, openapi, generate, static, static spec |

## Links

- npm: https://www.npmjs.com/package/fastify-swagger-generate
- Repository: https://github.com/manju4ever/fastify-swagger-generate
- Homepage: https://github.com/fastify/fastify-swagger#readme
- Issues: https://github.com/manju4ever/fastify-swagger-generate/issues
- npm.io page: https://npm.io/package/fastify-swagger-generate

## Dependencies (2)

- [openapi-types](https://npm.io/package/openapi-types.md) ^10.0.0
- [json-schema-resolver](https://npm.io/package/json-schema-resolver.md) ^1.3.0

## Recent versions

- 0.1.3 (latest) — 2022-12-22
- 0.1.3-0 (next) — 2022-12-22
- 0.1.2 — 2022-12-05
- 0.1.2-0 — 2022-12-04
- 0.1.1 — 2022-12-04
- 0.1.1-0 — 2022-12-04

## README

# fastify-swagger-generate

Generate Swagger/OpenAPI definitions without running fastify app !

<!-- toc -->

- [fastify-swagger-generate](#fastify-swagger-generate)
  - [Install](#install)
  - [Disclaimer](#disclaimer)
  - [Usage](#usage)
  - [API](#api)
    - [Options](#options)

<!-- tocstop -->

## 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)

---
_Source: https://npm.io/package/fastify-swagger-generate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
