Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aspida/openapi2aspida
Convert OpenAPI 3.0 or Swagger 2.0 definitions into aspida
https://github.com/aspida/openapi2aspida
aspida openapi swagger typescript
Last synced: 14 days ago
JSON representation
Convert OpenAPI 3.0 or Swagger 2.0 definitions into aspida
- Host: GitHub
- URL: https://github.com/aspida/openapi2aspida
- Owner: aspida
- License: mit
- Created: 2020-05-29T06:06:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T16:05:36.000Z (3 months ago)
- Last Synced: 2024-09-15T10:51:57.850Z (about 2 months ago)
- Topics: aspida, openapi, swagger, typescript
- Language: TypeScript
- Homepage: https://github.com/aspida/openapi2aspida
- Size: 1.71 MB
- Stars: 184
- Watchers: 5
- Forks: 32
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenAPI / Swagger to aspida
Convert OpenAPI 3.0 and Swagger 2.0 definitions into aspida.
## Getting Started
Compatible with yaml/json of OpenAPI3.0/Swagger2.0
```sh
$ 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`
```ts
import axiosClient from '@aspida/axios';
import api from './api/$api';
import type { Pet } from './api/@types';
(async () => {
const client = api(axiosClient());
const petId = 100;
const body: Pet = {
id: petId,
name: 'hoge',
photoUrls: [],
status: 'available',
};await client.pet.$post({ body });
const pet = await client.pet._petId(petId).$get();
console.log(pet);
})();
````package.json`
```json
{
"scripts": {
"start": "ts-node index.ts"
}
}
``````sh
$ npm start
# { id: 100, name: 'hoge', photoUrls: [], tags: [], status: 'available' }
```## Build from config file
Create config file in project root
`aspida.config.js`
```js
module.exports = {
input: 'api', // "input" of aspida is "output" for openapi2aspida
outputEachDir: true, // Generate $api.ts in each endpoint directory
openapi: { inputFile: 'https://petstore.swagger.io/v2/swagger.json' },
};
``````sh
$ 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
```bash
npx openapi2aspida -i=openApi/sample.yaml -o=lib/api/sample
```## License
openapi2aspida is licensed under a [MIT License](https://github.com/aspida/openapi2aspida/blob/master/LICENSE).