Skip to content

[Typescript-Angular] Service generation incorrectly attempting to use parameter. #6762

@defmonk0

Description

@defmonk0
Description

Upon generating the code for my angular project, I copied it into my app directory. Immediately, the compiler starts spitting out errors about being unable to find variables. This is an example of the exact error (there are a lot of them):

ERROR in /home/def_monk/code/eve-calendar/src/app/esi/api/wars.service.ts (163,92): Cannot find name 'war_id'.

It's pretty easy to identify what it's talking about, since the uses of snakecase are very rare in the files. There is a mismatch in the parameter name and what is used in the return statement. The function in which that particular error occurs is here:

/**
 * List kills for a war
 * Return a list of kills related to a war  --- Alternate route: `/v1/wars/{war_id}/killmails/`  Alternate route: `/legacy/wars/{war_id}/killmails/`  Alternate route: `/dev/wars/{war_id}/killmails/`  --- This route is cached for up to 3600 seconds
 * @param warId A valid war ID
 * @param datasource The server name you would like data from
 * @param page Which page of results to return
 * @param userAgent Client identifier, takes precedence over headers
 * @param xUserAgent Client identifier, takes precedence over User-Agent
 */
public getWarsWarIdKillmails(warId: number, datasource?: string, page?: number, userAgent?: string, xUserAgent?: string): Observable<Array<GetWarsWarIdKillmails200Ok>> {
    if (warId === null || warId === undefined) {
        throw new Error('Required parameter warId was null or undefined when calling getWarsWarIdKillmails.');
    }

    let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
    if (datasource !== undefined) {
        queryParameters = queryParameters.set('datasource', <any>datasource);
    }
    if (page !== undefined) {
        queryParameters = queryParameters.set('page', <any>page);
    }
    if (userAgent !== undefined) {
        queryParameters = queryParameters.set('user_agent', <any>userAgent);
    }

    let headers = this.defaultHeaders;
    if (xUserAgent !== undefined && xUserAgent !== null) {
        headers = headers.set('X-User-Agent', String(xUserAgent));
    }

    return this.httpClient.get<any>(`${this.basePath}/wars/${encodeURIComponent(String(war_id))}/killmails/`,
    {
        params: queryParameters,
        headers: headers,
        withCredentials: this.configuration.withCredentials,
    });
}
Swagger-codegen version

Master at time of pull: f0b7dae (which would mean actual version is 2.3.0, if I understand correctly).

Swagger declaration file content or url

https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility

Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
	-i https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility \
	-l typescript-angular \
	-o ./clients/esi/
Steps to reproduce

Generate code, and try to move it into the angular application. The typescript will not be able to compile. I'm used Angular CLI to do the project generation and the compile/serve.

Related issues/PRs

#4264 seems related, since it looks to be when the change to camelcase was made to match the style guide.

Suggest a fix/enhancement

Looking around to try and figure out what the problem was, I eventually made my way to this line of mustache template for the services. That said, this is my first time using both codegen and angular2+, and I know nothing about using mustache templates, so I have no idea if I'm actually correct in guessing it has something to do with that line of code. Lol. But simply using the camelcase version of the parameter, instead of snakecase, seems like it would fix the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions