Skip to content

Commit 2ffb612

Browse files
committed
fix(validators): handle additional properties object when no other properties are defined
1 parent 69665af commit 2ffb612

File tree

15 files changed

+158
-202
lines changed

15 files changed

+158
-202
lines changed

.changeset/soft-bulldogs-cover.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+
fix(validators): handle additional properties object when no other properties are defined

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,15 @@ export const vDictionaryWithArray = v.object({});
157157
/**
158158
* This is a string dictionary
159159
*/
160-
export const vDictionaryWithDictionary = v.object({});
160+
export const vDictionaryWithDictionary = v.record(v.string(), v.object({}));
161161

162162
/**
163163
* This is a complex dictionary
164164
*/
165-
export const vDictionaryWithProperties = v.object({});
165+
export const vDictionaryWithProperties = v.record(v.string(), v.object({
166+
foo: v.optional(v.string()),
167+
bar: v.optional(v.string())
168+
}));
166169

167170
/**
168171
* This is a type-only model that defines Date as a string

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/zod/default/zod.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,15 @@ export const zDictionaryWithArray = z.object({});
157157
/**
158158
* This is a string dictionary
159159
*/
160-
export const zDictionaryWithDictionary = z.object({});
160+
export const zDictionaryWithDictionary = z.record(z.object({}));
161161

162162
/**
163163
* This is a complex dictionary
164164
*/
165-
export const zDictionaryWithProperties = z.object({});
165+
export const zDictionaryWithProperties = z.record(z.object({
166+
foo: z.string().optional(),
167+
bar: z.string().optional()
168+
}));
166169

167170
/**
168171
* This is a type-only model that defines Date as a string

packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,15 @@ export const vDictionaryWithArray = v.object({});
206206
/**
207207
* This is a string dictionary
208208
*/
209-
export const vDictionaryWithDictionary = v.object({});
209+
export const vDictionaryWithDictionary = v.record(v.string(), v.object({}));
210210

211211
/**
212212
* This is a complex dictionary
213213
*/
214-
export const vDictionaryWithProperties = v.object({});
214+
export const vDictionaryWithProperties = v.record(v.string(), v.object({
215+
foo: v.optional(v.string()),
216+
bar: v.optional(v.string())
217+
}));
215218

216219
/**
217220
* This is a model with one number property

packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,15 @@ export const zDictionaryWithArray = z.object({});
220220
/**
221221
* This is a string dictionary
222222
*/
223-
export const zDictionaryWithDictionary = z.object({});
223+
export const zDictionaryWithDictionary = z.record(z.object({}));
224224

225225
/**
226226
* This is a complex dictionary
227227
*/
228-
export const zDictionaryWithProperties = z.object({});
228+
export const zDictionaryWithProperties = z.record(z.object({
229+
foo: z.string().optional(),
230+
bar: z.string().optional()
231+
}));
229232

230233
/**
231234
* This is a model with one number property

packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ export const vDictionaryWithArray = v.object({});
209209
/**
210210
* This is a string dictionary
211211
*/
212-
export const vDictionaryWithDictionary = v.object({});
212+
export const vDictionaryWithDictionary = v.record(v.string(), v.object({}));
213213

214214
/**
215215
* This is a complex dictionary
216216
*/
217-
export const vDictionaryWithProperties = v.object({});
217+
export const vDictionaryWithProperties = v.record(v.string(), v.object({
218+
foo: v.optional(v.string()),
219+
bar: v.optional(v.string())
220+
}));
218221

219222
/**
220223
* This is a model with one number property

packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/zod/default/zod.gen.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,15 @@ export const zDictionaryWithArray = z.object({});
223223
/**
224224
* This is a string dictionary
225225
*/
226-
export const zDictionaryWithDictionary = z.object({});
226+
export const zDictionaryWithDictionary = z.record(z.object({}));
227227

228228
/**
229229
* This is a complex dictionary
230230
*/
231-
export const zDictionaryWithProperties = z.object({});
231+
export const zDictionaryWithProperties = z.record(z.object({
232+
foo: z.string().optional(),
233+
bar: z.string().optional()
234+
}));
232235

233236
/**
234237
* This is a model with one number property

packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators-metadata/valibot.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const vFoo: v.GenericSchema = v.optional(v.union([
2828

2929
export const vBaz = v.optional(v.pipe(v.pipe(v.string(), v.regex(/foo\nbar/)), v.readonly()), 'baz');
3030

31+
export const vQux = v.record(v.string(), v.object({
32+
qux: v.optional(v.string())
33+
}));
34+
3135
/**
3236
* This is Foo parameter.
3337
*/

packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators-metadata/zod.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const zFoo: z.ZodTypeAny = z.union([
2828

2929
export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz');
3030

31+
export const zQux = z.record(z.object({
32+
qux: z.string().optional()
33+
}));
34+
3135
/**
3236
* This is Foo parameter.
3337
*/

packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/valibot.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const vFoo: v.GenericSchema = v.optional(v.union([
2828

2929
export const vBaz = v.optional(v.pipe(v.pipe(v.string(), v.regex(/foo\nbar/)), v.readonly()), 'baz');
3030

31+
export const vQux = v.record(v.string(), v.object({
32+
qux: v.optional(v.string())
33+
}));
34+
3135
/**
3236
* This is Foo parameter.
3337
*/

packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/zod.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const zFoo: z.ZodTypeAny = z.union([
2828

2929
export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz');
3030

31+
export const zQux = z.record(z.object({
32+
qux: z.string().optional()
33+
}));
34+
3135
/**
3236
* This is Foo parameter.
3337
*/

packages/openapi-ts-tests/test/openapi-ts.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default defineConfig(() => {
158158
{
159159
// comments: false,
160160
// exportFromIndex: true,
161-
// name: 'valibot',
161+
name: 'valibot',
162162
},
163163
{
164164
// case: 'snake_case',

packages/openapi-ts-tests/test/spec/3.1.x/validators.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ components:
104104
pattern: foo\nbar
105105
readOnly: true
106106
type: string
107+
Qux:
108+
additionalProperties:
109+
properties:
110+
qux:
111+
type: string
112+
type: object
113+
type: object

0 commit comments

Comments
 (0)