# @majkit/openapi

> Library that generates Typescript clients based on the OpenAPI specification.

Latest version **0.30.9** (published 2024-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @majkit/openapi
pnpm add @majkit/openapi
yarn add @majkit/openapi
bun add @majkit/openapi
```

Provides the command `openapi`.

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.30.9 |
| Published | 2024-03-15 |
| First published | 2023-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 203.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Majkit |
| Maintainers | majksa |
| Keywords | openapi, swagger, generator, typescript, yaml, json, fetch, xhr, axios, node |

## Links

- npm: https://www.npmjs.com/package/@majkit/openapi
- Repository: https://github.com/maxa-ondrej/openapi-typescript-codegen
- Issues: https://github.com/maxa-ondrej/openapi-typescript-codegen/issues
- npm.io page: https://npm.io/package/@majkit/openapi

## Dependencies (6)

- [fs-extra](https://npm.io/package/fs-extra.md) ^11.1.1
- [camelcase](https://npm.io/package/camelcase.md) ^6.3.0
- [commander](https://npm.io/package/commander.md) ^11.0.0
- [handlebars](https://npm.io/package/handlebars.md) ^4.7.7
- [@majkit/fp-ts-schema](https://npm.io/package/@majkit/fp-ts-schema.md) ^1.1.5
- [@apidevtools/json-schema-ref-parser](https://npm.io/package/@apidevtools/json-schema-ref-parser.md) ^9.0.9

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

- 0.30.9 (latest) — 2024-03-15
- 0.30.8 — 2024-03-15
- 0.30.7 — 2024-03-15
- 0.30.6 — 2024-03-15
- 0.30.5 — 2024-03-14
- 0.30.4 — 2024-03-14
- 0.29.3 — 2024-03-11
- 0.29.2 — 2024-03-11
- 0.29.1 — 2023-11-25
- 0.29.0 — 2023-11-16
- 0.28.5 — 2023-11-15
- 0.28.4 — 2023-11-15
- 0.28.3 — 2023-11-13
- 0.28.2 — 2023-11-13
- 0.28.1 — 2023-11-13
- … 11 more at https://npm.io/package/@majkit/openapi/versions

## README

# OpenAPI Typescript Codegen

[![NPM][npm-image]][npm-url]
[![License][license-image]][license-url]
[![Coverage][coverage-image]][coverage-url]
[![Coverage][coverage-image]][coverage-url]
[![Downloads][downloads-image]][downloads-url]
[![Build][build-image]][build-url]

> Node.js library that generates Typescript clients based on the OpenAPI specification.

## Why?
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
- Quick, lightweight, robust and framework-agnostic 🚀
- Supports generation of TypeScript clients
- Supports generations of Fetch, Node-Fetch, Axios, Angular and XHR http clients
- Supports OpenAPI specification v2.0 and v3.0
- Supports JSON and YAML files for input
- Supports generation through CLI, Node.js and NPX
- Supports tsc and @babel/plugin-transform-typescript
- Supports aborting of requests (cancelable promise pattern)
- Supports external references using [json-schema-ref-parser](https://github.com/APIDevTools/json-schema-ref-parser/)

## Install

```
pnpm install @majkit/openapi @majkit/fp-ts-schema -D
```

## Usage

```
$ openapi --help

  Usage: openapi [options]

  Options:
    -V, --version             output the version number
    -i, --input <value>       OpenAPI specification, can be a path, url or string content (required)
    -o, --output <value>      Output directory (required)
    -c, --client <value>      HTTP client to generate [fetch, xhr, node, axios] (default: "fetch")
    --name <value>            Custom client class name
    --useOptions              Use options instead of arguments
    --exportCore <value>      Write core files to disk (default: true)
    --exportServices <value>  Write services to disk (default: true)
    --exportModels <value>    Write models to disk (default: true)
    --exportSchemas <value>   Write schemas to disk (default: false)
    --indent <value>          Indentation options [4, 2, tab] (default: "4")
    --postfixServices         Service name postfix (default: "Service")
    --postfixModels           Model name postfix
    --request <value>         Path to custom request file
    -h, --help                display help for command

  Examples
    $ openapi --input ./spec.json --output ./generated
    $ openapi --input ./spec.json --output ./generated --client xhr
```

## Docker usage

To build the Docker container, execute the following command:

```
docker build . --tag openapi-typescript-codegen
```

After this is done, you can execute the CLI commands:

```
docker run openapi-typescript-codegen --help
docker run openapi-typescript-codegen --input sample.yaml --output client
```

Documentation
===
- [Basic usage](docs/basic-usage.md)
- [OpenAPI object](docs/openapi-object.md)
- [Client instances](docs/client-instances.md) `--name`
- [Argument vs. Object style](docs/arguments-vs-object-style.md) `--useOptions`
- [Runtime schemas](docs/runtime-schemas.md) `--exportSchemas`
- [Enum with custom names and descriptions](docs/custom-enums.md)
- [Nullable props (OpenAPI v2)](docs/nullable-props.md)
- [Authorization](docs/authorization.md)
- [External references](docs/external-references.md)
- [Canceling requests](docs/canceling-requests.md)
- [Custom request file](docs/custom-request-file.md)

Support
===
- [Babel support](docs/babel-support.md)
- [Axios support](docs/axios-support.md)
- [Node-Fetch support](docs/node-fetch-support.md)

[npm-url]: https://npmjs.org/package/@majkit/openapi
[npm-image]: https://img.shields.io/npm/v/@majkit/openapi.svg
[license-url]: LICENSE
[license-image]: http://img.shields.io/npm/l/@majkit/openapi.svg
[coverage-url]: https://codecov.io/gh/maxa-ondrej/openapi-typescript-codegen
[coverage-image]: https://img.shields.io/codecov/c/github/maxa-ondrej/openapi-typescript-codegen.svg
[downloads-url]: http://npm-stat.com/charts.html?package=@majkit/openapi
[downloads-image]: http://img.shields.io/npm/dm/@majkit/openapi.svg
[build-url]: https://circleci.com/gh/maxa-ondrej/openapi-typescript-codegen/tree/master.svg
[build-image]: https://circleci.com/gh/maxa-ondrej/openapi-typescript-codegen/tree/master.svg?style=svg

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