yaml_ext 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/example/schema.yml +1 -0
- data/lib/yaml_ext.rb +10 -8
- data/lib/yaml_ext/version.rb +1 -1
- data/yaml_ext.gemspec +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 478646f3feb20620a8f50d838c74f8a3a55824df7f1e7bb71ee80aec8d99473e
|
4
|
+
data.tar.gz: 2c8f3b4ed24f53cd3669f0b357c7925d5b0ba0edd0774fa6627dd59b0a9f6ccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5707fa1ad22b1fce23658916adb5a01f6bb2e0217e43c7ae55c5586f75c16380ad22772c96d9d219132e618b6e47ab1fafa8292dca4e54590b32c2ee016f7d
|
7
|
+
data.tar.gz: 44bc256bdb5e797c9f4be1bfdab3d4ef01a9c23382b61289535b4fd3e16e1b79db66c7f5a14d64e431790b4a4b1f413531b5f01d8243f3a2df40cfc4d7339e07
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# YamlExt
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/yaml_ext)
|
3
4
|
[](https://travis-ci.org/i2bskn/yaml_ext)
|
4
5
|
|
5
|
-
|
6
|
+
`yaml_ext` provide references in YAML.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -23,7 +24,7 @@ $ bundle install
|
|
23
24
|
```ruby
|
24
25
|
pry(main)> YamlExt.load("example/schema.yml")
|
25
26
|
=> {"openapi"=>"3.0.0",
|
26
|
-
"info"=>{"version"=>"1.0.0", "title"=>"Example API"},
|
27
|
+
"info"=>{"version"=>"1.0.0", "title"=>"Example API", "description"=>2},
|
27
28
|
"servers"=>[{"url"=>"http://example.com/v1"}],
|
28
29
|
"paths"=>
|
29
30
|
{"/users"=>
|
@@ -36,7 +37,7 @@ pry(main)> YamlExt.load("example/schema.yml")
|
|
36
37
|
{"200"=>
|
37
38
|
{"description"=>"A paged array of users",
|
38
39
|
"headers"=>{"x-next"=>{"description"=>"A link to the next page of responses", "schema"=>{"type"=>"string"}}},
|
39
|
-
"content"=>{"application/json"=>{"schema"=>{"type"=>"array", "items"=>{"
|
40
|
+
"content"=>{"application/json"=>{"schema"=>{"type"=>"array", "items"=>{"type"=>"object", "required"=>["id", "name"], "properties"=>{"id"=>{"type"=>"integer"}, "name"=>{"type"=>"string"}, "tag"=>{"type"=>"string"}}}}}}},
|
40
41
|
"default"=>{"description"=>"unexpected error", "content"=>{"application/json"=>{"schema"=>{"type"=>"object", "required"=>["code", "message"], "properties"=>{"code"=>{"type"=>"integer"}, "message"=>{"type"=>"string"}}}}}}}},
|
41
42
|
"post"=>
|
42
43
|
{"summary"=>"Create a user",
|
data/example/schema.yml
CHANGED
data/lib/yaml_ext.rb
CHANGED
@@ -36,10 +36,7 @@ module YamlExt
|
|
36
36
|
def ref_inner_node(node, path, node_tree = nil, node_path = [])
|
37
37
|
node.each_with_object({}) do |(k, v), obj|
|
38
38
|
if k == "$ref" && v.is_a?(String) && v.start_with?("#/")
|
39
|
-
|
40
|
-
value = ref_path.inject(node_tree) { |nodes, key| nodes[key] }
|
41
|
-
value = parse_nodes(:ref_inner_node, value, path, node_tree, ref_path)
|
42
|
-
update_node_tree(node_tree, node_path, value)
|
39
|
+
value = resolve_inner_ref(v, path, node_tree, node_path)
|
43
40
|
|
44
41
|
case value
|
45
42
|
when Hash
|
@@ -79,15 +76,20 @@ module YamlExt
|
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
82
|
-
def
|
83
|
-
|
79
|
+
def resolve_inner_ref(value, path, node_tree, node_path)
|
80
|
+
ref_path = value.split("/")[1..-1]
|
81
|
+
ref_value = ref_path.inject(node_tree) { |nodes, idx| nodes.fetch(idx) }
|
82
|
+
resolved_value = parse_nodes(:ref_inner_node, ref_value, path, node_tree, ref_path)
|
83
|
+
|
84
84
|
node_path.each.with_index(1) do |k, i|
|
85
85
|
if node_path.size > i
|
86
|
-
|
86
|
+
node_tree = node_tree[k]
|
87
87
|
else
|
88
|
-
|
88
|
+
node_tree[k] = resolved_value
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
resolved_value
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
data/lib/yaml_ext/version.rb
CHANGED
data/yaml_ext.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["i2bskn"]
|
9
9
|
spec.email = ["i2bskn@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
12
|
-
spec.description = "
|
11
|
+
spec.summary = "yaml_ext provide references in YAML."
|
12
|
+
spec.description = "yaml_ext provide references in YAML."
|
13
13
|
spec.homepage = "https://github.com/i2bskn/yaml_ext"
|
14
14
|
|
15
15
|
# Specify which files should be added to the gem when it is released.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.74.0
|
83
|
-
description:
|
83
|
+
description: yaml_ext provide references in YAML.
|
84
84
|
email:
|
85
85
|
- i2bskn@gmail.com
|
86
86
|
executables: []
|
@@ -131,5 +131,5 @@ requirements: []
|
|
131
131
|
rubygems_version: 3.0.3
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
|
-
summary:
|
134
|
+
summary: yaml_ext provide references in YAML.
|
135
135
|
test_files: []
|