https://github.com/pregalaxyer/nemo
a 💪 typescript generator 🔨 for swagger resultful api, based on swagger v2 摸鱼&代码量神器
https://github.com/pregalaxyer/nemo
api codegen interface moy nemo pregalaxyer swagger typescript
Last synced: 6 months ago
JSON representation
a 💪 typescript generator 🔨 for swagger resultful api, based on swagger v2 摸鱼&代码量神器
- Host: GitHub
- URL: https://github.com/pregalaxyer/nemo
- Owner: pregalaxyer
- License: other
- Created: 2021-10-29T03:17:51.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-25T03:01:44.000Z (about 4 years ago)
- Last Synced: 2025-10-19T21:47:00.317Z (9 months ago)
- Topics: api, codegen, interface, moy, nemo, pregalaxyer, swagger, typescript
- Language: TypeScript
- Homepage:
- Size: 612 KB
- Stars: 26
- Watchers: 0
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.en.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[简体中文](Readme.zh.md)
nemo🐠
a 💪 typescript generator 🔨 for swagger resultful api, based on swagger v2
## Install
```node
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:
1. `url`: your resultful swagger json url
2. `output`: the folder for your swagger typescript files
3. `requestPath`: customer request, such as `axios`, `umi-request` or file path
4. `exportsRequest`: the options for your to decide wether create request folder, always happened when you want save local fetch changes
5. `paths`: exports by paths filter
```typescript
interface SwaggerConfig {
/**
* @description swagger api url
*/
url: string
/**
* @description single-api or apis
*/
paths?: Array
/**
* @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`
```node
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**
``` 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:
```typescript
type RequestInitWithoutBodyInit = Omit
interface Options extends RequestInitWithoutBodyInit, Record {
body?: Record
formData?: Record
query?: Record
}
// default request
request(url: string, options: Options)
// your request file
import request from `${library}`
import { getRequestBody, Options } from `${output}/utils`
export default async function (url, options) {
const body: BodyInit | undefined = getRequestBody(options)
const data = await request(url, Object.assign(options, {body}))
return data
}
```
## TODO
- [ ] swagger v3 support