@signe/schema-to-zod 2.5.1 → 2.6.0

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/dist/index.js CHANGED
@@ -4179,10 +4179,11 @@ function getTypeFunction(schema) {
4179
4179
  }
4180
4180
  __name(getTypeFunction, "getTypeFunction");
4181
4181
  function convertPropertyToZod(schema, key, parentSchema) {
4182
+ const required = Array.isArray(parentSchema.required) && parentSchema.required.includes(key);
4182
4183
  if (schema.type === "object") {
4183
- return z.object(jsonSchemaToZod(schema));
4184
+ const objectSchema = z.object(jsonSchemaToZod(schema));
4185
+ return required ? objectSchema : objectSchema.optional();
4184
4186
  }
4185
- const required = Array.isArray(parentSchema.required) && parentSchema.required.includes(key);
4186
4187
  const typeValidator = applyValidators(getTypeFunction(schema), schema, required);
4187
4188
  return required ? typeValidator : typeValidator.optional();
4188
4189
  }