Module: Meta::JsonSchema::SchemaOptions

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

Class Method Summary collapse

Class Method Details

.divide_to_param_and_render(options) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/meta/json_schema/support/schema_options.rb', line 14

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

.normalize(options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/meta/json_schema/support/schema_options.rb', line 24

def normalize(options)
  # 只要 options 中设置为 nil 的选项没有明确的意义,则下行代码是永远有效的
  options = (@default_options.compact).merge(options.compact)
  if options[:using]
    if options[:type].nil?
      options[:type] = 'object'
    elsif options[:type] != 'object' && options[:type] != 'array'
      raise "当使用 using 时,type 必须声明为 object 或 array"
    end
  end

  options
end