json-schema-generator.d.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type * as JSONSchema from "./json-schema.js";
  2. import type { $ZodRegistry } from "./registries.js";
  3. import type * as schemas from "./schemas.js";
  4. import { type JSONSchemaGeneratorParams, type ProcessParams, type Seen } from "./to-json-schema.js";
  5. /**
  6. * Parameters for the emit method of JSONSchemaGenerator.
  7. * @deprecated Use toJSONSchema function instead
  8. */
  9. export type EmitParams = Pick<JSONSchemaGeneratorParams, "cycles" | "reused" | "external">;
  10. /**
  11. * Parameters for JSONSchemaGenerator constructor.
  12. * @deprecated Use toJSONSchema function instead
  13. */
  14. type JSONSchemaGeneratorConstructorParams = Pick<JSONSchemaGeneratorParams, "metadata" | "target" | "unrepresentable" | "override" | "io">;
  15. /**
  16. * Legacy class-based interface for JSON Schema generation.
  17. * This class wraps the new functional implementation to provide backward compatibility.
  18. *
  19. * @deprecated Use the `toJSONSchema` function instead for new code.
  20. *
  21. * @example
  22. * ```typescript
  23. * // Legacy usage (still supported)
  24. * const gen = new JSONSchemaGenerator({ target: "draft-07" });
  25. * gen.process(schema);
  26. * const result = gen.emit(schema);
  27. *
  28. * // Preferred modern usage
  29. * const result = toJSONSchema(schema, { target: "draft-07" });
  30. * ```
  31. */
  32. export declare class JSONSchemaGenerator {
  33. private ctx;
  34. /** @deprecated Access via ctx instead */
  35. get metadataRegistry(): $ZodRegistry<Record<string, any>>;
  36. /** @deprecated Access via ctx instead */
  37. get target(): ({} & string) | "draft-2020-12" | "draft-07" | "openapi-3.0" | "draft-04";
  38. /** @deprecated Access via ctx instead */
  39. get unrepresentable(): "any" | "throw";
  40. /** @deprecated Access via ctx instead */
  41. get override(): (ctx: {
  42. zodSchema: schemas.$ZodType;
  43. jsonSchema: JSONSchema.BaseSchema;
  44. path: (string | number)[];
  45. }) => void;
  46. /** @deprecated Access via ctx instead */
  47. get io(): "input" | "output";
  48. /** @deprecated Access via ctx instead */
  49. get counter(): number;
  50. set counter(value: number);
  51. /** @deprecated Access via ctx instead */
  52. get seen(): Map<schemas.$ZodType, Seen>;
  53. constructor(params?: JSONSchemaGeneratorConstructorParams);
  54. /**
  55. * Process a schema to prepare it for JSON Schema generation.
  56. * This must be called before emit().
  57. */
  58. process(schema: schemas.$ZodType, _params?: ProcessParams): JSONSchema.BaseSchema;
  59. /**
  60. * Emit the final JSON Schema after processing.
  61. * Must call process() first.
  62. */
  63. emit(schema: schemas.$ZodType, _params?: EmitParams): JSONSchema.BaseSchema;
  64. }
  65. export {};