Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
defmonk0 opened this issue Oct 19, 2017 · 2 comments · Fixed by #6769
Closed

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

defmonk0 opened this issue Oct 19, 2017 · 2 comments · Fixed by #6769

Comments

@defmonk0
Copy link
Contributor

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.

@macjohnny
Copy link
Contributor

@defmonk0 I would say the relevant line is here:

op.path = op.path.replaceAll("\\{(.*?)\\}", "\\$\\{encodeURIComponent(String($1))\\}");

the conversion from snake case to camel case is missing here.
could you open a PR suggesting a way to do that?

@defmonk0
Copy link
Contributor Author

Yea. I was looking and just realized that the line I was pointing to was using path instead of paramName like the function parameters were. I was trying to find where path was defined just now, so that's good. Lol. I'll look into it, see if I can figure out an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants