yaml_ext 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff4954b8a7a31968db3c31d7d8008ec5b6943f53b58a441b53e296f222466116
4
- data.tar.gz: 7570ae907e8ee2d47271bd568954cc8262e633e465ded6e6f737744b0f744bde
3
+ metadata.gz: 478646f3feb20620a8f50d838c74f8a3a55824df7f1e7bb71ee80aec8d99473e
4
+ data.tar.gz: 2c8f3b4ed24f53cd3669f0b357c7925d5b0ba0edd0774fa6627dd59b0a9f6ccb
5
5
  SHA512:
6
- metadata.gz: b7de6ed33f4fde2a27ef502c84cedb388ce3bb8bfd5936a329be0ab567f39280bd7dba1f21b995035fb9c462e43ed93d2995b537fe90810f34664fc6ef6e0ac9
7
- data.tar.gz: 4498e81d9ce2a95a46a8e9ce885c00bf5819699f5d54442fdf203bb8192e96c0d0c2d6cd87cdb8fa1ba6c343b7cb6ec94f20c01a325fe566c4666f69dd66b746
6
+ metadata.gz: 2d5707fa1ad22b1fce23658916adb5a01f6bb2e0217e43c7ae55c5586f75c16380ad22772c96d9d219132e618b6e47ab1fafa8292dca4e54590b32c2ee016f7d
7
+ data.tar.gz: 44bc256bdb5e797c9f4be1bfdab3d4ef01a9c23382b61289535b4fd3e16e1b79db66c7f5a14d64e431790b4a4b1f413531b5f01d8243f3a2df40cfc4d7339e07
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # YamlExt
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/yaml_ext.svg)](https://badge.fury.io/rb/yaml_ext)
3
4
  [![Build Status](https://travis-ci.org/i2bskn/yaml_ext.svg?branch=master)](https://travis-ci.org/i2bskn/yaml_ext)
4
5
 
5
- Multiple YAML Loader.
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"=>{"$ref"=>"#/components/schemas/User"}}}}},
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
@@ -2,6 +2,7 @@ openapi: "3.0.0"
2
2
  info:
3
3
  version: 1.0.0
4
4
  title: Example API
5
+ description: <%= 1 + 1 %>
5
6
  servers:
6
7
  - url: http://example.com/v1
7
8
  paths:
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
- ref_path = v.split("/")[1..-1]
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 update_node_tree(node_tree, node_path, value)
83
- content = node_tree
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
- content = content[k]
86
+ node_tree = node_tree[k]
87
87
  else
88
- content[k] = value
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
@@ -1,3 +1,3 @@
1
1
  module YamlExt
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
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 = "Multiple YAML Loader."
12
- spec.description = "Multiple YAML Loader."
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.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-08-28 00:00:00.000000000 Z
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: Multiple YAML Loader.
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: Multiple YAML Loader.
134
+ summary: yaml_ext provide references in YAML.
135
135
  test_files: []