Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@lune-climate/openapi-typescript-codegen

lune-climate175MIT0.1.18TypeScript support: included

Fork of: https://github.com/ferdikoomen/openapi-typescript-codegen. Library that generates Typescript clients based on the OpenAPI specification.

openapi, swagger, generator, typescript, yaml, json, fetch, xhr, axios, angular, node

readme

Lune openapi typescript generator

This repo is a friendly fork of the excellent https://github.com/ferdikoomen/openapi-typescript-codegen. The fork contains several changes to the generator to better fit our exact use case. Some of these changes we'll try to get merged into the upstream, but some are more of a specific use case for us, hence the need for a fork. This code is used by https://github.com/lune-climate/lune-ts to generate the base models/services.

We have some Developer documentation.

Release process

Changes made to the library will only be picked up by lune-ts once a new version is released to npm. The release process consists of:

  • Manually up the version as desired (major, minor, patch) on package-lock.json and package.json.
  • Create a PR with the changes.
  • Get the PR approved and merged as usual.
  • After the changes are in master, create a new release on GH with the corresponding tag.

After the GH release is created, the library will be automatically released to npm.

OpenAPI Typescript Codegen

NPM License Coverage Quality Code Climate Downloads Build

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

Install

npm install openapi-typescript-codegen --save-dev

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)
    -v, --apiVersion <value>  API calendar version value, added as `Lune-Version` header to all requests (required)
    -c, --client <value>      HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
    --name <value>            Custom client class name
    --useOptions              Use options instead of arguments
    --useUnionTypes           Use union types instead of enums
    --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")
    --postfix <value>         Service name postfix (default: "Service")
    --request <value>         Path to custom request file
    -h, --help                display help for command

  Examples
    $ openapi --input ./spec.json --output ./generated --apiVersion '2024-08-08'
    $ openapi --input ./spec.json --output ./generated --apiVersion '2024-08-08' --client xhr

Documentation

For end-users:

For developers:

Support

changelog

Changelog

All notable changes to this project will be documented in this file.

[0.20.1] - 2022-02-25

Fixed

  • Support enums with single quotes in names for V2

[0.20.0] - 2022-02-25

Fixed

  • Updated dependencies
  • Support enums with single quotes in names for V3
  • Generating better names when operationId is not given (breaking change)
  • Fixed issue where x-enum flags where breaking due to non-string values

[0.19.0] - 2022-02-02

Added

  • Support for Angular client with --name option
  • Added test cases for Angular client

[0.18.2] - 2022-02-02

Fixed

  • Updated dependencies
  • Fixed type definition

    Added

  • Added test cases for CLI commands
  • Added test cases for query parsing

[0.18.1] - 2022-01-31

Fixed

  • Escaping error description
  • Made Client.request and BaseHttpRequest.config props public

_## [0.18.0] - 2022-01-28

Added

  • Angular client generation!
  • Updated documentation with more examples and better descriptions

[0.17.0] - 2022-01-26

Fixed

  • Shorthand notation for properties passed through constructor
  • Simplified creation of headers
  • Prepare codebase for Angular client

[0.16.2] - 2022-01-26

Fixed

  • Removed dependency on URLSearchParams to support browser and node without any additional imports

[0.16.1] - 2022-01-26

Fixed

  • Correct export inside index.ts when giving a custom name

[0.16.0] - 2022-01-25

Added

  • Added option to set the indentation (spaces and tabs)
  • Added option to export separate client file that allows usage for multiple backends

    Fixed

  • Decoupled OpenAPI object from requests
  • Updated dependencies

[0.15.0] - 2022-01-24

Added

  • Added change log and releases on GitHub

[0.14.0] - 2022-01-24

Fixed

  • Added missing postfix options to typedef
  • Updated escaping of comments and descriptions
  • Better handling of services without tags
  • Updated dependencies