Class: Schemacop::V3::ReferenceNode
- Inherits:
-
Node
- Object
- Node
- Schemacop::V3::ReferenceNode
show all
- Defined in:
- lib/schemacop/v3/reference_node.rb
Constant Summary
collapse
- RFC6901_ESCAPE =
{ '~' => '~0', '/' => '~1' }.freeze
Instance Attribute Summary
Attributes inherited from Node
#as, #default, #description, #name, #options, #parent, #require_key, #title
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Node
#allowed_types, #cast_str_wrapper?, #children, #create, dsl_methods, #dsl_node, #dsl_scm, #initialize, #require_key?, #required?, resolve_class, #schemas, supports_children, supports_children_options, #validate
Class Method Details
.allowed_options ⇒ Object
6
7
8
|
# File 'lib/schemacop/v3/reference_node.rb', line 6
def self.allowed_options
super + i[path]
end
|
.create(path, **options, &block) ⇒ Object
10
11
12
13
|
# File 'lib/schemacop/v3/reference_node.rb', line 10
def self.create(path, **options, &block)
options[:path] = path
super(**options, &block)
end
|
Instance Method Details
#_validate(data, result:) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/schemacop/v3/reference_node.rb', line 30
def _validate(data, result:)
super_data = super
return if super_data.nil?
node = target
fail "Schema #{@path.to_s.inspect} not found." unless node
node._validate(super_data, result: result)
end
|
#as_json ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/schemacop/v3/reference_node.rb', line 15
def as_json
if context.swagger_json?
sanitized = @path.to_s.gsub(%r{[~/]}, '.')
process_json([], '$ref': "#/components/schemas/#{sanitized}")
else
escaped = @path.to_s.gsub(%r{[~/]}, RFC6901_ESCAPE)
process_json([], '$ref': "#/definitions/#{escaped}")
end
end
|
#cast(data) ⇒ Object
46
47
48
49
|
# File 'lib/schemacop/v3/reference_node.rb', line 46
def cast(data)
data = default if data.nil?
return target.cast(data)
end
|
#target ⇒ Object
42
43
44
|
# File 'lib/schemacop/v3/reference_node.rb', line 42
def target
schemas[@path] || Schemacop.context.schemas[@path] || GlobalContext.schema_for(@path)
end
|
#used_external_schemas(encountered_nodes = Set.new) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/schemacop/v3/reference_node.rb', line 51
def used_external_schemas(encountered_nodes = Set.new)
if encountered_nodes.include?(self)
return []
end
target_children_schema = target.used_external_schemas(encountered_nodes + [self])
if schemas.include?(@path)
return target_children_schema
else
return [@path] + target_children_schema
end
end
|