1.0.1 • Published 5 years ago

swagger-es6 v1.0.1

Weekly downloads
28
License
MIT
Repository
github
Last release
5 years ago

swagger-es6

Swagger.json to ES6 Client Generator

Installation

npm install swagger-es6 --dev

Generate

Using NodeJS file

const swaggerGen = require('swagger-es6')
const jsonData = require('../api-docs.json')
const fs = require('fs')
const path = require('path')

let opt = {
  swagger: jsonData,
  moduleName: 'api',
  className: 'api'
}
const codeResult = swaggerGen(opt)
fs.writeFileSync(path.join(__dirname, '../dist/api.js'), codeResult)

# Generated client usage

In JS main file set API domain
```javascript
import { setDomain } from './lib/api-client.js'
const server = "http://localhost:3000/api";
setDomain(server)

Import API function into JS component, for example to log in

import { user_login as userLogin } from '../lib/api-client.js'

userLogin({
  credentials: {
    username: 'admin',
    password: 'admin'
  }
}).then(function (response) {
  console.log(response.data) // {id: "<token>", ttl: 1209600, created: "2017-01-01T00:00:00.000Z", userId: 1}
})

All requests use axios module with promise, for more information about that follow axios documentation

Links

License

MIT

1.0.1

5 years ago

1.0.0

6 years ago

0.9.9

6 years ago

0.9.9-stable

6 years ago

0.9.9-beta

6 years ago

0.9.9-alpha

6 years ago

0.9.8-dev

6 years ago

0.9.8

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago