Class: Meta::JsonSchema::RefSchema

Inherits:
BaseSchema show all
Defined in:
lib/meta/json_schema/schemas/ref_schema.rb

Constant Summary

Constants inherited from BaseSchema

BaseSchema::OPTIONS_CHECKER, BaseSchema::USER_OPTIONS_CHECKER

Instance Attribute Summary collapse

Attributes inherited from BaseSchema

#options

Instance Method Summary collapse

Methods inherited from BaseSchema

#filter?, #find_schema, #if?, #scoped, #staged, #to_schema, #value?

Constructor Details

#initialize(schema, options = {}) ⇒ RefSchema

Returns a new instance of RefSchema.



10
11
12
13
# File 'lib/meta/json_schema/schemas/ref_schema.rb', line 10

def initialize(schema, options = {})
  super(options)
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



8
9
10
# File 'lib/meta/json_schema/schemas/ref_schema.rb', line 8

def schema
  @schema
end

Instance Method Details

#filter(value, user_options = {}) ⇒ Object



15
16
17
18
# File 'lib/meta/json_schema/schemas/ref_schema.rb', line 15

def filter(value, user_options = {})
  value = super
  schema.filter(value, user_options)
end

#to_schema_doc(user_options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/meta/json_schema/schemas/ref_schema.rb', line 20

def to_schema_doc(user_options)
  schema_name = schema.resolve_name(user_options[:stage])

  # 首先将 Schema 写进 schemas 选项中去
  schema_components = user_options[:schemas]
  unless schema_components.key?(schema_name)
    schema_components[schema_name] = nil # 首先设置 schemas 防止出现无限循环
    schema_components[schema_name] = schema.to_schema_doc(**user_options) # 原地修改 schemas,无妨
  end

  # 返回的是 $ref 结构
  { '$ref': "#/components/schemas/#{schema_name}" }
end