Module: Meta::JsonSchema::SchemaOptions

Defined in:
lib/meta/json_schema/support/schema_options.rb

Defined Under Namespace

Modules: UserOptions

Constant Summary collapse

BaseBuildOptions =
Utils::Kwargs::Builder.build do
  key :type, :items, :description, :presenter, :value, :default, :properties, :convert
  key :validate, :required, :format
  key :enum, alias_names: [:allowable]
  key :ref, alias_names: [:using], normalizer: ->(entity) { entity }
  key :dynamic_ref, alias_names: [:dynamic_using], normalizer: ->(value) { value.is_a?(Proc) ? { resolve: value } : value }
  key :before, :after
  key :if
end

Class Method Summary collapse

Class Method Details

.divide_to_param_and_render(options) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/meta/json_schema/support/schema_options.rb', line 66

def divide_to_param_and_render(options)
  common_opts = (options || {}).dup
  param_opts = common_opts.delete(:param)
  render_opts = common_opts.delete(:render)

  param_opts = merge_common_to_stage(common_opts, param_opts)
  render_opts = merge_common_to_stage(common_opts, render_opts)
  [param_opts, render_opts, common_opts]
end

.fix_type_option!(options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/meta/json_schema/support/schema_options.rb', line 51

def fix_type_option!(options)
  if options[:type].is_a?(Class)
    # 修复 type 为自定义类的情形
    the_class = options[:type]
    # 修复 param 选项
    options[:param] = {} if options[:param].nil?
    make_after_cast_to_class(options[:param], the_class) if options[:param]
    # 修复 render 选项
    options[:render] = {} if options[:render].nil?
    make_before_match_to_class(options[:render], the_class) if options[:render]
    # 最终确保 type 为 object
    options.merge!(type: 'object')
  end
end