UNPKG

bookish-potato-dto

Version:

A TypeScript DTO (Data Transfer Object) parsing and validation library. Define a schema once — get runtime validation and a fully inferred TypeScript type for free.

83 lines (82 loc) 2.16 kB
/** * A subset of the OpenAPI 3.0/3.1 Schema Object relevant for DTOs. * Following the OpenAPI Specification: https://swagger.io/specification/#schema-object */ export interface OpenApiSchema { /** * The type of the value. */ readonly type?: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; /** * The format of the value (e.g., date-time, uuid, etc.). */ readonly format?: 'date' | 'date-time' | 'password' | 'byte' | 'binary' | 'email' | 'uuid' | 'int32' | 'int64' | 'float' | 'double'; /** * Possible values for the property. */ readonly enum?: readonly (string | number)[]; /** * Property definitions for object types. */ readonly properties?: Record<string, OpenApiSchema>; /** * Schema for items in an array. */ readonly items?: OpenApiSchema; /** * List of required property names. */ readonly required?: readonly string[]; /** * Whether the property can be null. */ readonly nullable?: boolean; /** * Default value for the property. */ readonly default?: unknown; /** * Brief description of the property. */ readonly description?: string; /** * Example value for the property. */ readonly example?: unknown; /** * Regular expression pattern the value must match. */ readonly pattern?: string; /** * Minimum length for a string. */ readonly minLength?: number; /** * Maximum length for a string. */ readonly maxLength?: number; /** * Minimum value for a number. */ readonly minimum?: number; /** * Maximum value for a number. */ readonly maximum?: number; /** * Minimum number of items in an array. */ readonly minItems?: number; /** * Maximum number of items in an array. */ readonly maxItems?: number; /** * Reference to another schema definition. */ readonly $ref?: string; /** * Additional properties allowed (OpenAPI 3.1). */ readonly additionalProperties?: boolean | OpenApiSchema; }