Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type Schema =
// | BaseSchema;

export interface BaseSchema {
/** A special key used as an intermediate representation of extends-style relationships. Removed in the omit stage. */
_ref?: BaseSchema;

type?: string | undefined;
$id?: string | undefined;
id?: string | undefined;
Expand Down
26 changes: 9 additions & 17 deletions packages/core/src/registries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,20 @@ export interface JSONSchemaMeta {
[k: string]: unknown;
}

export class $ZodJSONSchemaRegistry<
Meta extends JSONSchemaMeta = JSONSchemaMeta,
Schema extends $ZodType = $ZodType,
> extends $ZodRegistry<Meta, Schema> {
toJSONSchema(_schema: Schema): object {
return {};
}
}
// export class $ZodJSONSchemaRegistry<
// Meta extends JSONSchemaMeta = JSONSchemaMeta,
// Schema extends $ZodType = $ZodType,
// > extends $ZodRegistry<Meta, Schema> {
// toJSONSchema(_schema: Schema): object {
// return {};
// }
// }

export interface GlobalMeta extends JSONSchemaMeta {}

export const globalRegistry: $ZodJSONSchemaRegistry<GlobalMeta> =
/*@__PURE__*/ new $ZodJSONSchemaRegistry<GlobalMeta>();

// registries
export function registry<T extends MetadataType = MetadataType, S extends $ZodType = $ZodType>(): $ZodRegistry<T, S> {
return new $ZodRegistry<T, S>();
}

export function jsonSchemaRegistry<
T extends JSONSchemaMeta = JSONSchemaMeta,
S extends $ZodType = $ZodType,
>(): $ZodJSONSchemaRegistry<T, S> {
return new $ZodJSONSchemaRegistry();
}
export const globalRegistry: $ZodRegistry<GlobalMeta> = /*@__PURE__*/ registry<GlobalMeta>();
5 changes: 4 additions & 1 deletion packages/core/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface $ZodTypeInternals<out O = unknown, out I = unknown> extends $Zo
/** The constructor function of this schema. */
constr: new (
def: any
) => any;
) => $ZodType;

/** A catchall object for computed metadata related to this schema. Commonly modified by checks using `onattach`. */
computed: Record<string, any>;
Expand All @@ -140,6 +140,9 @@ export interface $ZodTypeInternals<out O = unknown, out I = unknown> extends $Zo

/** An optional method used to override `toJSONSchema` logic. */
toJSONSchema?: () => object;

/** The parent of this schema. Only set during certain clone operations. */
parent?: $ZodType | undefined;
}

export interface $ZodType<out O = unknown, out I = unknown> {
Expand Down
Loading