GithubHelp home page GithubHelp logo

isabella232 / openapi2aspida Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lumakernel/openapi2aspida

0.0 0.0 0.0 1.83 MB

Convert OpenAPI 3.0 or Swagger 2.0 definitions into aspida

Home Page: https://github.com/aspida/openapi2aspida

License: MIT License

JavaScript 3.10% TypeScript 96.90%

openapi2aspida's Introduction

OpenAPI / Swagger to aspida


aspida


Convert OpenAPI 3.0 and Swagger 2.0 definitions into aspida.



Breaking change โš ๏ธ

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

License

openapi2aspida is licensed under a MIT License.

openapi2aspida's People

Contributors

dependabot[bot] avatar redshoga avatar solufa avatar stmtk1 avatar toshiaki61 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.