swanco
v4.0.7
Published
Swagger code generation for Angular
Downloads
47
Readme
swanco
This project is a small tool, which generates an Angular module from a Swagger 2.0 specification.
Key features
- Generate complete API module, which contains enums, models and services
- Generate services only, as a part of another module
- Generate models only (It can be useful, when you use WebSocket instant XHR requests)
Requirements
The generator requires NodeJS 10.12.0
or later and has a few dependencies:
- yargs
- handlebars
- lodash.camelcase
- lodash.groupby
- lodash.isequal
- lodash.kebabcase
- lodash.orderby
- lodash.uniqby
- lodash.upperfirst
Installation
npm install --save-dev swanco
Usage
Options
--input
, -i
URL or local path to the file with specification in JSON format
--output
, -o
Path to write generated content, default: src/app/api
--auth
Basic authentication credentials, like user:password
--skip-services
Do not create services content
--skip-module
Do not create module file
--hide-report
Do not show results of files generation
--version
Show version number
--help
Show help
Run directly
node_modules/.bin/swanco -i <path_to_swagger_json> [-o <output_dir>]
Run as npm script
Add script bellow to package.json
and execute npm run swanco
{
"scripts": {
"swanco": "swanco -i <path_to_swagger_json> [-o <output_dir>]"
}
}
Run as a module
Usage as a module, it is an asynchronous function, which returns a promise.
// JavaScript
const swanco = require('swanco');
swanco({ input: '<path_to_swagger_json>' }).then(
() => { /* do something */ },
err => console.error(err.message)
);
// TypeScript
import * as swanco from 'swanco';
swanco({ input: '<path_to_swagger_json>' }).then(
() => { /* do something */ },
err => console.error(err.message)
);
Example
The commands bellow will generate an API module for Swagger's PetStore example, assuming Angular CLI is installed globally:
ng new petstore
cd petstore
npm install --save-dev swanco
node_modules/.bin/swanco -i http://petstore.swagger.io/v2/swagger.json
It generates api module bellow:
petstore
+-- src
+-- app
+-- api
+-- enums
| +-- index.ts
| +-- order-status.enum.ts
| +-- pet-status.enum.ts
+-- models
| +-- api-response.model.ts
| +-- category.model.ts
| +-- index.ts
| +-- order.model.ts
| +-- pet.model.ts
| +-- tag.model.ts
| +-- user.model.ts
+-- services
| +-- index.ts
| +-- pet.service.ts
| +-- store.service.ts
| +-- user.service.ts
+-- api.module.ts
+-- config.service.ts
+-- index.ts
+-- variables.ts
Bug report
If you have any problems in use, please, create new issue with example.