Class: RailsApiDocs::Inspectors::BodyInferrer
- Inherits:
-
Object
- Object
- RailsApiDocs::Inspectors::BodyInferrer
- Defined in:
- lib/rails-api-docs/inspectors/body_inferrer.rb
Overview
Composes ControllerInspector + SchemaInspector to produce a typed body field list for write actions (create / update).
Returned shape per call:
[
{ "name" => "email", "type" => "string", "required" => true },
{ "name" => "age", "type" => "integer", "required" => false }
]
Returns ‘nil` (not an empty array) when there’s nothing useful to add —the Builder uses that to decide whether to emit a ‘body:` key at all.
Constant Summary collapse
- WRITE_ACTIONS =
%w[create update].freeze
Instance Method Summary collapse
- #call(controller:, action:) ⇒ Object
-
#initialize(root: nil, controller_inspector: nil, schema_inspector: nil, verbose: false) ⇒ BodyInferrer
constructor
A new instance of BodyInferrer.
Constructor Details
#initialize(root: nil, controller_inspector: nil, schema_inspector: nil, verbose: false) ⇒ BodyInferrer
Returns a new instance of BodyInferrer.
20 21 22 23 24 25 26 |
# File 'lib/rails-api-docs/inspectors/body_inferrer.rb', line 20 def initialize(root: nil, controller_inspector: nil, schema_inspector: nil, verbose: false) @root = root @controller_inspector_class = controller_inspector || ControllerInspector @schema_inspector_class = schema_inspector || SchemaInspector @verbose = verbose @cache = {} end |
Instance Method Details
#call(controller:, action:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rails-api-docs/inspectors/body_inferrer.rb', line 28 def call(controller:, action:) return nil unless WRITE_ACTIONS.include?(action.to_s) permitted = controller_permits(controller) return nil if permitted.empty? types = column_types(controller) permitted.map { |name| build_field(name, types[name]) } end |