Type Alias IJsonSchemaUnit<Version, Type>

IJsonSchemaUnit: Version extends "3.0"
    ? IJsonSchemaUnit.IV3_0<Type>
    : IJsonSchemaUnit.IV3_1<Type>

Single unit of JSON schema representation.

IJsonSchemaUnit represents a self-contained JSON schema unit that encapsulates a single schema definition along with its associated reusable components. This is typically used when generating a JSON schema for a single TypeScript type, as opposed to a collection of multiple types.

Unlike IJsonSchemaCollection which handles multiple schemas, IJsonSchemaUnit focuses on representing a single schema with its dependencies. This makes it ideal for scenarios where you need to work with individual type definitions or when integrating with systems that expect single schema documents.

The unit contains:

  • A single JSON schema definition for the specified TypeScript type
  • All necessary reusable components that the schema may reference
  • Version-specific formatting for either OpenAPI v3.0 or v3.1 compatibility
  • Optional type metadata for compile-time type safety

Key differences from collection:

  • Contains only one schema instead of an array of schemas
  • More lightweight for single-type use cases
  • Simpler structure for direct schema consumption
  • Still maintains full component reference support

Type Parameters

  • Version extends "3.0" | "3.1" = "3.1"

    The OpenAPI specification version to target ("3.0" or "3.1"). Defaults to "3.1" for enhanced JSON Schema Draft 2020-12 compatibility. This determines the schema format, validation capabilities, and available features like tuple support and null type handling.

  • Type = unknown

    The original TypeScript type that was analyzed to generate this JSON schema unit. This provides compile-time type safety and enables IDEs to provide better intellisense and validation.

interface User {
id: string;
name: string;
email?: string;
}

// Generate a single schema unit for OpenAPI v3.1 (default)
const userSchema = typia.json.schema<User>();
// Type: IJsonSchemaUnit<"3.1", User>

// Generate a single schema unit for OpenAPI v3.0 (Swagger compatibility)
const swaggerUserSchema = typia.json.schema<User, "3.0">();
// Type: IJsonSchemaUnit<"3.0", User>

IJsonSchemaCollection For handling multiple schemas at once

Jeongho Nam - https://github.com/samchon