Schema Guide

Custom Types Schema - Comprehensive Guide

Core Concepts

The custom types system allows you to define complex data structures with validation, type safety, and nested relationships. Each custom type serves as a template for data that follows a specific structure.

Detailed Schema Structure

Base Schema

interface CustomTypeSchema {
  name: string;        // Name of the custom type
  description: string; // Description of what this type represents
  properties: Record<string, CustomJsonPropertyType>; // Field definitions
}

Field Types In-Depth

1. String Fields

Used for text-based data.

{
  "userName": {
    "type": "string",
    "description": "The user's display name in the system",
    "required": true,
    "title": "Username",  // Optional display name
    "default": ""        // Optional default value
  }
}

Use Cases:

  • User names

  • Descriptions

  • Email addresses

  • Any text-based input

  • IDs or reference numbers

2. Number Fields

Used for numeric values, including both integers and decimals.

Use Cases:

  • Measurements

  • Quantities

  • Scores or ratings

  • Financial values

  • Calculations

3. Object Fields

Used for grouping related fields together in a nested structure.

Use Cases:

  • Complex data structures

  • Grouped information

  • Nested data

  • Form sections

  • Related data points

4. Array Fields

Used for lists or collections of items.

Use Cases:

  • Multiple entries of the same type

  • Lists of items

  • Collections of documents

  • Multiple contact methods

  • Repeated data structures

5. Enum Fields

Used for fields with a fixed set of possible values.

Use Cases:

  • Status indicators

  • Categories

  • Priority levels

  • Predefined options

  • State management

6. OneOf Fields

Used for fields that can have multiple different structures.

Use Cases:

  • Multiple possible configurations

  • Different types of the same concept

  • Conditional data structures

  • Variant handling

  • Flexible data models

7. File Fields

Used for file attachments and uploads.

Use Cases:

  • Document uploads

  • Image attachments

  • File references

  • Media content

  • Data uploads

8. Location Fields

Used for geographic location data.

Use Cases:

  • Geographic coordinates

  • Site locations

  • Address verification

  • Map integration

  • Location tracking

Validation and Requirements

Required Fields

Fields can be marked as required to ensure data completeness:

Description Requirements

Every field must have a description that explains:

  • Purpose of the field

  • Expected data

  • Any constraints or requirements

  • Usage context

Best Practices

  1. Field Naming:

    • Use clear, descriptive names

    • Follow camelCase convention

    • Avoid special characters

    • Be consistent across similar fields

  2. Descriptions:

    • Write clear, concise descriptions

    • Include any relevant constraints

    • Mention expected formats

    • Document any dependencies

  3. Structure:

    • Group related fields in objects

    • Use arrays for collections

    • Keep nesting reasonable

    • Consider data access patterns

  4. Validation:

    • Mark essential fields as required

    • Use enums for fixed options

    • Provide sensible defaults

    • Consider data integrity

  5. Maintainability:

    • Document complex structures

    • Use consistent patterns

    • Consider future extensions

    • Keep it as simple as possible

This comprehensive guide should help in understanding and implementing custom types effectively in your system.

Last updated