Skip to content

Commit 583f5ba

Browse files
committed
fix: πŸ› change how additionalProperties are typed
This removes the `| undefined` addition to additional properties in an object βœ… Closes: openapi-ts#1070
1 parent 04c8379 commit 583f5ba

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

β€Žpnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žsrc/transform/schema-object.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export function defaultSchemaObjectTransform(
191191
});
192192
}
193193
}
194-
coreType.push(indent(`[key: string]: ${tsUnionOf(addlType ? addlType : "unknown", "undefined")};`, indentLv)); // note: `| undefined` is required to mesh with possibly-undefined keys
194+
coreType.push(indent(`[key: string]: ${addlType ? addlType : "unknown"};`, indentLv));
195195
}
196196
indentLv--;
197197
}

β€Žtest/schema-object.test.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const options: TransformSchemaObjectOptions = {
1414
operations: {},
1515
pathParamsAsTypes: false,
1616
postTransform: undefined,
17+
parameters: {},
1718
silent: true,
1819
supportArrayLength: false,
1920
transform: undefined,
@@ -202,15 +203,15 @@ describe("Schema Object", () => {
202203
const generated = transformSchemaObject(schema, options);
203204
expect(generated).toBe(`{
204205
property?: boolean;
205-
[key: string]: string | undefined;
206+
[key: string]: string;
206207
}`);
207208
});
208209

209210
test("additionalProperties: true", () => {
210211
const schema: SchemaObject = { type: "object", additionalProperties: true };
211212
const generated = transformSchemaObject(schema, options);
212213
expect(generated).toBe(`{
213-
[key: string]: unknown | undefined;
214+
[key: string]: unknown;
214215
}`);
215216
});
216217

@@ -221,15 +222,15 @@ describe("Schema Object", () => {
221222
};
222223
const generated = transformSchemaObject(schema, options);
223224
expect(generated).toBe(`{
224-
[key: string]: string | undefined;
225+
[key: string]: string;
225226
}`);
226227
});
227228

228229
test("additionalProperties: {}", () => {
229230
const schema: SchemaObject = { type: "object", additionalProperties: {} };
230231
const generated = transformSchemaObject(schema, options);
231232
expect(generated).toBe(`{
232-
[key: string]: unknown | undefined;
233+
[key: string]: unknown;
233234
}`);
234235
});
235236

@@ -424,7 +425,7 @@ describe("Schema Object", () => {
424425
});
425426
expect(generated).toBe(`{
426427
fixed: boolean;
427-
[key: string]: unknown | undefined;
428+
[key: string]: unknown;
428429
}`);
429430
});
430431
});
@@ -516,9 +517,9 @@ describe("Schema Object", () => {
516517
ctx: { ...options.ctx, immutableTypes: true },
517518
});
518519
expect(generated).toBe(`{
519-
readonly array?: (readonly ({
520-
[key: string]: unknown | undefined;
521-
})[]) | null;
520+
readonly array?: readonly ({
521+
[key: string]: unknown;
522+
})[] | null;
522523
}`);
523524
});
524525
});

0 commit comments

Comments
Β (0)