0.24.0 • Published 3 months ago

openapi2aspida v0.24.0

Weekly downloads
437
License
MIT
Repository
github
Last release
3 months ago

OpenAPI / Swagger to aspida

Breaking change :warning:

2022/03/07

Since openapi2aspida >= 0.18.0 , decision whether to be required follows the OpenAPI spec correctly. Dropping the support for original implementation, that was defaulting to required.

2021/03/15

Since openapi2aspida >= 0.16.0 , requires TypeSciprt 3.8 or higher for Type-Only Imports.

2020/11/26

Since openapi2aspida >= 0.14.0 , request headers are forced to be optional.

2020/11/14

Since openapi2aspida >= 0.13.0 , optional for aspida only if the 'required' property of OpenAPI is set to false.

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

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

{
  "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 openapi2aspida
  outputEachDir: true, // Generate $api.ts in each endpoint directory
  openapi: { 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.

0.24.0

3 months ago

0.23.2

1 year ago

0.23.1

1 year ago

0.23.0

1 year ago

0.22.0

1 year ago

0.20.0

2 years ago

0.21.0

2 years ago

0.19.0

3 years ago

0.18.0

3 years ago

0.17.0

3 years ago

0.16.5

3 years ago

0.16.4

4 years ago

0.16.3

4 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.3

4 years ago

0.15.2

4 years ago

0.15.1

4 years ago

0.15.0

4 years ago

0.14.0

4 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.11.0

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.4

5 years ago

0.5.5

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago