npm

@grafikart/o2ts
TypeScript icon, indicating that this package has built-in type declarations

0.1.15 • Public • Published

@grafikart/o2ts

A simple tool to convert OpenAPI 3.0/3.1 specs into a TypeScript file with useful types.

Install

npm i -D @grafikart/o2ts
yarn add -D @grafikart/o2ts
pnpm add -D @grafikart/o2ts

Usage

Add the following script to your package.json:

{
  "scripts": {
    "openapi": "o2ts ./openapi.yml"
  }
}

Then:

npm run openapi

Example

Here is an example of using the definitions generated with the tool:

import type { APIPaths, APIRequests, APIResponse } from './openapi'

export async function fetchAPI<
  Path extends APIPaths,
  Options extends APIRequests<Path>
> (path: Path, options: Options): Promise<APIResponse<Path, Options['method']>> {
  // Your code here
}

You can find more implementations in the examples directory.

Readme

Keywords

none

Package Sidebar

Install

npm i @grafikart/o2ts

Weekly Downloads

140

Version

0.1.15

License

ISC

Unpacked Size

20.8 kB

Total Files

27

Last publish

Collaborators

  • grafikart