Module: JSONSkooma::Formatters::Annotated

Defined in:
lib/json_skooma/formatters.rb

Overview

Re-shapes collected annotations into a hash that mirrors the instance data: every node (except the root) becomes a hash of its annotations plus a “value” key holding the original value (with nested nodes wrapped the same way). Annotations contributed through $ref/allOf land on the same instance location, so they merge naturally; annotations from failed subschemas are dropped, per the JSON Schema spec.

result.output(:annotated)
# => {"user_id" => {"title" => "User Identifier", "value" => 123}, ...}

Options:

keywords: list of annotation keywords to include (default: title, description)
value_key: key under which the original value is placed (default: "value")

Constant Summary collapse

DEFAULT_KEYWORDS =
%w[title description].freeze

Class Method Summary collapse

Class Method Details

.call(result, keywords: DEFAULT_KEYWORDS, value_key: "value", **_options) ⇒ Object



154
155
156
157
158
# File 'lib/json_skooma/formatters.rb', line 154

def call(result, keywords: DEFAULT_KEYWORDS, value_key: "value", **_options)
  annotations = {}
  collect(result, keywords.map(&:to_s), annotations)
  represent(result.instance, annotations, value_key, root: true)
end