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

Abierto
#1,094 1 comentario 0 reacciones 1 asignado Ver en GitHub

@kay-schecker ya está trabajando en esto.

Desde el 9/1/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug

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

Lenguaje dominante
TypeScript
Estrellas
2k
Forks
208
Merge medio
7 h 12 min
PR fusionados (30 d)
6

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenAPITools/openapi-generator-cli

Todos los issues de OpenAPITools/openapi-generator-cli

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.