generator-api-on-calling
v0.1.5
Published
generate frontend api request client according to an openapi shema url
Downloads
10
Maintainers
Readme
generator-api-on-calling
API is crucial to the business when developing softwares.
Many companies happen to feel it is not easy to manage various kinds of api when the number of the apis grow up.
So, it comes to a question: is there an easy and efficient request client, which can be auto generated according to some special kind of openapi schema data ?
generator-api-on-calling
It generate frontend api request client according to an openapi shema url(OpenAPI v3.0.3).
The generated request api service always got a method called 'calling', and receive the options object argument.
e.g. GET /pets/{petId}:
/**
* the request options
*/
const requestOptions = {};
await ApiService.pets.$petId.get.calling(requestOptions);
- npm install yeoman globally
npm install yo -g
- install generator-api-on-calling globally
npm i generator-api-on-calling -g
- generate some api service according to an openapi shema url ?
enter some frontend project workspace, e.g. hello
say we want the api service name to be ApiService
cd /some/path/to/your/project/hello
yo api-on-calling --lang=javascript --service=ApiService --schema-url=http://localhost:8080/some-backend-schema-url.json
common required options
- lang
now only support: javascript
- service
the service name, which is in camel case style
e.g. ApiService, UserService, AuthService, ProfileService ...etc.
- schema-url
the shcema url, an http request url which can be requested by GET .
suppported data format: json
supported openapi version: v3.0.3
lang - javascript
command line options
- javascript-keyword-request
the str of the keyword request, which to indicate how the request is imported.
default (cmd line: just type the Enter)
import { request } from '@request';
@attention
this needs webpack config alias field:
const webpackConfig = {
alias: {
"@request": "/some/path/to/your/request"
}
};
- javascript-prettier-config
the path of the javascript prettier config
default (cmd line: just type the Enter)
module.exports = {
printWidth: 120,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
quoteProps: 'as-needed',
trailingComma: 'es5',
jsxSingleQuote: true,
trailingComma: 'es5',
bracketSpacing: true,
bracketSameLine: false,
endOfLine: 'lf',
};