OpenAPITools / OpenAPITools/openapi-generator-cli

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

Aperta
#1,094 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@kay-schecker ci sta già lavorando.

Dal 9/1/2026.

bug
Lingua principale
TypeScript
Stelle
2k
Fork
208
Merge medio
7h 12m
PR unite (30g)
6

Descrizione

🐛 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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.