Added recipe contract

Necessary to validate the API response and ensure it's of the right format and type. Leverages the recently added `Recipes::Author` contract.

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-01-15 09:16:14 -07:00
parent a9cd032ee1
commit 35352a579c
2 changed files with 37 additions and 0 deletions
+1
View File
@@ -27,6 +27,7 @@ module TRMNL
register :ip_address, Contracts::IPAddress
register :model, Contracts::Model
register :palette, Contracts::Palette
register :recipe, Contracts::Recipe
register :setup, Contracts::Setup
end
+36
View File
@@ -0,0 +1,36 @@
# frozen_string_literal: true
require "dry/schema"
module TRMNL
module API
module Contracts
# Validates API response.
Recipe = Dry::Schema.JSON do
required(:data).array(:hash) do
required(:id).filled :integer
required(:name).filled :string
required(:screenshot_url).filled :string
required(:published_at).filled :time
optional(:icon_url).maybe :string
optional(:icon_content_type).maybe :string
required(:author_bio).maybe Recipes::Author
required(:custom_fields).array(:hash)
required(:stats).filled :hash do
required(:installs).filled :integer
required(:forks).filled :integer
end
end
required(:total).filled :integer
required(:from).filled :integer
required(:to).filled :integer
required(:per_page).filled :integer
required(:current_page).filled :integer
required(:prev_page_url).maybe :string
required(:next_page_url).maybe :string
end
end
end
end