fix: preserve parameter order while ensuring path parameters win over same-named query parameters#151
Merged
Conversation
…napshot Replace vitest .snap files with plain .ts files per directory structure. Each snapshot is now stored as a readable TypeScript file alongside the generated code it verifies, making diffs easier to review in PRs. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Generated snapshot files in __snapshots__ directories contain TypeScript output from the code generator that is not expected to be type-safe. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toMatchSnapshottotoMatchFileSnapshotfor better diff readabilitygeneratePropertySignatureswhere same-named parameters were reorderedProblem
The previous fix for same-named path/query parameter conflicts (#150) used
.sort()to push path parameters to the end of the array before reducing into aRecord. This caused all path parameters to appear last in the generated TypeScript interface, regardless of their position in the OpenAPI spec.For example, when the spec defines:
The previous output was:
Additionally, the Kubernetes v1.28.6 spec exposes a second pattern: both the path parameter and the query parameter with the same name (
path) are defined as$refreferences. The previous sort only resolvedinfor inline parameters, so both references were treated as non-path and the query parameter reference (appearing last) won.Fix
Replaced the sort +
Recordreduce approach with aMap-based iteration that preserves insertion order:Mappreserves insertion order onset()of an existing key)resolveParameterInnow resolves$refreferences viastore.getParameter()so both inline and referenced path parameters are correctly identifiedTest plan
pnpm test:code:gen:class— regenerate code passespnpm test:code:gen:function— regenerate code passespnpm test:code:gen:currying-function— regenerate code passespnpm test:snapshot— all 54 snapshot tests pass$ref-based path/query conflict scenario added totest/path-parameter/index.yml🤖 Generated with Claude Code