Caution
LUCO社内利用のためにOAS 3.1.0に仮対応したものです。
LUCO社内での利用は問題ありませんが、社外の利用に関して一切の責任を負いません。
また、このフォークはupstreamへのPRを基本的に作成しません(OAS 3.0.x利用者への破壊的な変更が含まれるためです)
また一切の自動テストを行っていませんので、利用に際しては自己責任でお願いします。
This is a temporary support version of OAS 3.1.0 for LUCO internal use.
Internal use within LUCO is not a problem, but we do not take any responsibility for external use.
Also, this fork does not basically create a PR to upstream (as it contains destructive changes to the 3.0.x environment)
Please note that no automatic testing has been carried out and that you use the system at your own risk.
THIS IS UNOFFICIAL FORK
Convert OpenAPI 3.0 and Swagger 2.0 definitions into aspida.
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.
Since openapi2aspida >= 0.16.0
, requires TypeSciprt 3.8 or higher for Type-Only Imports.
Since openapi2aspida >= 0.14.0
, request headers are forced to be optional.
Since openapi2aspida >= 0.13.0
, optional for aspida only if the 'required' property of OpenAPI is set to false
.
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' }
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
path to an OpenAPI spec file for input
can change aspida output directory
path to an aspida config file
displays version of openapi2aspida
npx openapi2aspida -i=openApi/sample.yaml -o=lib/api/sample
openapi2aspida is licensed under a MIT License.