Skip to content

Commit b3c2755

Browse files
authored
Merge pull request #3841 from hey-api/pullfrog/3838-fix-duplicate-key-in-transformers
2 parents 216ba90 + d880caa commit b3c2755

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

.changeset/purple-jars-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(@hey-api/transformers)**: fix: use symbols for `additionalProperties` key variables

packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,17 @@ function processSchemaType({
195195
}
196196

197197
if (schema.additionalProperties && dataExpression) {
198+
const key = plugin.symbol('key');
198199
const entryValueNodes = processSchemaType({
199-
dataExpression: $(dataExpression).attr('key').computed(),
200+
dataExpression: $(dataExpression).attr(key).computed(),
200201
plugin,
201202
schema: schema.additionalProperties,
202203
});
203204

204205
if (entryValueNodes.length) {
205206
const properties = Object.keys(schema.properties ?? {});
206207
nodes.push(
207-
$.for($.const('key'))
208+
$.for($.const(key))
208209
.of($('Object').attr('keys').call(dataExpression))
209210
.$if(
210211
properties.length,
@@ -214,7 +215,7 @@ function processSchemaType({
214215
$.not(
215216
$.array(...properties)
216217
.attr('includes')
217-
.call('key'),
218+
.call(key),
218219
),
219220
).do(...entryValueNodes),
220221
),

packages/openapi-ts/src/ts-dsl/stmt/for.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class ImplForTsDsl<M extends ForMode = 'for'> extends Mixed {
4242
override analyze(ctx: AnalysisContext): void {
4343
ctx.analyze(this._condition);
4444
ctx.analyze(this._iterableOrUpdate);
45-
ctx.analyze(this._variableOrInit);
4645
ctx.pushScope();
46+
ctx.analyze(this._variableOrInit);
4747
try {
4848
super.analyze(ctx);
4949
} finally {

0 commit comments

Comments
 (0)