Skip to content

Commit f6d4512

Browse files
committed
docs: add changesets
1 parent 6056043 commit f6d4512

231 files changed

Lines changed: 3872 additions & 2384 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/early-bodies-stay.md‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
---
22
"@hey-api/openapi-ts": patch
3-
"@hey-api/custom-client": patch
43
---
54

6-
**client**: send an explicitly-provided empty object request body instead of dropping it
7-
8-
When an operation was called with an empty object body (for example when every body field is optional and none were supplied), `buildClientParams` treated the empty object as an unused slot and stripped it. The request was then sent with no body and no `Content-Type` header, which servers requiring `application/json` reject. An explicitly-provided body — including an empty object — is now preserved and sent as-is, while requests genuinely without a body continue to send none.
5+
**plugin(@hey-api/client-angular)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎.changeset/new-owls-wait.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/client-next)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎.changeset/new-ties-say.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/client-axios)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎.changeset/pretty-pandas-talk.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/client-ky)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎.changeset/salty-poems-taste.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/client-nuxt)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎.changeset/sharp-places-roll.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/client-ofetch)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎.changeset/shy-moose-press.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/client-fetch)**: fix: send an empty object request body when explicitly provided in flat parameters mode

‎packages/custom-client/src/core/params.ts‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,19 @@ function buildKeyMap(fields: FieldsConfig, map?: KeyMap): KeyMap {
5858

5959
interface Params {
6060
body?: unknown;
61-
headers?: Record<string, unknown>;
62-
path?: Record<string, unknown>;
63-
query?: Record<string, unknown>;
61+
headers: Record<string, unknown>;
62+
path: Record<string, unknown>;
63+
query: Record<string, unknown>;
6464
}
6565

66-
// Strips constructed slots (headers/path/query) that ended up empty, so we
67-
// don't send an empty object the caller never populated. `body` is deliberately
68-
// excluded: unlike the other slots it is supplied by the caller, so an explicit
69-
// empty body (e.g. `{}`) is a real value and must be sent as-is.
70-
const stripEmptySlots = (params: Params) => {
66+
function stripEmptySlots(params: Params): void {
7167
for (const [slot, value] of Object.entries(params)) {
72-
if (slot === 'body') {
73-
continue;
74-
}
75-
if (value && typeof value === 'object' && !Object.keys(value).length) {
68+
if (slot === 'body') continue;
69+
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
7670
delete params[slot as Slot];
7771
}
7872
}
79-
};
73+
}
8074

8175
export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params {
8276
const params: Params = {
@@ -87,18 +81,14 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
8781

8882
const map = buildKeyMap(fields);
8983

90-
// Writes a single field into its slot. `body` has no placeholder and is
91-
// created on first write, so a request without a body sends none, while an
92-
// explicitly-provided body is preserved by `stripEmptySlots`. The null
93-
// prototype guards against prototype pollution (GHSA-hhx9-57xq-r5rw).
94-
const writeSlot = (slot: Slot, key: string, value: unknown): void => {
84+
function writeSlot(slot: Slot, key: string, value: unknown): void {
9585
let record = params[slot] as Record<string, unknown> | undefined;
9686
if (record === undefined) {
9787
record = Object.create(null) as Record<string, unknown>;
9888
params[slot] = record;
9989
}
10090
record[key] = value;
101-
};
91+
}
10292

10393
let config: FieldsConfig[number] | undefined;
10494

@@ -115,7 +105,9 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
115105
if (config.key) {
116106
const field = map.get(config.key)!;
117107
const name = field.map || config.key;
118-
writeSlot(field.in, name, arg);
108+
if (field.in) {
109+
writeSlot(field.in, name, arg);
110+
}
119111
} else {
120112
params.body = arg;
121113
}

‎packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/core/params.gen.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,39 @@ function buildKeyMap(fields: FieldsConfig, map?: KeyMap): KeyMap {
8888
}
8989

9090
interface Params {
91-
body: unknown;
91+
body?: unknown;
9292
headers: Record<string, unknown>;
9393
path: Record<string, unknown>;
9494
query: Record<string, unknown>;
9595
}
9696

97-
type ParamsSlotMap = Record<Slot, unknown>;
98-
99-
function stripEmptySlots(params: ParamsSlotMap): void {
97+
function stripEmptySlots(params: Params): void {
10098
for (const [slot, value] of Object.entries(params)) {
99+
if (slot === 'body') continue;
101100
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
102101
delete params[slot as Slot];
103102
}
104103
}
105104
}
106105

107106
export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params {
108-
const params: ParamsSlotMap = {
109-
body: Object.create(null),
107+
const params: Params = {
110108
headers: Object.create(null),
111109
path: Object.create(null),
112110
query: Object.create(null),
113111
};
114112

115113
const map = buildKeyMap(fields);
116114

115+
function writeSlot(slot: Slot, key: string, value: unknown): void {
116+
let record = params[slot] as Record<string, unknown> | undefined;
117+
if (record === undefined) {
118+
record = Object.create(null) as Record<string, unknown>;
119+
params[slot] = record;
120+
}
121+
record[key] = value;
122+
}
123+
117124
let config: FieldsConfig[number] | undefined;
118125

119126
for (const [index, arg] of args.entries()) {
@@ -130,7 +137,7 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
130137
const field = map.get(config.key)!;
131138
const name = field.map || config.key;
132139
if (field.in) {
133-
(params[field.in] as Record<string, unknown>)[name] = arg;
140+
writeSlot(field.in, name, arg);
134141
}
135142
} else {
136143
params.body = arg;
@@ -142,7 +149,7 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
142149
if (field) {
143150
if (field.in) {
144151
const name = field.map || key;
145-
(params[field.in] as Record<string, unknown>)[name] = value;
152+
writeSlot(field.in, name, value);
146153
} else {
147154
params[field.map] = value;
148155
}
@@ -151,11 +158,11 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
151158

152159
if (extra) {
153160
const [prefix, slot] = extra;
154-
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
161+
writeSlot(slot, key.slice(prefix.length), value);
155162
} else if ('allowExtra' in config && config.allowExtra) {
156163
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
157164
if (allowed) {
158-
(params[slot as Slot] as Record<string, unknown>)[key] = value;
165+
writeSlot(slot as Slot, key, value);
159166
break;
160167
}
161168
}
@@ -167,5 +174,5 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
167174

168175
stripEmptySlots(params);
169176

170-
return params as Params;
177+
return params;
171178
}

‎packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/core/params.gen.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,39 @@ function buildKeyMap(fields: FieldsConfig, map?: KeyMap): KeyMap {
8888
}
8989

9090
interface Params {
91-
body: unknown;
91+
body?: unknown;
9292
headers: Record<string, unknown>;
9393
path: Record<string, unknown>;
9494
query: Record<string, unknown>;
9595
}
9696

97-
type ParamsSlotMap = Record<Slot, unknown>;
98-
99-
function stripEmptySlots(params: ParamsSlotMap): void {
97+
function stripEmptySlots(params: Params): void {
10098
for (const [slot, value] of Object.entries(params)) {
99+
if (slot === 'body') continue;
101100
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
102101
delete params[slot as Slot];
103102
}
104103
}
105104
}
106105

107106
export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params {
108-
const params: ParamsSlotMap = {
109-
body: Object.create(null),
107+
const params: Params = {
110108
headers: Object.create(null),
111109
path: Object.create(null),
112110
query: Object.create(null),
113111
};
114112

115113
const map = buildKeyMap(fields);
116114

115+
function writeSlot(slot: Slot, key: string, value: unknown): void {
116+
let record = params[slot] as Record<string, unknown> | undefined;
117+
if (record === undefined) {
118+
record = Object.create(null) as Record<string, unknown>;
119+
params[slot] = record;
120+
}
121+
record[key] = value;
122+
}
123+
117124
let config: FieldsConfig[number] | undefined;
118125

119126
for (const [index, arg] of args.entries()) {
@@ -130,7 +137,7 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
130137
const field = map.get(config.key)!;
131138
const name = field.map || config.key;
132139
if (field.in) {
133-
(params[field.in] as Record<string, unknown>)[name] = arg;
140+
writeSlot(field.in, name, arg);
134141
}
135142
} else {
136143
params.body = arg;
@@ -142,7 +149,7 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
142149
if (field) {
143150
if (field.in) {
144151
const name = field.map || key;
145-
(params[field.in] as Record<string, unknown>)[name] = value;
152+
writeSlot(field.in, name, value);
146153
} else {
147154
params[field.map] = value;
148155
}
@@ -151,11 +158,11 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
151158

152159
if (extra) {
153160
const [prefix, slot] = extra;
154-
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
161+
writeSlot(slot, key.slice(prefix.length), value);
155162
} else if ('allowExtra' in config && config.allowExtra) {
156163
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
157164
if (allowed) {
158-
(params[slot as Slot] as Record<string, unknown>)[key] = value;
165+
writeSlot(slot as Slot, key, value);
159166
break;
160167
}
161168
}
@@ -167,5 +174,5 @@ export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsCo
167174

168175
stripEmptySlots(params);
169176

170-
return params as Params;
177+
return params;
171178
}

0 commit comments

Comments
 (0)