Skip to content

Commit 52c595d

Browse files
committed
Fix another bug
1 parent 81b4a95 commit 52c595d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/examples.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
"additionalProperties": false,
4040
"$schema": "http://json-schema.org/draft-07/schema#"
4141
},
42+
{
43+
"type": "object",
44+
"properties": {
45+
"filter": {
46+
"type": "string",
47+
"description": "Filter the apps by name or description. Looks for substrings."
48+
}
49+
},
50+
"additionalProperties": false,
51+
"$schema": "http://json-schema.org/draft-07/schema#"
52+
},
4253
{
4354
"type": "object",
4455
"properties": {

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ export function convertJsonSchemaToZod(schema: JSONSchema): z.ZodTypeAny {
182182
shape[key] = shape[key].optional();
183183
}
184184
}
185+
} else {
186+
// In JSON Schema, properties are optional by default
187+
// if no required array is specified
188+
for (const key of Object.keys(shape)) {
189+
shape[key] = shape[key].optional();
190+
}
185191
}
186192

187193
// Create the schema with or without passthrough based on additionalProperties

0 commit comments

Comments
 (0)