Skip to content

[BUG] [typescript-angular] Base Path can't be set to '<empty string>' #2731

@DanielHabenicht

Description

@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/[email protected]
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
  1. Generate typescript-angular package from openapi.config
  2. Configure the ApiModule in app.module.ts
  3. Use a service from the generated typescript-angular package.
Related issues/PRs

Nothing found.

Suggest a fix

Two ways:

  1. Remove the fallback basePath by setting it to '' (empty string)
  2. Fix the evalutation basePath property.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions