Commit fb586ad
fix: path parameters with same name as query parameters are always required in generated TypeScript interfaces (#150)
## Summary
- Added a Kubernetes-style scenario to `test/path-parameter/index.yml`
that reproduces the pattern found in
`connectCoreV1HeadNodeProxyWithPath`
(`/api/v1/nodes/{name}/proxy/{path}`) from the Kubernetes OpenAPI spec
- Fixed a bug in `generatePropertySignatures` where a same-named query
parameter would overwrite a path parameter when building the TypeScript
interface, causing `path?: string` instead of the correct `path: string`
- Updated snapshots across all code generators (class, functional,
currying-functional) to reflect the corrected output
## Root Cause
`generatePropertySignatures` in `Parameter.ts` used the parameter name
alone as the deduplication key when building a `typeElementMap`. When a
PathItem defined both a path parameter `path` (required) and a query
parameter `path` (optional) with the same name — as seen in the
Kubernetes spec — the last parameter processed won, and the optional
query parameter overwrote the required path parameter.
## Fix
Sort parameters before reducing so that path parameters are processed
last. Since the reduce uses the parameter name as the key, path
parameters now always overwrite same-named non-path parameters,
preserving the required status in the generated TypeScript interface.
```diff
+ const sorted = [...parameters].sort((a, b): number => {
+ const aIsPath = !Guard.isReference(a) && a.in === "path";
+ const bIsPath = !Guard.isReference(b) && b.in === "path";
+ if (aIsPath && !bIsPath) return 1;
+ if (!aIsPath && bIsPath) return -1;
+ return 0;
+ });
const typeElementMap = sorted.reduce<Record<string, string>>((all, parameter) => {
```
## Test plan
- [ ] `pnpm test:code:gen:class` — regenerate code passes
- [ ] `pnpm test:code:gen:function` — regenerate code passes
- [ ] `pnpm test:code:gen:currying-function` — regenerate code passes
- [ ] `pnpm test:snapshot` — all 53 snapshot tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent f980cc7 commit fb586ad
17 files changed
Lines changed: 4725 additions & 4464 deletions
File tree
- src
- __tests__
- internal
- OpenApiTools/components
- TsGenerator/__tests__
- test
- __tests__
- class/__snapshots__
- currying-functional/__snapshots__
- functional/__snapshots__
- path-parameter
This file was deleted.
Lines changed: 27 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
8 | 14 | | |
9 | 15 | | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | | - | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | | - | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
45 | | - | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | | - | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | | - | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
63 | | - | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
69 | | - | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | | - | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
81 | | - | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
87 | | - | |
| 91 | + | |
88 | 92 | | |
89 | 93 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | 3 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 4 | | |
24 | 5 | | |
25 | 6 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
34 | 20 | | |
35 | 21 | | |
36 | 22 | | |
| |||
41 | 27 | | |
42 | 28 | | |
43 | 29 | | |
44 | | - | |
45 | 30 | | |
46 | 31 | | |
47 | | - | |
48 | 32 | | |
49 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
113 | 122 | | |
114 | 123 | | |
115 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
0 commit comments