[BUG] Environment variable not found (missing .env loading)
@kay-schecker đang làm issue này rồi.
Từ ngày 9/1/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
🐛 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:
- Create a .env file with the following content:
ART_USER=testuser
ART_PASSWORD=testpassword
- 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"
}
}
}
- 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.
- Ngôn ngữ chính
- TypeScript
- Star
- 2k
- Fork
- 208
- Merge trung bình
- 7 giờ 12 phút
- Pull request đã merge (30 ngày)
- 6
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenAPITools/openapi-generator-cli
-
[FEATURE] consider using caret ranges instead of pinned exact versions for runtime dependencies Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
bug
OpenAPITools/openapi-generator-cli#1213 · 1 người được giao ·
-
bug
OpenAPITools/openapi-generator-cli#1190 · 1 người được giao ·
-
bug
OpenAPITools/openapi-generator-cli#1138 · 1 bình luận · 1 người được giao ·
-
bug
OpenAPITools/openapi-generator-cli#991 · 1 người được giao ·
Tất cả issue của OpenAPITools/openapi-generator-cli
Issue tương tự
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Crush Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
catppuccin/catppuccin#3125 ·
-
Add a SECURITY.md Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
ElementsProject/cln-application#167 · 1 bình luận · 1 reaction ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Quantco/pnpm-licenses#17 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100