OpenAPITools / OpenAPITools/openapi-generator-cli

[BUG] Environment variable not found (missing .env loading)

Offen
#1,094 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@kay-schecker arbeitet bereits daran.

Seit 09.1.2026.

bug
Vorherrschende Sprache
TypeScript
Sterne
2k
Forks
208
Ø Merge
7 Std. 12 Min.
Gemergte PRs (30 T.)
6

Beschreibung

🐛 Bug Report:

Describe the bug

The ConfigService in the @openapitools/openapi-generator-cli package does not explicitly load .env files, which causes environment variables defined in .env to be inaccessible during placeholder replacement in the openapitools.json configuration file. This leads to errors when using ${env.VARIABLE_NAME} placeholders if the variables are not explicitly exported in the shell.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a .env file with the following content:
ART_USER=testuser
ART_PASSWORD=testpassword
  1. Use ${env.ART_USER} and ${env.ART_PASSWORD} placeholders in the openapitools.json file.
    For example:
{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.4.0",
    "repository": {
      "downloadUrl": "https://${env.ART_USER}:${env.ART_PASSWORD}@artifactory.mycorp.com/maven-central/${groupId}/${artifactId}/${versionName}/${artifactId}-${versionName}.jar"
    }
  }
}
  1. Run the openapi-generator-cli command without explicitly exporting the environment variables in the shell.
    Observe that the placeholders are not replaced, and an error is logged:
Download 7.4.0 ...
Environment variable for placeholder 'ART_USER' not found.
Environment variable for placeholder 'ART_PASSWORD' not found.
Download failed, because of: "Request failed with status code 401"
Expected behavior

The ConfigService should automatically load .env files so that environment variables defined in .env are accessible during placeholder replacement.

Screenshots

N/A

Operation System:
  • OS: MacOS
  • Version: Sequoia 15.5
Package System:
  • @openapitools/openapi-generator-cli Version: 2.27.0
Additional context

The issue lies in the replacePlaceholders class. While it attempts to replace placeholders with environment variables, it does not explicitly load .env files. This can be fixed by adding support for .env file loading using the dotenv package.

Suggested fix

Modify the ConfigService to explicitly load .env files in its constructor:

import { config as loadEnv } from 'dotenv'; // Import dotenv

constructor(
  @Inject(LOGGER) private readonly logger: LOGGER,
  @Inject(COMMANDER_PROGRAM) private readonly program: Command,
) {
  // Explicitly load .env file
  loadEnv();
}

This ensures that .env variables are loaded into process.env before placeholder replacement occurs.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.