yaml_ext 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +71 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/example/components/index.yml +2 -0
- data/example/components/schemas/Error.yml +9 -0
- data/example/components/schemas/User.yml +11 -0
- data/example/components/schemas/Users.yml +3 -0
- data/example/components/schemas/index.yml +6 -0
- data/example/paths/index.yml +8 -0
- data/example/paths/users/create_users.yml +13 -0
- data/example/paths/users/list_users.yml +29 -0
- data/example/paths/users/show_user_by_id.yml +25 -0
- data/example/schema.yml +10 -0
- data/lib/yaml_ext.rb +79 -0
- data/lib/yaml_ext/version.rb +3 -0
- data/yaml_ext.gemspec +29 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5c50a167ebcd2e16535c639ffb075f669e5460f36f1529f115c0ed9da5147b51
|
4
|
+
data.tar.gz: 12bdbf3f9ee69f5dbdd331c013b2708c585a4de4ab692399fad4821fabef1ec0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34340ea31a332e792426961325dc2312dc6c2e643d0aea00f9bed21a0f12fba20823282af5181f205ea92991d407caba692c2dfbc26afaf8921f489e82b4ec7c
|
7
|
+
data.tar.gz: 9f5561dd431c156a93a71326e275f37458d25915c18d448b2611edcad207ab4dab83ed9a67fd1a121b6b9db9e0e90120e239b07c8da79a1019909f291334083c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ken Iiboshi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# YamlExt
|
2
|
+
|
3
|
+
Multiple YAML Loader.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "yaml_ext"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
pry(main)> YamlExt.load("example/schema.yml")
|
23
|
+
=> {"openapi"=>"3.0.0",
|
24
|
+
"info"=>{"version"=>"1.0.0", "title"=>"Example API"},
|
25
|
+
"servers"=>[{"url"=>"http://example.com/v1"}],
|
26
|
+
"paths"=>
|
27
|
+
{"/users"=>
|
28
|
+
{"get"=>
|
29
|
+
{"summary"=>"List all users",
|
30
|
+
"operationId"=>"listUsers",
|
31
|
+
"tags"=>["users"],
|
32
|
+
"parameters"=>[{"name"=>"limit", "in"=>"query", "description"=>"How many items to return at one time (max 100)", "required"=>false, "schema"=>{"type"=>"integer"}}],
|
33
|
+
"responses"=>
|
34
|
+
{"200"=>
|
35
|
+
{"description"=>"A paged array of users",
|
36
|
+
"headers"=>{"x-next"=>{"description"=>"A link to the next page of responses", "schema"=>{"type"=>"string"}}},
|
37
|
+
"content"=>{"application/json"=>{"schema"=>{"type"=>"array", "items"=>{"$ref"=>"#/components/schemas/User"}}}}},
|
38
|
+
"default"=>{"description"=>"unexpected error", "content"=>{"application/json"=>{"schema"=>{"type"=>"object", "required"=>["code", "message"], "properties"=>{"code"=>{"type"=>"integer"}, "message"=>{"type"=>"string"}}}}}}}},
|
39
|
+
"post"=>
|
40
|
+
{"summary"=>"Create a user",
|
41
|
+
"operationId"=>"createUsers",
|
42
|
+
"tags"=>["users"],
|
43
|
+
"responses"=>
|
44
|
+
{"201"=>{"description"=>"Null response"},
|
45
|
+
"default"=>{"description"=>"unexpected error", "content"=>{"application/json"=>{"schema"=>{"type"=>"object", "required"=>["code", "message"], "properties"=>{"code"=>{"type"=>"integer"}, "message"=>{"type"=>"string"}}}}}}}}},
|
46
|
+
"/users/{userId}"=>
|
47
|
+
{"get"=>
|
48
|
+
{"get"=>
|
49
|
+
{"summary"=>"Info for a specific user",
|
50
|
+
"operationId"=>"showUserById",
|
51
|
+
"tags"=>["users"],
|
52
|
+
"parameters"=>[{"name"=>"userId", "in"=>"path", "description"=>"The id of the user", "required"=>true, "schema"=>{"type"=>"integer"}}],
|
53
|
+
"responses"=>
|
54
|
+
{"200"=>{"description"=>"Expected response to a valid request", "content"=>{"application/json"=>{"schema"=>{"type"=>"object", "required"=>["id", "name"], "properties"=>{"id"=>{"type"=>"integer"}, "name"=>{"type"=>"string"}, "tag"=>{"type"=>"string"}}}}}},
|
55
|
+
"default"=>{"description"=>"unexpected error", "content"=>{"application/json"=>{"schema"=>{"type"=>"object", "required"=>["code", "message"], "properties"=>{"code"=>{"type"=>"integer"}, "message"=>{"type"=>"string"}}}}}}}}}}},
|
56
|
+
"components"=>
|
57
|
+
{"schemas"=>
|
58
|
+
{"User"=>{"type"=>"object", "required"=>["id", "name"], "properties"=>{"id"=>{"type"=>"integer"}, "name"=>{"type"=>"string"}, "tag"=>{"type"=>"string"}}},
|
59
|
+
"Users"=>{"type"=>"array", "items"=>{"type"=>"object", "required"=>["id", "name"], "properties"=>{"id"=>{"type"=>"integer"}, "name"=>{"type"=>"string"}, "tag"=>{"type"=>"string"}}}},
|
60
|
+
"Error"=>{"type"=>"object", "required"=>["code", "message"], "properties"=>{"code"=>{"type"=>"integer"}, "message"=>{"type"=>"string"}}}}}}
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/i2bskn/yaml_ext.
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
summary: List all users
|
2
|
+
operationId: listUsers
|
3
|
+
tags:
|
4
|
+
- users
|
5
|
+
parameters:
|
6
|
+
- name: limit
|
7
|
+
in: query
|
8
|
+
description: How many items to return at one time (max 100)
|
9
|
+
required: false
|
10
|
+
schema:
|
11
|
+
type: integer
|
12
|
+
responses:
|
13
|
+
'200':
|
14
|
+
description: A paged array of users
|
15
|
+
headers:
|
16
|
+
x-next:
|
17
|
+
description: A link to the next page of responses
|
18
|
+
schema:
|
19
|
+
type: string
|
20
|
+
content:
|
21
|
+
application/json:
|
22
|
+
schema:
|
23
|
+
$ref: "#/components/schemas/Users"
|
24
|
+
default:
|
25
|
+
description: unexpected error
|
26
|
+
content:
|
27
|
+
application/json:
|
28
|
+
schema:
|
29
|
+
$ref: "#/components/schemas/Error"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
get:
|
2
|
+
summary: Info for a specific user
|
3
|
+
operationId: showUserById
|
4
|
+
tags:
|
5
|
+
- users
|
6
|
+
parameters:
|
7
|
+
- name: userId
|
8
|
+
in: path
|
9
|
+
description: The id of the user
|
10
|
+
required: true
|
11
|
+
schema:
|
12
|
+
type: integer
|
13
|
+
responses:
|
14
|
+
'200':
|
15
|
+
description: Expected response to a valid request
|
16
|
+
content:
|
17
|
+
application/json:
|
18
|
+
schema:
|
19
|
+
$ref: "#/components/schemas/User"
|
20
|
+
default:
|
21
|
+
description: unexpected error
|
22
|
+
content:
|
23
|
+
application/json:
|
24
|
+
schema:
|
25
|
+
$ref: "#/components/schemas/Error"
|
data/example/schema.yml
ADDED
data/lib/yaml_ext.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "yaml"
|
3
|
+
require "yaml_ext/version"
|
4
|
+
|
5
|
+
module YamlExt
|
6
|
+
class << self
|
7
|
+
def load(path)
|
8
|
+
resolve_ref_inner_json(load_file(path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_file(path)
|
12
|
+
parse_extended_node(load_yaml_file(path), path)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def load_yaml_file(path)
|
18
|
+
YAML.load(ERB.new(File.read(path), nil, "-").result)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_extended_node(node, path)
|
22
|
+
case node
|
23
|
+
when Hash
|
24
|
+
node.each_with_object({}) { |(k, v), obj|
|
25
|
+
if k == "$ref" && v.is_a?(String) && !v.start_with?("#/")
|
26
|
+
value = load_file(File.expand_path(v, File.dirname(path)))
|
27
|
+
case value
|
28
|
+
when Hash
|
29
|
+
obj = {} unless obj.is_a?(Hash)
|
30
|
+
obj.merge!(value)
|
31
|
+
when Array
|
32
|
+
obj = [] unless obj.is_a?(Array)
|
33
|
+
obj.concat(value)
|
34
|
+
else
|
35
|
+
obj = value
|
36
|
+
end
|
37
|
+
else
|
38
|
+
obj = {} unless obj.is_a?(Hash)
|
39
|
+
obj[k] = parse_extended_node(v, path)
|
40
|
+
end
|
41
|
+
}
|
42
|
+
when Array
|
43
|
+
node.map { |n| parse_extended_node(n, path) }
|
44
|
+
else
|
45
|
+
node
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def resolve_ref_inner_json(node, node_tree = nil)
|
50
|
+
node_tree ||= node
|
51
|
+
|
52
|
+
case node
|
53
|
+
when Hash
|
54
|
+
node.each_with_object({}) { |(k, v), obj|
|
55
|
+
if k == "$ref" && v.is_a?(String) && v.start_with?("#/")
|
56
|
+
value = v.split("/")[1..-1].inject(node_tree) { |nodes, key| nodes.fetch(key) }
|
57
|
+
case value
|
58
|
+
when Hash
|
59
|
+
obj = {} unless obj.is_a?(Hash)
|
60
|
+
obj.merge!(value)
|
61
|
+
when Array
|
62
|
+
obj = [] unless obj.is_a?(Array)
|
63
|
+
obj.concat(value)
|
64
|
+
else
|
65
|
+
obj = value
|
66
|
+
end
|
67
|
+
else
|
68
|
+
obj = {} unless obj.is_a?(Hash)
|
69
|
+
obj[k] = resolve_ref_inner_json(v, node_tree)
|
70
|
+
end
|
71
|
+
}
|
72
|
+
when Array
|
73
|
+
node.map { |n| resolve_ref_inner_json(n, node_tree) }
|
74
|
+
else
|
75
|
+
node
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/yaml_ext.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "yaml_ext/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yaml_ext"
|
8
|
+
spec.version = YamlExt::VERSION
|
9
|
+
spec.authors = ["i2bskn"]
|
10
|
+
spec.email = ["i2bskn@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Multiple YAML Loader.}
|
13
|
+
spec.description = %q{Multiple YAML Loader.}
|
14
|
+
spec.homepage = "https://github.com/i2bskn/yaml_ext"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "minitest"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaml_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- i2bskn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Multiple YAML Loader.
|
70
|
+
email:
|
71
|
+
- i2bskn@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- example/components/index.yml
|
85
|
+
- example/components/schemas/Error.yml
|
86
|
+
- example/components/schemas/User.yml
|
87
|
+
- example/components/schemas/Users.yml
|
88
|
+
- example/components/schemas/index.yml
|
89
|
+
- example/paths/index.yml
|
90
|
+
- example/paths/users/create_users.yml
|
91
|
+
- example/paths/users/list_users.yml
|
92
|
+
- example/paths/users/show_user_by_id.yml
|
93
|
+
- example/schema.yml
|
94
|
+
- lib/yaml_ext.rb
|
95
|
+
- lib/yaml_ext/version.rb
|
96
|
+
- yaml_ext.gemspec
|
97
|
+
homepage: https://github.com/i2bskn/yaml_ext
|
98
|
+
licenses: []
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.0.3
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Multiple YAML Loader.
|
119
|
+
test_files: []
|