dynemo
v1.1.3
Published
swagger typescript codegen
Downloads
2
Maintainers
Readme
Install
npm install @pregalaxyer/nemo
// or
yarn add @pregalaxyer/nemo
// install global
npm install @pregalaxyer/nemo -g
Example
excute the file below, your will get your swagger typescript files. options:
url
: your resultful swagger json urloutput
: the folder for your swagger typescript filesrequestPath
: customer request, such asaxios
,umi-request
or file pathexportsRequest
: the options for your to decide wether create request folder, always happened when you want save local fetch changespaths
: exports by paths filter
interface SwaggerConfig {
/**
* @description swagger api url
*/
url: string
/**
* @description single-api or apis
*/
paths?: Array<string | Regexp>
/**
* @description output floder
*/
output?: string
/**
* @description where request module import from
*/
requestPath?: string
/**
* @description request templates only create and remove when it is true
* when you only need exportsRequest once, mostly code likes:
* * `exportsRequest: !isRequestFloderExsit`
*/
exportsRequest?: boolean
}
swagger.js
const main = require('@pregalaxyer/nemo')
// with esm
import main from '@pregalaxyer/nemo'
main({
url: 'https://petstore.swagger.io/v2/swagger.json',
output: './src/api'
})
Terminal Bash
@pregalaxyer/nemo convert -i https://petstore.swagger.io/v2/swagger.json -o ./src/api
# or after install global
npx @pregalaxyer/nemo convert -i https://petstore.swagger.io/v2/swagger.json -o ./src/api
Change request library
It easy for you to use other request library. Example:
type RequestInitWithoutBodyInit = Omit<RequestInit, 'body'>
interface Options extends RequestInitWithoutBodyInit, Record<string, any> {
body?: Record<string, any>
formData?: Record<string, any>
query?: Record<string, any>
}
// default request
request<ResponseType>(url: string, options: Options)
// your request file
import request from `${library}`
import { getRequestBody, Options } from `${output}/utils`
export default async function <T>(url, options) {
const body: BodyInit | undefined = getRequestBody(options)
const data = await request<T>(url, Object.assign(options, {body}))
return data
}
TODO
- [ ] swagger v3 support