Contract Introspection
Contract introspection returns a single contract's structure as an Introspection::Contract object.
ruby
contract = InvoiceContract.introspectAccessors
| Method | Returns |
|---|---|
actions | Hash of Action objects |
types | Hash of Type objects |
enums | Hash of Enum objects |
Actions
ruby
action = contract.actions[:create]
action.method # => :post
action.path # => "/invoices"
action.raises # => [:bad_request, :not_found, :unprocessable_entity]
action.deprecated? # => falseRequest and Response
ruby
request = action.request
request.query? # => false
request.body? # => true
request.body.each do |name, param|
puts "#{name}: #{param.type}"
endruby
response = action.response
response.no_content? # => false
body = response.body
body.object? # => true
body.shape[:invoice] # => Param for the invoiceExpand Mode
By default, only types defined in the contract are included. The expand: true option includes referenced types (useful for debugging or export generation):
ruby
InvoiceContract.introspect
# types: { invoice_filter: {...} }ruby
InvoiceContract.introspect(expand: true)
# types: { invoice_filter: {...}, datetime_filter: {...}, ... }Locale
The locale: option produces translated descriptions:
ruby
InvoiceContract.introspect(locale: :sv)Translations come from I18n files.
Caching
Results are cached per contract, locale, and expand. In development, Rails reloading clears caches automatically.
See also
- Introspection::Contract reference — all introspection methods