# openapi-json-schema

> Minimalistic OpenAPI 3 ⬌ JSON Schema (draft 7) conversion

Latest version **2.0.0** (published 2023-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install openapi-json-schema
pnpm add openapi-json-schema
yarn add openapi-json-schema
bun add openapi-json-schema
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2023-02-02 |
| First published | 2021-02-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.13.1 \|\| >= 16 |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Gustaf Räntilä |
| Maintainers | grantila |
| Keywords | openapi, json, schema, convert, conversion |

## Links

- npm: https://www.npmjs.com/package/openapi-json-schema
- Repository: https://github.com/grantila/openapi-json-schema
- Homepage: https://github.com/grantila/openapi-json-schema#readme
- Issues: https://github.com/grantila/openapi-json-schema/issues
- npm.io page: https://npm.io/package/openapi-json-schema

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0 (latest) — 2023-02-02
- 1.1.3 — 2021-10-17
- 1.1.2 — 2021-09-11
- 1.1.1 — 2021-02-21
- 1.1.0 — 2021-02-19
- 1.0.3 — 2021-02-18
- 1.0.2 — 2021-02-18
- 1.0.1 — 2021-02-18
- 1.0.0 — 2021-02-18

## README

[![npm version][npm-image]][npm-url]
[![downloads][downloads-image]][npm-url]
[![build status][build-image]][build-url]
[![coverage status][coverage-image]][coverage-url]


# openapi-json-schema

Minimalistic OpenAPI 3 ⬌ JSON Schema (draft 7) conversion.

 * This package aims at full conversion support except reference resolution, but isn't there yet. Currently supports:
   * `null`/`nullable` conversion
   * `$ref`'s being converted `#/definitions` <-> `#/components/schemas`
   * `const` ➡ `enum` when converting to OpenAPI
   * `$id`/`$comment` ➡ `info['x-id']`/`info['x-comment']` when converting to OpenAPI
   * *PR's are welcome.*
 * JSON `$ref`s are not resolved.
 * This package has no dependencies, and will continue to have no dependencies - re: minimalistic.


## Versions

 * Since v2 this is a [pure ESM][pure-esm] package, and requires Node.js >=14.13.1. It cannot be used from CommonJS.


# Usage

```ts
import {
    jsonSchemaToOpenApiSchema,
    openApiSchemaToJsonSchema,
} from 'openapi-json-schema'

// JSON Schema to Open API
const openApi = jsonSchemaToOpenApiSchema( jsonSchema );

// Open API to JSON Schema
const jsonSchema = openApiSchemaToJsonSchema( openApi );
```


## Utilities

The library exports utilities; `encodeRefNameJsonSchema`, `decodeRefNameJsonSchema`, `encodeRefNameOpenApi` and `decodeRefNameOpenApi` used to convert to/from references names, and their corresponding encoding in JSON Schema and Open API.


[npm-image]: https://img.shields.io/npm/v/openapi-json-schema.svg
[npm-url]: https://npmjs.org/package/openapi-json-schema
[downloads-image]: https://img.shields.io/npm/dm/openapi-json-schema.svg
[build-image]: https://img.shields.io/github/actions/workflow/status/grantila/openapi-json-schema/master.yml?branch=master
[build-url]: https://github.com/grantila/openapi-json-schema/actions?query=workflow%3AMaster
[coverage-image]: https://coveralls.io/repos/github/grantila/openapi-json-schema/badge.svg?branch=master
[coverage-url]: https://coveralls.io/github/grantila/openapi-json-schema?branch=master
[pure-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

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