Skip to content

Commit 1b15515

Browse files
authored
fix(openapi-client): handle empty objects in bracket-notation deserialization (#196)
1 parent 61aba35 commit 1b15515

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/openapi-client/src/adapters/standard/bracket-notation.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ describe('bracketNotation', () => {
8787
})
8888

8989
describe('.deserialize', () => {
90+
it('can deserialize empty objects', () => {
91+
expect(serializer.deserialize([])).toEqual({})
92+
})
93+
9094
it('can deserialize arrays', () => {
9195
expect(serializer.deserialize([
9296
['', 1],
@@ -181,6 +185,7 @@ describe('bracketNotation', () => {
181185
})
182186

183187
it.each([
188+
[{ }],
184189
[{ a: 1, b: 2, c: [1, 2, { a: 1, b: 2 }, new Date(), new Blob([]), new Set([1, 2]), new Map([[1, 2]])] }],
185190
])('.serialize + .deserialize', (value) => {
186191
expect(serializer.deserialize(serializer.serialize(value))).toEqual(value)

packages/openapi-client/src/adapters/standard/bracket-notation.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ export class BracketNotationSerializer {
2323
return result
2424
}
2525

26-
deserialize(serialized: BracketNotationSerialized): unknown {
26+
deserialize(serialized: BracketNotationSerialized): Record<string, unknown> | unknown[] {
27+
if (serialized.length === 0) {
28+
return {}
29+
}
30+
2731
const arrayPushStyles = new WeakSet()
28-
const ref = { value: [] }
32+
const ref: { value: Record<string, unknown> | unknown[] } = { value: [] }
2933

3034
for (const [path, value] of serialized) {
3135
const segments = this.parsePath(path)

0 commit comments

Comments
 (0)