[BUG] [Typescript-Angular] client service generator does not honor injected BASE_PATH
Created by: ry99
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output?
Description
I am trying to generate angular client services from a yaml file. I was previously using the swagger-codegen-cli-v3 docker image, but want to switch to openapi-generator-cli. My application injects the BASE_PATH variable in the app.module.ts file using APP_INITIALIZER
callbacks. The BASE_PATH is determined at runtime from a configuration file. It is not available at generation time.
However, when generating client services, the services do not honor the injected BASE_PATH
if the configuration is undefined and the basePath argument is not a string...and the basePath argument is always an array of strings
The swagger generator produces code that accepts the injected value in all cases:
constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
if (basePath) {
this.basePath = basePath;
}
if (configuration) {
this.configuration = configuration;
this.basePath = basePath || configuration.basePath || this.basePath;
}
}
The openapi-generator produces code that ignores the injected basePath (in my case, at least):
constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
if (configuration) {
this.configuration = configuration;
}
if (typeof this.configuration.basePath !== 'string') {
if (typeof basePath !== 'string') {
basePath = this.basePath;
}
this.configuration.basePath = basePath;
}
this.encoder = this.configuration.encoder || new CustomHttpParameterCodec();
}
The basePath
argument is an array, not a string (I return a string from my APP_INITIALIZER
), so the code block uses the (incorrect) default basePath.
openapi-generator version
6.0.1
OpenAPI declaration file content or url
Seems to happen with any yaml (probably json, too). I just picked one off the internet
https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml
Generation Details
Steps to reproduce
- openapi-generator-cli generate -i XXX.yaml -g typescript-angular -o generated --additional-properties=ngVersion=14.15.4,providedInRoot=true
Related issues/PRs
#12936
Suggest a fix
I assume the basePath
argument to the service constructor is supposed to be an array, so the moustache file needs to be updated to reflect the argument types, and handle them appropriately.