Custom Type Variants Alpha

Define reusable object types with context-specific property requirements using custom type variants.
Available Plans
  • free
  • starter
  • growth
  • enterprise

This guide shows you how to define and use custom type variants in your Data Catalog.

Overview

Custom type variants let you define different property requirements for reusable object types based on a discriminating property value. This feature is particularly useful when an object type needs different validation rules depending on the context in which it is used.

success
Custom type variants work similarly to Event Rule Variants but are defined at the custom type level rather than the event level. This makes them reusable across multiple events and Tracking Plans.

Define custom type variants

Using your preferred text editor, add variants to your custom types in the Custom Types YAML file:

Basic structure

Custom type variants are defined within custom type definitions. See Variants YAML Reference for the detailed variant specification.

The following snippet is a simplified example to demonstrate the structure. See the Examples section below for real-world use cases with complete implementations.

version: rudder/v0.1
kind: custom-types
metadata:
  name: mycustomtypes
spec:
  types:
    - id: custom_object
      name: "Custom Object"
      type: object
      description: "Object with context-specific requirements"
      
      # Common properties for all variants
      properties:
        - $ref: "#/properties/common_props/property_1"
          required: true    # Discriminator property must be required
        - $ref: "#/properties/common_props/property_2"
          required: false   # Common property that may be required by variants
        - $ref: "#/properties/common_props/property_3"
          required: false   # Property used in default case
      
      variants:
        - type: discriminator
          discriminator: "#/properties/common_props/property_1"    # Must match the property defined above
          cases:
            - id: case_a
              display_name: "Case A"
              match: 
                - "value1"
                - "value2"
              description: "Description of Case A"
              properties:
                - $ref: "#/properties/common_props/property_2"
                  required: true
            
            - id: case_b
              display_name: "Case B"
              match:
                - "value3"
              description: "Description of Case B"
              properties:
                - $ref: "#/properties/common_props/property_2"
                  required: true
          
          # Default case for unmatched values
          default:
            - $ref: "#/properties/common_props/property_3"
              required: true

Each variant definition requires:

  • The discriminator type (type: discriminator)
  • The discriminating property name (discriminator)
  • One or more cases with:
    • A unique identifier (id)
    • A display name (display_name)
    • Match values (match)
    • Description (description) explaining when this case applies
    • Property requirements (properties) specific to this case
  • Optional default case (default) for when no cases match
warning

The discriminator property must be:

  • Defined in the custom type’s properties section
  • Marked as required
  • Have a type matching your match values (string, boolean, or number)

Supported discriminator types

You can use the following discriminator types in your custom type variants:

TypeDescriptionExample values
StringMatch against text values"US", "UK", "Japan"
BooleanMatch true/false conditionstrue, false
NumberMatch against numeric thresholds500, 1000, 2000
info

Note that for each type:

  • You can specify multiple match values in an array
  • Values are matched exactly (no range or pattern matching)
  • String matches are case-sensitive

Examples

The following examples show variant definitions for different use cases:

Best practices

Follow these best practices when defining custom type variants:

  • Discriminator selection

    • Choose properties that clearly indicate different contexts
    • Ensure the discriminator property is always available
    • Use simple, predictable property values
  • Case definition

    • Use clear, descriptive IDs and display names
    • Group related match values in the same case
    • Include helpful descriptions
  • Property requirements

    • Include only relevant properties for each case
    • Consider required vs. optional carefully
    • Use default case for common requirements
  • Validation

    • Test all variant cases
    • Verify property references
    • Check for edge cases

Validate and deploy variants

To update your custom types with the newly-added variants, make sure to validate and deploy the changes using Rudder CLI.

Reference custom types in properties

Once defined, you can use custom types with variants in your properties:

version: rudder/v0.1
kind: properties
metadata:
  name: integration_properties
spec:
  properties:
    - id: customer_profile
      name: "customer_profile"
      type: "#/custom-types/user_profile_types/user_profile_object"
      description: "Customer profile information"
    - id: purchased_product
      name: "purchased_product" 
      type: "#/custom-types/product_types/product_object"
      description: "Product that was purchased"
    - id: shipping_address
      name: "shipping_address"
      type: "#/custom-types/address_types/address_object"
      description: "Where to ship the order"

You can then reference these properties in your Tracking Plan:

version: rudder/0.1
kind: tp
metadata:
  name: integrated_tracking_plan
spec:
  id: integrated_plan
  display_name: "Integrated Plan with Custom Types"
  description: "Tracking plan demonstrating custom type usage"
  rules:
    - type: event_rule
      id: purchase_completed_rule
      event:
        $ref: "#/events/ecommerce_events/purchase_completed"
        allow_unplanned: false
      
      properties:
        - $ref: "#/properties/integration_properties/customer_profile"
          required: true
        - $ref: "#/properties/integration_properties/purchased_product"
          required: true
        - $ref: "#/properties/integration_properties/shipping_address"
          required: true

See also



Questions? Contact us by email or on Slack