4.0.7 • Published 1 year ago

swanco v4.0.7

Weekly downloads
8
License
MIT
Repository
github
Last release
1 year ago

swanco

CircleCI branch npm node License

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:

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.

4.0.7

1 year ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago