From bb9424563643507466f12e974c8566b154b29d8f Mon Sep 17 00:00:00 2001 From: jai <86279939+Jayavardhan11@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:51:07 +0530 Subject: [PATCH] feat(types): define base schema types for JSON Schema Introduced Schema, StringSchema, ObjectSchema, etc., to serve as base for all helpers. --- src/types.ts | 84 +++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/types.ts b/src/types.ts index 9416cce..441688b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,58 +1,62 @@ -export type Schema = StringSchema | NumberSchema | IntegerSchema | BooleanSchema | ArraySchema | ObjectSchema | NullSchema | RefSchema | AnyOfSchema - -export type BaseSchema = { - title?: string - description?: string - const?: T - enum?: T[] +export interface BaseSchema { + title?: string; + description?: string; + default?: any; } -export type StringSchema = BaseSchema & { - type: 'string' - pattern?: string - format?: string +export interface StringSchema extends BaseSchema { + type: 'string'; + enum?: string[]; + pattern?: string; + minLength?: number; + maxLength?: number; } -export type NumberSchema = BaseSchema & { - type: 'number' - multipleOf?: number - maximum?: number - exclusiveMaximum?: number - minimum?: number - exclusiveMinimum?: number +export interface NumberSchema extends BaseSchema { + type: 'number'; + minimum?: number; + maximum?: number; } -export type IntegerSchema = Omit & { - type: 'integer' +export interface IntegerSchema extends BaseSchema { + type: 'integer'; + minimum?: number; + maximum?: number; } -export type BooleanSchema = BaseSchema & { - type: 'boolean' +export interface BooleanSchema extends BaseSchema { + type: 'boolean'; } -export type ObjectSchema = BaseSchema> & { - type: 'object' - properties: Record - required: string[] - additionalProperties: boolean - $defs?: Record +export interface ObjectSchema extends BaseSchema { + type: 'object'; + properties: Record; + required?: string[]; + additionalProperties?: boolean; + $defs?: Record; } -export type ArraySchema = BaseSchema & { - type: 'array' - items: Schema - minItems?: number - maxItems?: number +export interface ArraySchema extends BaseSchema { + type: 'array'; + items: Schema; + minItems?: number; + maxItems?: number; } -export type NullSchema = { - type: 'null' +export interface RefSchema { + $ref: string; } -export type RefSchema = { - $ref: string +export interface AnyOfSchema { + anyOf: Schema[]; } -export type AnyOfSchema = { - anyOf: Schema[] -} +export type Schema = + | StringSchema + | NumberSchema + | IntegerSchema + | BooleanSchema + | ObjectSchema + | ArraySchema + | RefSchema + | AnyOfSchema;