Rust SDK
Data Models
Data Models are schemas that define the structure and validation rules for structured data assets in the Gateway Protocol. They ensure data consistency and provide a standardized way to validate and organize information. This guide covers working with Data Models using the Rust SDK.
Understanding Data Models
Before working with structured data assets, it’s important to understand:
- Data Models define the expected structure of your data using JSON Schema
- Every structured data asset must conform to a Data Model
- Data Models help maintain data quality and consistency
Creating Data Models
Use the SDK to create Data Models that define the structure of your data:
Data Model Structure
A Data Model consists of several key components:
-
Metadata
title
: Name of the Data Modeldescription
: Detailed description of the Data Model’s purposetags
: Array of keywords for categorization
-
Schema
- Follows JSON Schema specification
- Defines the structure and validation rules
- Supports various data types and validations
Supported Data Types
Data Models support all standard JSON Schema data types:
string
: Text datanumber
: Numeric valuesboolean
: True/false valuesarray
: Lists of itemsobject
: Nested structuresnull
: Null values
Validation Rules
You can specify various validation rules:
Retrieving Data Models
You can retrieve Data Models using various methods.
Pagination Examples
Batch Operations
Best Practices
-
Plan Your Schema
- Design your Data Model schema carefully before creation
- Consider future needs as schemas cannot be modified after creation
- Include all necessary validation rules
-
Use Required Fields
- Specify required fields to ensure data completeness
- Be conservative with required fields to maintain flexibility
-
Validation Rules
- Use appropriate validation rules to maintain data quality
- Consider adding min/max lengths for strings
- Add reasonable bounds for numeric values
-
Documentation
- Provide clear descriptions for fields
- Use meaningful titles for properties
- Add relevant tags for better discoverability
-
Property Constraints
- Consider setting
additionalProperties: false
to prevent extra fields - Use appropriate formats for specialized strings (email, URI, etc.)
- Consider setting