Giter Site home page Giter Site logo

apocali1 / gengen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from luxoft/gengen

0.0 0.0 0.0 1.26 MB

Tool for generating models and Angular services based on OpenAPIs and Swagger's JSON.

License: MIT License

TypeScript 99.86% JavaScript 0.14%

gengen's Introduction

GenGen

NPM version license GitHub contributors

This tool generates models and Angular services based on generated Swagger JSON.

Getting Started

First of all you make sure that swagger.json is accessable.

Location by default is https://localhost:5001/swagger/v1/swagger.json. You can override it. See all options

Generate all API

gengen g --all

Generate a part of API

  1. Initialize empty rule set

    gengen init
  2. Generate list of available endpoints

    gengen g:c
  3. Describe endpoints who will be generated

    import { Endpoints } from './endpoints';
    
    export default new Set([Endpoints.ProductService.GetProducts, Endpoints.CategoryService.AddCategory]);
  4. Generate specified routes

    gengen g

Options

Option Description Type Default value
all Generate all boolean false
url Location of swagger.json string https://localhost:5001/swagger/v1/swagger.json
file Local path to swagger.json string
output Output directory string ./src/generated
configOutput Output directory using in 'Generate a part of API' scenario string ./.generated
aliasName Specify prefix for generated filenames. more info string
withRequestOptions Allows to pass http request options to generated methods. more info boolean false

Option details

aliasName

Alias provides:

  1. Prefixes for model and service files
  2. A way to specify dynamic basePath for services.

Example:

gengen --aliasName myalias

GenGen would create files myalias-models.ts, myalias-services.ts in output directory. And we could override services basePath with following code

window.__gengen__basePathMap = {
    myalias: 'https://myexternalapi/api'
};

withRequestOptions

GenGen would generate optional parameter options for each method in services. With which you could provide any additional request options from the interface below (IAngularHttpRequestOptions).

Example:

interface IAngularHttpRequestOptions {
    headers?: HttpHeaders | { [header: string]: string | string[] };
    observe?: 'body' | 'response';
    params?: HttpParams | { [param: string]: string | string[] };
    reportProgress?: boolean;
    responseType?: 'json' | 'blob';
    withCredentials?: boolean;
}

@Injectable({
    providedIn: 'root'
})
export class ExampleService extends BaseHttpService {
    // ...

    public methodName(options?: IAngularHttpRequestOptions): Observable<void> {
        return this.post<string>(`methodName`, options);
    }

    // ...
}

@Component(
    // ...
)
export class MyComponent {
    constructor(private exampleService: ExampleService) {
        this.exampleService.methodName({
            withCredentials: true
        });
    }
}

License and copyright

Copyright (c) 2020-2021 Luxoft

Licensed under the MIT license

gengen's People

Contributors

aleshchev avatar sevaru avatar jeremiah avatar jackkk94 avatar nikitaegorov avatar aleshadk avatar dependabot[bot] avatar llotall avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.