api-generator-modules
v0.2.4
Published
An API generation library for NodeJS
Readme
configure
- configure file
// api.config.ts
module.exports = [
/** swagger json address */
origin: 'xxxxxx',
/** Code generation directory */
output: 'ser/service',
/** accounts */
account: '',
/** Password */
password: '',
/** Module filter */
filter: '',
getTagName: '',
getApiName: ''
]- use
npx api-generator-modules example
const TAGS = ['dishes-controller',];
module.exports = [
{
origin: `https://xxxxxxxxx.../api-docs`,
output: 'src/service',
filter(api) {
return TAGS.includes(api.tag);
},
getTagName(api) {
return api.path
.split('/')
.filter(Boolean)
.slice(0, 3)
.reduce((tagName, item, index) => {
return (
tagName +
item
.split(/[^a-z0-9]+/)
.filter(Boolean)
.reduce(
(joins, piece) =>
joins + (index === 0 ? piece : piece.replace(/^[a-z]/, (i) => i.toUpperCase())),
'',
)
);
}, '');
},
},
];