[BUG] [typescript-angular] Base Path can't be set to '<empty string>'
Created by: DanielHabenicht
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
If the basePath
in the config is set to ''
(empty string). The configuration is ignored and 'http://localhost'
is used instead. That is unexpected behaviour.
Background
The basePath of the typescript-angular generated Files are currently set to 'http://localhost'
(as a Fallback). When trying to setup the basePath to ''
(empty String) the config is not used as the generated line of code configuration.basePath || basePath || this.basePath;
is evaluated to false, because empty string in javascript is false.
protected basePath = 'http://localhost';
public configuration = new Configuration();
constructor(
protected httpClient: HttpClient,
@Optional() @Inject(BASE_PATH) basePath: string,
@Optional() configuration: Configuration
) {
if (configuration) {
this.configuration = configuration;
this.configuration.basePath = configuration.basePath || basePath || this.basePath;
} else {
this.configuration.basePath = basePath || this.basePath;
}
}
openapi-generator version
4.0.0-beta2
OpenAPI declaration file content or url
Command line used for generation
npm install @openapitools/openapi-generator-cli@0.0.8-4.0.0-beta2
openapi-generator generate -i swagger.json -g typescript-angular -o projects/client-api/src/lib/ --additional-properties="ngVersion=6.1.7" --additional-properties="supportsES6=true"
Steps to reproduce
- Generate typescript-angular package from openapi.config
- Configure the
ApiModule
in app.module.ts - Use a service from the generated typescript-angular package.
Related issues/PRs
Nothing found.
Suggest a fix
Two ways:
- Remove the fallback basePath by setting it to
''
(empty string) - Fix the evalutation
basePath
property.