Generable

Derive Macro Generable 

Source
#[derive(Generable)]
{
    // Attributes available to this derive:
    #[generable]
    #[serde]
}
Expand description

Re-export the derive macro when the derive feature is enabled. Derives the Generable trait for a struct or enum.

This generates a JSON Schema that describes the type’s structure, which can be used for structured generation with FoundationModels.

§Attributes

§Container attributes (#[generable(...)] or #[serde(...)])

  • rename_all = "..." - Rename all fields/variants (camelCase, snake_case, etc.)
  • description = "..." - Add a description to the schema

§Field/variant attributes (#[generable(...)] or #[serde(...)])

  • rename = "..." - Rename this field/variant
  • skip - Skip this field/variant in the schema
  • description = "..." - Add a description
  • minimum = N / maximum = N - Numeric bounds
  • min_length = N / max_length = N - String length bounds
  • pattern = "..." - Regex pattern for strings
  • min_items = N / max_items = N - Array length bounds

§Example

use fm_rs::Generable;

#[derive(Generable)]
#[generable(rename_all = "camelCase")]
struct Person {
    #[generable(description = "The person's full name")]
    full_name: String,
    #[generable(minimum = 0, maximum = 150)]
    age: u32,
}

Derives Generable for structs and unit enums.