# @devexperts/swagger-codegen-ts

> TS generator for swagger spec

Latest version **2.0.0-alpha.29** (published 2023-02-17) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install @devexperts/swagger-codegen-ts
pnpm add @devexperts/swagger-codegen-ts
yarn add @devexperts/swagger-codegen-ts
bun add @devexperts/swagger-codegen-ts
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0-alpha.29 |
| Published | 2023-02-17 |
| First published | 2018-10-31 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 526.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 80 |
| Author | devexperts |
| Maintainers | sky161, yivanov, raveclassic, eugryumov, dx-owner, mankdev, anikolaenkov, devexperts-bot, korol, sutarmin, dmkokovtsev |

## Links

- npm: https://www.npmjs.com/package/@devexperts/swagger-codegen-ts
- Repository: https://github.com/devexperts/swagger-codegen-ts
- Homepage: https://github.com/devexperts/swagger-codegen-ts#readme
- Issues: git+https://github.com/devexperts/swagger-codegen-ts/issues
- npm.io page: https://npm.io/package/@devexperts/swagger-codegen-ts

## Dependencies (11)

- [color](https://npm.io/package/color.md) ^3.1.2
- [adm-zip](https://npm.io/package/adm-zip.md) ^0.4.13
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [prettier](https://npm.io/package/prettier.md) ^1.19.1
- [@types/color](https://npm.io/package/@types/color.md) ^3.0.0
- [@types/adm-zip](https://npm.io/package/@types/adm-zip.md) ^0.4.32
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^8.0.0
- [@types/prettier](https://npm.io/package/@types/prettier.md) ^1.13.2
- [@devexperts/utils](https://npm.io/package/@devexperts/utils.md) ^1.0.0-alpha.10
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^3.1.1
- [json-schema-ref-parser](https://npm.io/package/json-schema-ref-parser.md) ^7.1.1

## Recent versions

- 2.0.0-alpha.29 (latest) — 2023-02-17
- 2.0.0-alpha.28 — 2022-02-09
- 2.0.0-alpha.27 — 2021-09-14
- 2.0.0-alpha.26 — 2021-07-14
- 2.0.0-alpha.25 — 2021-05-25
- 2.0.0-alpha.24 — 2020-12-24
- 2.0.0-alpha.23 — 2020-11-02
- 2.0.0-alpha.22 — 2020-07-29
- 2.0.0-alpha.21 — 2020-07-08
- 2.0.0-alpha.20 — 2020-05-20
- 2.0.0-alpha.19 — 2020-05-20
- 2.0.0-alpha.18 — 2020-04-17
- 2.0.0-alpha.17 — 2020-01-31
- 2.0.0-alpha.16 — 2020-01-31
- 2.0.0-alpha.15 — 2020-01-23
- … 37 more at https://npm.io/package/@devexperts/swagger-codegen-ts/versions

## README

[![Build Status](https://travis-ci.org/devexperts/swagger-codegen-ts.svg?branch=master)](https://travis-ci.org/devexperts/swagger-codegen-ts)

# Typesafe OpenAPI generator for TypeScript

## Features
* Generates client code from **OpenAPI 3.0, 2.0** (aka Swagger) and **AsyncAPI** specs
* **Pluggable HTTP clients:** can use `fetch`, `Axios` or any other library
* **Flexible response types:** works with Promises and reactive streams like RxJS
* **Runtime type checks:** validates server responses against the spec
* Written in **pure TypeScript** using [`fp-ts`](https://github.com/gcanti/fp-ts) and [`io-ts`](https://github.com/gcanti/io-ts) libraries

## Demo code

> The examples below refer to the [Pet Store OpenAPI 3.0 schema](https://petstore3.swagger.io/).

After running the codegen, interacting with a REST API may be as simple as this:

```typescript
import { petController as createPetController } from "./src/generated/petstore.json/paths/PetController";
import { Pet } from "./src/generated/petstore.json/components/schemas/Pet";

// Creating a controller, see the "HTTP Clients" wiki page for more details
const petController = createPetController({ httpClient: fetchHttpClient });

// The returned object is guaranteed to be a valid `Pet`
const createdPet: Promise<Pet> = petController.addPet({
  body: {
    // The parameters are statically typed, IntelliSense works, too
    name: "Spotty",
    photoUrls: [],
  },
});
```

More usage scenarios are supported - check the [usage page](./docs/usage/generated-code.md) for more detail.

## Installation

1. Make sure the peer dependencies are installed, then install the codegen itself:
   ```
   yarn add typescript fp-ts io-ts io-ts-types
   yarn add -D @devexperts/swagger-codegen-ts
   ```

2. Create a console script that would invoke the `generate` function, passing the options such as path to the schema file and the output directory.
See the [Generators](docs/usage/api.md) page for the API reference, and [examples/generate](examples/generate) for sample scripts.

3. In most cases, you might want to include the code generation step into the build and local launch scripts. Example:
   ```diff
   /* package.json */

     "scripts": {
   +   "generate:api": "ts-node scripts/generate-api.ts",
   -   "start": "react-scripts start",
   +   "start": "yarn generate:api && react-scripts start",
   -   "build": "react-scripts build"
   +   "build": "yarn generate:api && react-scripts build"
     }
   ```

## Contributing

* Feel free to file bugs and feature requests in [GitHub issues](https://github.com/devexperts/swagger-codegen-ts/issues/new).
* Pull requests are welcome - please use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/).

Please read the [Contributors Guide](./docs/development/contributors-guide.md) for more information.

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