# swagger-converter

> Converts Swagger documents from version 1.x to version 2.0

Latest version **2.1.0** (published 2021-02-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install swagger-converter
pnpm add swagger-converter
yarn add swagger-converter
bun add swagger-converter
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2021-02-16 |
| First published | 2014-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.x |
| Dependencies | 1 |
| Unpacked size | 37.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Mohsen Azimi |
| Maintainers | swagger, mohsen, i1g |
| Keywords | OAS, OpenAPI, Swagger, converter, API |

## Links

- npm: https://www.npmjs.com/package/swagger-converter
- Repository: https://github.com/apigee-127/swagger-converter
- Issues: https://github.com/apigee-127/swagger-converter/issues
- npm.io page: https://npm.io/package/swagger-converter

## Dependencies (1)

- [urijs](https://npm.io/package/urijs.md) ^1.19.6

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2021-02-16
- 2.0.0 — 2020-12-03
- 1.5.1 — 2019-01-28
- 1.4.4 — 2018-05-03
- 1.4.1 — 2016-03-30
- 1.4.0 — 2016-03-14
- 1.3.0 — 2016-03-09
- 1.2.0 — 2016-02-25
- 1.1.0 — 2015-12-06
- 1.0.1 — 2015-11-09
- 1.0.0 — 2015-11-09
- 0.2.0 — 2015-09-29
- 0.1.7 — 2015-06-15
- 0.1.6 — 2015-06-15
- 0.1.5 — 2015-06-08
- … 10 more at https://npm.io/package/swagger-converter/versions

## README

# Swagger Converter

[![NPM version][npm-image]][npm-link]
[![Build status][actions-image]][actions-link]
[![Coverage Status][codecov-image]][codecov-link]
[![Dependency status][deps-image]][deps-link]
[![devDependency status][devdeps-image]][devdeps-link]

[![Join the chat at https://gitter.im/apigee-127/swagger-converter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/apigee-127/swagger-converter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

> Converts [Swagger](http://swagger.io/) documents from version **`1.x`** to version **`2.0`**

### Installation

Use npm

```shell
npm install swagger-converter --save
```

### Usage

It's recommended to use command line tools like [**`swagger-tools`**][swagger-tools-npm] or [**`swagger-spec-converter`**][swagger-spec-converter] for converting your spec. This module will not handle validation and if your spec is not valid can produce invalid spec.

##### convert function

`convert` accept accept following arguments:

- `resourceListing`(required) is Swagger 1.x entry point file.
- `apiDeclarations`(required) is a map with paths from `resourceListing` as keys and resources as values
- `options`(optional) - See [options](#options) for the full list of options

```javascript
var swaggerConverter = require('swagger-converter');

var resourceListing = require('/path/to/petstore/index.json');

var apiDeclarations = {
  '/pet': require('/path/to/petstore/pet.json'),
  '/user': require('/path/to/petstore/user.json'),
  '/store': require('/path/to/petstore/store.json'),
};

var swagger2Document = swaggerConverter.convert(
  resourceListing,
  apiDeclarations,
);

console.log(JSON.stringify(swagger2Document, null, 2));
```

##### listApiDeclarations function

`listApiDeclarations` function accept following arguments:

- `sourceUrl`(required) - source URL for root Swagger 1.x document
- `resourceListing`(required) - root Swagger 1.x document

```javascript
var swaggerConverter = require('swagger-converter');

var resourceListing = require('/path/to/petstore/index.json');

var apiDeclarations = swaggerConverter.listApiDeclarations(
  'http://test.com/api-docs',
  resourceListing,
);

console.log(JSON.stringify(apiDeclarations, null, 2));
/*
{
  "/pet": "http://test.com/api-docs/pet",
  "/user": "http://test.com/api-docs/user",
  "/store": "http://test.com/api-docs/store"
}
*/
```

### Options

- `collectionFormat`[string] - assigned to every array parameter.
- `buildTagsFromPaths`[bool] - ignore `resourcePath` and buid tags from resource `path`. Default: false.

### Development

Install dependencies with `npm install` command and use `npm test` to run the test. Tests will fail if you break coding style.

##### Building for browser

Just run this command to make a new `browser.js`

```
npm run build
```

### License

MIT. See [LICENSE](./LICENSE)

[npm-image]: https://img.shields.io/npm/v/swagger-converter.svg?style=flat
[npm-link]: https://npmjs.org/package/swagger-converter
[actions-image]: https://github.com/apigee-127/swagger-converter/workflows/CI/badge.svg?branch=master
[actions-link]: https://github.com/apigee-127/swagger-converter/actions?query=branch%3Amaster
[codecov-image]: https://codecov.io/gh/apigee-127/swagger-converter/branch/master/graph/badge.svg
[codecov-link]: https://codecov.io/gh/apigee-127/swagger-converter
[deps-image]: https://img.shields.io/david/apigee-127/swagger-converter.svg?style=flat
[deps-link]: https://david-dm.org/apigee-127/swagger-converter
[devdeps-image]: https://img.shields.io/david/dev/apigee-127/swagger-converter.svg?style=flat
[devdeps-link]: https://david-dm.org/apigee-127/swagger-converter#info=devDependencies
[swagger-tools-npm]: https://www.npmjs.com/package/swagger-tools
[swagger-spec-converter]: https://github.com/lucybot/api-spec-converter

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