Skip to content

fix: preserve existing OpenAPI environment files - #408

Closed
KennyMcSimpson wants to merge 1 commit into
darrenburns:2.xfrom
KennyMcSimpson:fix/preserve-imported-env
Closed

KennyMcSimpson wants to merge 1 commit into
darrenburns:2.xfrom
KennyMcSimpson:fix/preserve-imported-env

Conversation

@KennyMcSimpson

@KennyMcSimpson KennyMcSimpson commented Oct 24, 2026 •

Copy link
Copy Markdown

Closes #91

Importing an OpenAPI document writes environment files into the source directory. If a file already exists, including an environment file from an earlier import, the importer currently overwrites its contents. Different server URLs can also collapse to the same generated filename.

Create environment files exclusively and choose a numbered filename when the destination exists. Existing bytes remain intact, and the generated collection README references the filename actually created.

Validation: all six added regression cases fail against the original implementation and pass with this change. The 40 OpenAPI, Postman, and curl import tests pass through the repository Makefile test target. Coverage includes OpenAPI 3.0/3.1, existing .env and named files, repeated imports, and colliding server names.

The full local suite was stopped after 300 seconds in UI snapshot tests. Separate baseline checks reproduce Windows-only timezone (time.tzset) and POSIX file-mode failures in the original source. The upstream Linux workflow is awaiting maintainer approval.

@chiragjangiir chiragjangiir left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix for preserving existing .env files during OpenAPI spec imports (#91).

Key strengths:

  1. Atomic creation: Using open("x") with FileExistsError handling guarantees atomic file creation without TOCTOU (time-of-check-to-time-of-use) race conditions between existence checks and writes.
  2. Deterministic versioning: Suffixing collision candidates as {stem}.{number}{suffix} (e.g. api_example_test.2.env) correctly handles multiple servers with identical sanitized domain names (e.g. http:// vs https://).
  3. Readme synchronization: The generated collection README references the actual created filename (collection.readme), keeping documentation consistent with disk state.

LGTM! Parametrized tests across OpenAPI 3.0.3 and 3.1.0 cover both single and multiple collisions cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants