ImageBriefValidator (image_brief_validator v0.1.0)

Copy Markdown View Source

Validates the structure of an image-generation brief before it is passed to a rendering workflow.

The validator is provider-independent and performs no network requests.

Summary

Functions

Returns the reduced aspect ratio for valid positive integer dimensions.

Validates a brief and returns either the original brief or all detected errors.

Returns all structural errors as a keyword list.

Functions

aspect_ratio(width, height)

@spec aspect_ratio(integer(), integer()) :: {:ok, String.t()} | {:error, atom()}

Returns the reduced aspect ratio for valid positive integer dimensions.

iex> ImageBriefValidator.aspect_ratio(1920, 1080)
{:ok, "16:9"}

validate(brief)

@spec validate(map()) :: {:ok, map()} | {:error, keyword()}

Validates a brief and returns either the original brief or all detected errors.

Examples

iex> ImageBriefValidator.validate(%{prompt: "A studio product photo", width: 1200, height: 800})
{:ok, %{prompt: "A studio product photo", width: 1200, height: 800}}

iex> ImageBriefValidator.validate(%{prompt: "", width: 0, height: 800})
{:error, [prompt: :must_be_present, width: :must_be_a_positive_integer]}

validate_all(brief)

@spec validate_all(map()) :: keyword()

Returns all structural errors as a keyword list.

String and atom keys are both accepted. Optional style values are limited to the documented presets, and references must be a list of non-empty strings.