New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

openapi-typegen

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-typegen

Generate typescript from swagger files

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
93
82.35%
Maintainers
1
Weekly downloads
 
Created
Source

Openapi Typegen

Build Status Coverage Status npm version

Generates typescript code to access your api based on the openapi (swagger) json files. The generated files are completely typesafe. This library supports only openapi schemas with the version 3.

Installation

With npm

$ npm install --global openapi-typegen`

With yarn

$ yarn global add openapi-typegen

Usage

1. Generate the files with the cli tool

$ typegen --src <path-or-url-to-schema> --out <output-directory>

For example

$ typegen --src http://localhost:8080/v2/api-docs --out ./generated 

2. Use the generated files in your application

import { createApi } from './generated/create-api';

const api = createApi({
  baseUrl: 'http://localhost:8000/api' // Override the base url the default is the url from the first server in the schema
});

// Now you can use the api as the following. The function names will be generated
// based on the operationIds
api.findPetsByTags({
  query: {
    tags: ['available']
  }
})
  .then(response => console.log(`Found pets ${response.data}`))
  .catch(error => console.error('Error while searching pets'));

Example

For an example of the generated files please take a look at the pet-store example.

FAQs

Package last updated on 14 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts