zod#ZodTypeDef TypeScript Examples

The following examples show how to use zod#ZodTypeDef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: parseDef.ts    From zod-to-json-schema with ISC License 6 votes vote down vote up
export function parseDef(
  def: ZodTypeDef,
  refs: References
): JsonSchema7Type | undefined {
  const item = refs.items.find((x) => Object.is(x.def, def));
  if (item) return select$refStrategy(item, refs);
  const newItem: Item = { def, path: refs.currentPath, jsonSchema: undefined };
  refs.items.push(newItem);
  const jsonSchema = selectParser(def, (def as any).typeName, refs);
  if (jsonSchema) addMeta(def, jsonSchema);
  newItem.jsonSchema = jsonSchema;
  return jsonSchema;
}
Example #2
Source File: parseDef.ts    From zod-to-json-schema with ISC License 5 votes vote down vote up
addMeta = (
  def: ZodTypeDef,
  jsonSchema: JsonSchema7Type
): JsonSchema7Type => {
  if (def.description) jsonSchema.description = def.description;
  return jsonSchema;
}