JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 99
  • Score
    100M100P100Q81675F
  • License MIT

Generate TypeScript types from OpenAPI 3.0 specs.

Package Exports

  • openapi-to-ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (openapi-to-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

🌅 openapi-to-ts

TypeScript type generator for OpenAPI 3.0 specification files. To view an example, please follow the links below:

Example

Features

  • Generates TypeScript types from OpenAPI 3.0 specification files using Node.js.
  • Retrieves specification files from the file system or remote sources.
  • Supports YAML and JSON specification files.
  • Generates interfaces and types.
  • Tiny size with only a few dependencies.

Install

npm install openapi-to-ts

or

yarn add openapi-to-ts

CLI Usage

To generate TypeScript types from the local file system, run the following command in your console:

npx openapi-to-ts -i ./example/example.yaml -o ./example/example.ts

To generate TypeScript types from a remote source, run the following command in your console:

npx openapi-to-ts -i https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml -o ./example/example.ts

CLI Options

Option Alias Required Default Description
--input -i Yes Specifies the OpenAPI 3.0 specification file that should be converted.
--output -o Yes Specifies the output file where the TypeScript types should be written to.
--prefixWithI No false Appends the letter I as a prefix to all interface names.

Planned Improvements

  • Add an option to run prettier on the generated TS file.
  • Allow fetching OpenAPI files from private GitHub repos.
  • Implement additionalProperties.
  • Reduce bundlesize.
  • Allow usage from Node.js and not just the CLI.
  • Cover the codebase with tests.

Bugs

Found a bug? Please report it here and I would be happy to take a look. Contributions are more than welcome too!