1.2.6 • Published 2 months ago

@luxbss/gengen v1.2.6

Weekly downloads
5
License
MIT
Repository
-
Last release
2 months ago

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

OptionDescriptionTypeDefault value
allGenerate allbooleanfalse
urlLocation of swagger.jsonstringhttps://localhost:5001/swagger/v1/swagger.json
fileLocal path to swagger.jsonstring
outputOutput directorystring./src/generated
configOutputOutput directory using in 'Generate a part of API' scenariostring./.generated
aliasNameSpecify prefix for generated filenames. more infostring
withRequestOptionsAllows to pass http request options to generated methods. more infobooleanfalse
utilsRelativePathRelative path to utils files. It may be useful when you have multiple generation sourcesstring
unstrictIdDisable converting 'id' properties to strong Guid type. more infobooleanfalse

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

1.2.6

2 months ago

1.2.5

3 months ago

1.2.4

5 months ago

1.2.0

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.0

7 months ago

1.2.3

6 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.0.0-rc.13

2 years ago

1.0.0-rc.12

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.10

2 years ago

1.0.0-rc.9

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.8

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-rc.3

3 years ago

1.0.0-rc.2

3 years ago

1.0.0-rc.1

3 years ago

1.0.0-rc.0

3 years ago

0.0.0-alpha.12

3 years ago

0.0.0-alpha.11

3 years ago