@signe/schema-to-zod 2.5.1 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signe/schema-to-zod",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -162,11 +162,13 @@ function convertPropertyToZod(
162
162
  key: string,
163
163
  parentSchema: JSONSchema7
164
164
  ): ZodType<unknown> {
165
+ const required = Array.isArray(parentSchema.required) && parentSchema.required.includes(key);
166
+
165
167
  if (schema.type === 'object') {
166
- return z.object(jsonSchemaToZod(schema));
168
+ const objectSchema = z.object(jsonSchemaToZod(schema));
169
+ return required ? objectSchema : objectSchema.optional();
167
170
  }
168
171
 
169
- const required = Array.isArray(parentSchema.required) && parentSchema.required.includes(key);
170
172
  const typeValidator = applyValidators(getTypeFunction(schema), schema, required);
171
173
  return required ? typeValidator : typeValidator.optional();
172
174
  }