@signe/schema-to-zod 2.5.0 → 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/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -2
- package/tests/validate.spec.ts +693 -10
package/package.json
CHANGED
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
|
-
|
|
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
|
}
|