Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mjarkk/openapicodegen
Generate minimal javascript from a swagger file
https://github.com/mjarkk/openapicodegen
Last synced: about 1 month ago
JSON representation
Generate minimal javascript from a swagger file
- Host: GitHub
- URL: https://github.com/mjarkk/openapicodegen
- Owner: mjarkk
- License: mit
- Created: 2019-09-11T07:36:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-11T07:39:09.000Z (about 5 years ago)
- Last Synced: 2024-04-15T10:06:38.454Z (7 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `openApiCodeGen` Generate minimal javascript from a swagger file
Made for swagger v2 and outputs javascript that just calles a helper function for fetching the data## How to use
### Install
```sh
go get github.com/mjarkk/openApiCodeGen
```### Generate javascript
```sh
# Generate javascript and output it to the stdout
openApiCodeGen -in swagger.json# Generate javascript and place it in a file
openApiCodeGen -in swagger.json > api.js
```### Create the fetch function
The api file generated will reqeust a function `apiUtil.js`
The `apiUtil.js` file needs to be in the same dir as the generated code
```js
// apiUtil.js
// apiFetcher is the function requested by the generated codeexport const apiFetcher = async reqData => {
console.log(reqData)
/*{
params: ['firstParam', 'secondParam'],
method: "POST",
url: "/api/v1/user/firstParam/edit/secondParam",
body: {...},
}*/return await fetch(reqData.url)
}
```