npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@luxbss/gengen

v1.2.8

Published

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

Downloads

33

Readme

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 | | utilsRelativePath | Relative path to utils files. It may be useful when you have multiple generation sources | string | | | unstrictId | Disable converting 'id' properties to strong Guid type. 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
        });
    }
}

unstrictId

By default, GenGen converts all 'id' properties from string type to custom Guid type. You can disable this behaviour by using it option

Example:

public static toDTO(model: Partial<Product>): IProduct {
    return {
        // ...
        id: model.id ? model.id.toString() : Guid.empty.toString(),
        // ...
    };
}

public static fromDTO(dto: IProduct): Product {
    // ...
    model.id = new Guid(dto.id);
    // ...
}

License and copyright

Copyright (c) 2020-2023 Luxoft

Licensed under the MIT license