Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ruby SDK

This is the README that tungsten generates for the Ruby target, shown for a small example API (Swagger's Petstore). Names change with your API; the structure does not.

These recorded examples retain their original generator and runtime versions. Their installation snippets name example generated packages; they are not a current registry installation recipe. See runtime distribution for the verified stable 0.1.2 package versions and matching source routes for the unreleased 0.1.3 candidate.

Ruby SDK for openapi, generated by tungsten. It needs Ruby 3.3 or later and the tungsten-runtime gem (~> 0.1.3); the runtime uses Ruby's standard libraries (net/http, json, openssl) and declares its base64 gem dependency for Bundler compatibility.

Usage

require "openapi_sdk"

client = OpenapiSdk::OpenapiClient.new(base_url: "https://api.example.com", auth: { ... })
result = client.pets.list
if result.ok?
  puts result.value
else
  warn result.error.remediation
end

Every method returns Tungsten::Runtime::Ok (value, raw, meta, verification) or Tungsten::Runtime::Err (error: the diagnostic envelope with category, remediation, retryable, next_action, ...; partial: what a failed call already produced). API and transport failures never raise.

Arguments are keywords with the Ruby names (snake_case); call options go in opts::

client.some_resource.create(name: "x", opts: { idempotency_key: SecureRandom.uuid, timeout_ms: 10_000 })
  • idempotency_key: the key of an operation that takes one (generate it once per intent and reuse it on every retry);
  • confirm: true for a destructive operation, or the confirmation_token of the operation's preview_<method> (the only way for an irreversible one);
  • timeout_ms, verify, headers.

Client options (keywords of new): base_url, auth (credentials by scheme name), timeout_ms, retries, idempotency_store, middleware, validate_responses ("warn", "strict", "off"), on_diagnostic, headers, max_event_bytes, max_reconnects, reconnect_max_ms, idle_timeout_ms, token_store, max_oauth_token_response_bytes (positive safe integer, 64 KiB by default for each code/refresh response).

Operations

MethodOperationSafety
client.pets.listopenapi.listPetsread_only
client.pets.createopenapi.createPetsmutating
client.pets.getopenapi.showPetByIdread_only

Custom code

lib/openapi_sdk/custom/extensions.rb is yours: tungsten creates it once and never overwrites it, and the gem requires it last.