Skip to content

Repository files navigation

OpenAPI / Swagger to aspida



aspida logo image


npm versionnpm download

Convert OpenAPI 3.0 and Swagger 2.0 definitions into aspida.



Getting Started

Compatible with yaml/json of OpenAPI3.0/Swagger2.0

$ mkdir petstore-api
$ cd petstore-api
$ npx openapi2aspida -i https://petstore.swagger.io/v2/swagger.json # or ../local-swagger.yaml# api/$api.ts was built successfully.
$ npm init -y
$ npm install @aspida/axios axios typescript ts-node @types/node

index.ts

importaxiosClientfrom'@aspida/axios';importapifrom'./api/$api';importtype{Pet}from'./api/@types';(async()=>{constclient=api(axiosClient());constpetId=100;constbody: Pet={id: petId,name: 'hoge',photoUrls: [],status: 'available',};awaitclient.pet.$post({ body });constpet=awaitclient.pet._petId(petId).$get();console.log(pet);})();

package.json

{
"scripts": {
"start": "ts-node index.ts"
}
}
$ npm start
# { id: 100, name: 'hoge', photoUrls: [], tags: [], status: 'available' }

Build from config file

Create config file in project root

aspida.config.js

module.exports={input: 'api',// "input" of aspida is "output" for openapi2aspidaoutputEachDir: true,// Generate $api.ts in each endpoint directoryopenapi: {inputFile: 'https://petstore.swagger.io/v2/swagger.json'},};
$ npx openapi2aspida

Cli options

-i, --input

path to an OpenAPI spec file for input

-o, --outputdir

can change aspida output directory

-c, --config

path to an aspida config file

--version

displays version of openapi2aspida

example

npx openapi2aspida -i=openApi/sample.yaml -o=lib/api/sample

License

openapi2aspida is licensed under a MIT License.

About

Convert OpenAPI 3.0 or Swagger 2.0 definitions into aspida

Topics

Resources

Stars

189 stars

Watchers

3 watching

Forks

Releases

Used by

Contributors

Languages