2.0.1 • Published 6 years ago
openapi-typegen v2.0.1
Openapi Typegen
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.
2.0.1
6 years ago
2.0.0
6 years ago
1.0.3
6 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.0.3-development
7 years ago
0.0.2-development
7 years ago
0.0.1-development
7 years ago
0.0.0-development
7 years ago