2.5.2 • Published 8 days ago
openapi-toolkit v2.5.2
Install
npm i openapi-toolkit
Auto Generate Client/Server (Cli)
npm i -g openapi-toolkit
# example
openapi-toolkit -i https://petstore3.swagger.io/api/v3/openapi.json -g typescript-axios -o ./src/services/petStore --modelNamePrefix My --modelNameSuffix .dto
# show all options
openapi-toolkit -h
# with docker
docker run --rm --name openapi-toolkit -v "$(pwd)/output:/output" -e CLI_PARAMS="-i https://petstore3.swagger.io/api/v3/openapi.json -g typescript-axios --modelNamePrefix My --modelNameSuffix .dto" barnuri/openapi-toolkit
Help output
openapi-toolkit <command>, default command 'generate'
Commands:
generate auto generate proxy client from swagger file [default]
generators generators list
completion generate completion script
Options:
--version Show version number [boolean]
-h, --help Show help [boolean]
-i, --pathOrUrl path or url for swagger file [required]
-o, --output output path [required]
-g, --generator generator name [default: "typescript-axios"]
-t, --type [choices: "client", "server"] [default: "client"]
-n, --namepsace [default: "OpenapiDefinitionGenerate"]
--modelsFolderName [default: "models"]
--modelNamePrefix [default: ""]
--modelNameSuffix [default: ""]
--controllersFolderName [default: "controllers"]
--controllerNamePrefix [default: ""]
--controllerNameSuffix [default: "Controller"]
Vscode Plugin For Auto Generate
Examples
1) React Example
2) Angular Example
3) Look at editorInputToHtml.ts to handle editors by yourself
Example of using editorInputToHtml.ts
Download this file
https://petstore.swagger.io/v2/swagger.json
Then use this code
import { writeFileSync } from 'fs';
import openapiSchemaExample from './openapiSchemaExample.json';
import { editorInputToHtml, getEditor, OpenApiDocument } from 'openapi-toolkit';
const ex = async () = {
await axios.get('https://petstore.swagger.io/v2/swagger.json')
const editors = ['Order', 'User', 'Category', 'Tag', 'Pet', 'ApiResponse'].map(tabName => getEditor((openapiSchemaExample as any) as OpenApiDocument, tabName));
const html = editorInputToHtml(editors);
writeFileSync('./openapiSchemaExample.result.json', JSON.stringify(editors, undefined, 4), 'utf-8');
writeFileSync('./openapiSchemaExample.html', html, 'utf-8');
var start = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open';
require('child_process').exec(start + ' ' + './openapiSchemaExample.html');
}
Result
2.5.0
8 days ago
2.5.2
8 days ago
2.5.1
8 days ago
2.4.9
20 days ago
2.4.8
21 days ago
2.4.3
12 months ago
2.4.2
12 months ago
2.4.5
11 months ago
2.4.4
12 months ago
2.4.6
11 months ago
2.4.1
1 year ago
2.4.0
1 year ago
2.3.8
2 years ago
2.3.9
2 years ago
2.3.7
2 years ago
2.0.28
2 years ago
2.0.29
2 years ago
2.1.1
2 years ago
2.3.2
2 years ago
2.3.4
2 years ago
2.3.3
2 years ago
2.3.6
2 years ago
2.3.5
2 years ago
2.2.6
2 years ago
2.0.30
2 years ago
2.1.0
2 years ago
2.0.26
2 years ago
2.0.24
2 years ago
2.0.25
2 years ago
2.0.22
2 years ago
2.0.23
2 years ago
2.0.21
2 years ago
2.0.19
3 years ago
2.0.17
3 years ago
2.0.18
3 years ago
2.0.15
3 years ago
2.0.16
3 years ago
2.0.13
3 years ago
2.0.14
3 years ago
2.0.11
3 years ago
2.0.12
3 years ago
2.0.20
3 years ago
2.0.9
3 years ago
2.0.10
3 years ago
2.0.6
3 years ago
2.0.5
3 years ago