Skip to content

Nested operation Inclusion

Vladislav Trotsenko edited this page Sep 30, 2019 · 1 revision

Synopsis

Provides JSON API inclusion of related resources. Dot-separated relationship path supporting not implemented at this time.

HTTP request example: GET /users?include=team,organization

Code

Before using this nested operation you should set ctx[:available_inclusion_options] with an array as available options.

module Api::V1::Lib::Operation
  class Inclusion < ApplicationOperation
    step :inclusion_query_param_passed?, Output(:failure) => End(:success)
    step Macro::Contract::Schema(
      Api::V1::Lib::Contract::InclusionValidation,
      name: :uri_query,
      inject: %i[available_inclusion_options]
    )
    step Contract::Validate(name: :uri_query)
    step Macro::Assign(to: :inclusion_options, path: %w[contract.uri_query include])
  end
end

Used nested & macroses

Clone this wiki locally