json_schema-faker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/json_schema-faker.gemspec +30 -0
- data/lib/json_schema/faker.rb +302 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7137b715285867fea6d5ecc696dfe0aac42a38f1
|
4
|
+
data.tar.gz: 220a678a7049bf935b3d7b71aecb2a69045fac37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29ca21c97466107c9a71bd8253ba919350a0a005e534a784f9c62b75fcff3a64e9cc54364019fe575b2baad59b9b9248c54fb1d68ab1d6ee8a8d774dd0fedb67
|
7
|
+
data.tar.gz: 3f9c593277208bc7ca82d8ccb07254680c81d45f7bce4ad9176959c6bd64d641eb3a1c16e8437cd823d536d9d8ef889bb28d3ba988089734b519dab438d9008d
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at okitakunio@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# Feel free to open issues for suggestions and improvements
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 okitan
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# JsonSchema::Faker [![Build Status](https://travis-ci.org/okitan/json_schema-faker.svg?branch=master)](https://travis-ci.org/okitan/json_schema-faker)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'json_schema-faker'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install json_schema-faker
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "json_schema/faker"
|
23
|
+
|
24
|
+
raw_schema = {
|
25
|
+
"id" => "https://example.com/schema.json",
|
26
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
27
|
+
"properties" => { "a" => { "enum" => [ "e", "n", "u", "m" ] } },
|
28
|
+
"required" => [ "a" ],
|
29
|
+
}
|
30
|
+
|
31
|
+
schema = JsonSchema::Schema.parse(raw_schema)
|
32
|
+
|
33
|
+
JsonSchema::Faker.new(schema).generate #=> { "a" => "e" }
|
34
|
+
```
|
35
|
+
|
36
|
+
Note: It is too difficult to correspond to complex schema.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/json_schema-faker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
41
|
+
|
42
|
+
### Run tests
|
43
|
+
|
44
|
+
before running `rake spec`, run `git submodule init && git submodule update`
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json_schema/faker"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "json_schema-faker"
|
4
|
+
spec.version = File.read(File.expand_path("VERSION", File.dirname(__FILE__))).chomp
|
5
|
+
spec.authors = ["okitan"]
|
6
|
+
spec.email = ["okitakunio@gmail.com"]
|
7
|
+
|
8
|
+
spec.summary = "generate fake data from json schema"
|
9
|
+
spec.description = "generate fake data from json schema"
|
10
|
+
spec.homepage = "https://github.com/okitan/json_schema-faker"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
14
|
+
spec.bindir = "exe"
|
15
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "json_schema", ">= 0.12.4"
|
19
|
+
spec.add_dependency "pxeger"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
# test
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
|
28
|
+
# debug
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
require "json_schema"
|
2
|
+
|
3
|
+
require "pxeger"
|
4
|
+
|
5
|
+
module JsonSchema
|
6
|
+
class Faker
|
7
|
+
module Configuration
|
8
|
+
attr_accessor :logger
|
9
|
+
|
10
|
+
module_function :logger, :logger=
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO:
|
14
|
+
# strategy to use for faker
|
15
|
+
def initialize(schema, options = {})
|
16
|
+
@schema = schema
|
17
|
+
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate(hint: nil)
|
22
|
+
generated = _generate(@schema, hint: nil, position: "")
|
23
|
+
|
24
|
+
Configuration.logger.debug "to generate against #{@schema.inspect_schema}" if Configuration.logger
|
25
|
+
Configuration.logger.debug "generated: #{generated.inspect}" if Configuration.logger
|
26
|
+
|
27
|
+
generated
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def _generate(schema, hint: nil, position:)
|
32
|
+
Configuration.logger.debug "current position: #{position}" if Configuration.logger
|
33
|
+
|
34
|
+
raise "here comes nil for schema at #{position}" unless schema
|
35
|
+
|
36
|
+
return schema.default if schema.default
|
37
|
+
|
38
|
+
if schema.not
|
39
|
+
hint ||= {}
|
40
|
+
# too difficult
|
41
|
+
# TODO: support one_of/any_of/all_of
|
42
|
+
hint[:not_have_keys] = schema.not.required if schema.not.required
|
43
|
+
hint[:not_be_values] = schema.not.enum if schema.not.enum
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: should support the combinations of them
|
47
|
+
# http://json-schema.org/latest/json-schema-validation.html#anchor75
|
48
|
+
# Notes:
|
49
|
+
# one_of, any_of, all_of, properties and type is given default and never be nil
|
50
|
+
if !schema.one_of.empty?
|
51
|
+
generate_for_one_of(schema, hint: hint, position: position)
|
52
|
+
elsif !schema.any_of.empty?
|
53
|
+
generate_for_any_of(schema, hint: hint, position: position)
|
54
|
+
elsif !schema.all_of.empty?
|
55
|
+
generate_for_all_of(schema, hint: hint, position: position)
|
56
|
+
elsif schema.enum
|
57
|
+
generate_by_enum(schema, hint: hint, position: position)
|
58
|
+
elsif !schema.type.empty?
|
59
|
+
generate_by_type(schema, position: position)
|
60
|
+
else # consider as object
|
61
|
+
generate_for_object(schema, hint: hint, position: position)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def generate_for_one_of(schema, hint: nil, position:)
|
66
|
+
merged_schema = JsonSchema::Schema.new
|
67
|
+
merged_schema.copy_from(schema)
|
68
|
+
|
69
|
+
merged_schema.one_of = []
|
70
|
+
|
71
|
+
# TODO: treat rest as not
|
72
|
+
_generate(merge_schema(merged_schema, schema.one_of.first), hint: hint, position: "position/one_of[0]")
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_for_any_of(schema, hint: nil, position:)
|
76
|
+
merged_schema = JsonSchema::Schema.new
|
77
|
+
merged_schema.copy_from(schema)
|
78
|
+
|
79
|
+
merged_schema.any_of = []
|
80
|
+
|
81
|
+
_generate(merge_schema(merged_schema, schema.any_of.first), hint: hint, position: "position/any_of[0]")
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_for_all_of(schema, hint: nil, position:)
|
85
|
+
# deep_merge all_of
|
86
|
+
merged_schema = JsonSchema::Schema.new
|
87
|
+
merged_schema.copy_from(schema)
|
88
|
+
|
89
|
+
merged_schema.all_of = []
|
90
|
+
|
91
|
+
schema.all_of.each do |sub_schema|
|
92
|
+
merge_schema(merged_schema, sub_schema)
|
93
|
+
end
|
94
|
+
|
95
|
+
_generate(merged_schema, hint: hint, position: "position/all_of")
|
96
|
+
end
|
97
|
+
|
98
|
+
def generate_for_object(schema, hint: nil, position:)
|
99
|
+
# http://json-schema.org/latest/json-schema-validation.html#anchor53
|
100
|
+
if schema.required
|
101
|
+
keys = schema.required
|
102
|
+
required_length = schema.min_properties || keys.length
|
103
|
+
|
104
|
+
object = keys.each.with_object({}) do |key, hash|
|
105
|
+
hash[key] = _generate(schema.properties[key], hint: hint, position: "#{position}/#{key}") # TODO: pass hint
|
106
|
+
end
|
107
|
+
else
|
108
|
+
required_length = schema.min_properties || schema.max_properties || 0
|
109
|
+
|
110
|
+
keys = (schema.properties || {}).keys
|
111
|
+
keys -= (hint[:not_have_keys] || []) if hint
|
112
|
+
|
113
|
+
object = keys.first(required_length).each.with_object({}) do |key, hash|
|
114
|
+
hash[key] = _generate(schema.properties[key], hint: hint, position: "#{position}/#{key}") # TODO: pass hint
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# if length is not enough
|
119
|
+
if schema.additional_properties === false
|
120
|
+
(required_length - object.keys.length).times.each.with_object(object) do |i, hash|
|
121
|
+
if schema.pattern_properties.empty?
|
122
|
+
key = (schema.properties.keys - object.keys).first
|
123
|
+
hash[key] = _generate(schema.properties[key], hint: hint, position: "#{position}/#{key}")
|
124
|
+
else
|
125
|
+
name = Pxeger.new(schema.pattern_properties.keys.first).generate
|
126
|
+
hash[name] = _generate(schema.pattern_properties.values.first, hint: hint, position: "#{position}/#{name}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
else
|
130
|
+
# FIXME: key confilct with properties
|
131
|
+
(required_length - object.keys.length).times.each.with_object(object) do |i, hash|
|
132
|
+
hash[i.to_s] = i
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# consider dependency
|
137
|
+
depended_keys = object.keys & schema.dependencies.keys
|
138
|
+
|
139
|
+
# FIXME: circular dependency is not supported
|
140
|
+
depended_keys.each.with_object(object) do |key, hash|
|
141
|
+
dependency = schema.dependencies[key]
|
142
|
+
|
143
|
+
if dependency.is_a?(JsonSchema::Schema)
|
144
|
+
# too difficult we just merge
|
145
|
+
hash.update(_generate(schema.dependencies[key], hint: nil, position: "#{position}/dependencies/#{key}"))
|
146
|
+
else
|
147
|
+
dependency.each do |additional_key|
|
148
|
+
object[additional_key] = _generate(schema.properties[additional_key], hint: hint, position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def generate_by_enum(schema, hint: nil, position:)
|
155
|
+
black_list = (hint ? hint[:not_be_values] : nil)
|
156
|
+
|
157
|
+
if Configuration.logger
|
158
|
+
Configuration.logger.info "generate by enum at #{position}"
|
159
|
+
Configuration.logger.debug schema.inspect_schema
|
160
|
+
Configuration.logger.debug "black list: #{black_list}" if black_list
|
161
|
+
end
|
162
|
+
|
163
|
+
if black_list
|
164
|
+
(schema.enum - black_list).first
|
165
|
+
else
|
166
|
+
schema.enum.first
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def generate_by_type(schema, hint: nil, position:)
|
171
|
+
if Configuration.logger
|
172
|
+
Configuration.logger.info "generate by type at #{position}"
|
173
|
+
Configuration.logger.debug schema.inspect_schema
|
174
|
+
end
|
175
|
+
|
176
|
+
# http://json-schema.org/latest/json-schema-core.html#anchor8
|
177
|
+
# TODO: use include? than first
|
178
|
+
case schema.type.first
|
179
|
+
when "array"
|
180
|
+
generate_for_array(schema, hint: hint, position: position)
|
181
|
+
when "boolean"
|
182
|
+
true
|
183
|
+
when "integer", "number"
|
184
|
+
generate_for_number(schema, hint: hint)
|
185
|
+
when "null"
|
186
|
+
nil
|
187
|
+
when "object"
|
188
|
+
# here comes object without properties
|
189
|
+
generate_for_object(schema, hint: hint, position: position)
|
190
|
+
when "string"
|
191
|
+
generate_for_string(schema, hint: hint)
|
192
|
+
else
|
193
|
+
raise "unknown type for #{schema.inspect_schema}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def generate_for_array(schema, hint: nil, position:)
|
198
|
+
# http://json-schema.org/latest/json-schema-validation.html#anchor36
|
199
|
+
# additionalItems items maxItems minItems uniqueItems
|
200
|
+
length = schema.min_items || 0
|
201
|
+
|
202
|
+
# if "items" is not present, or its value is an object, validation of the instance always succeeds, regardless of the value of "additionalItems";
|
203
|
+
# if the value of "additionalItems" is boolean value true or an object, validation of the instance always succeeds;
|
204
|
+
item = if (schema.items.nil? || schema.items.is_a?(JsonSchema::Schema)) || ( schema.additional_items === true || schema.additional_items.is_a?(JsonSchema::Schema))
|
205
|
+
length.times.map.with_index {|i| i }
|
206
|
+
else # in case schema.items is array and schema.additional_items is true
|
207
|
+
# if the value of "additionalItems" is boolean value false and the value of "items" is an array
|
208
|
+
# the instance is valid if its size is less than, or equal to, the size of "items".
|
209
|
+
raise "#{position}: item length(#{schema.items.length} is shorter than minItems(#{schema.min_items}))" unless schema.items.length <= length
|
210
|
+
|
211
|
+
# TODO: consider unique items
|
212
|
+
length.times.map.with_index {|i| _generate(schema.items[i], position: position + "[#{i}]") }
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def generate_for_number(schema, hint: nil)
|
217
|
+
# http://json-schema.org/latest/json-schema-validation.html#anchor13
|
218
|
+
# TODO: use hint[:not_be_values]
|
219
|
+
min = schema.min
|
220
|
+
max = schema.max
|
221
|
+
|
222
|
+
if schema.multiple_of
|
223
|
+
min = (min + schema.multiple_of - min % schema.multiple_of) if min
|
224
|
+
max = (max - max % schema.multiple_of) if max
|
225
|
+
end
|
226
|
+
|
227
|
+
delta = schema.multiple_of ? schema.multiple_of : 1
|
228
|
+
|
229
|
+
# TODO: more sophisticated caluculation
|
230
|
+
min, max = [ (min || (max ? max - delta * 2 : 0)), (max || (min ? min + delta * 2 : 0)) ]
|
231
|
+
|
232
|
+
# to get average of min and max can avoid exclusive*
|
233
|
+
if schema.type.first == "integer"
|
234
|
+
(min / delta + max / delta) / 2 * delta
|
235
|
+
else
|
236
|
+
(min + max) / 2.0
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def generate_for_string(schema, hint: nil)
|
241
|
+
# http://json-schema.org/latest/json-schema-validation.html#anchor25
|
242
|
+
# TODO: use hint[:not_be_values]
|
243
|
+
# TODO: support format
|
244
|
+
if schema.pattern
|
245
|
+
Pxeger.new(schema.pattern).generate
|
246
|
+
else
|
247
|
+
length = schema.min_length || 0
|
248
|
+
"a" * length
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def merge_schema(a, b)
|
253
|
+
# attr not supported now
|
254
|
+
# any_of: too difficult...
|
255
|
+
# enum/items: TODO: just get and of array
|
256
|
+
# not: too difficult (if `not` is not wrapped by all_of wrap it?)
|
257
|
+
# multiple_of TODO: least common multiple
|
258
|
+
# pattern: too difficult...
|
259
|
+
# format TODO: just override
|
260
|
+
|
261
|
+
# array properties
|
262
|
+
%i[ type one_of all_of ].each do |attr|
|
263
|
+
a.__send__("#{attr}=", a.__send__(attr) + b.__send__(attr))
|
264
|
+
end
|
265
|
+
a.required = (a.required ? a.required + b.required : b.required) if b.required
|
266
|
+
|
267
|
+
# object properties
|
268
|
+
# XXX: key conflict
|
269
|
+
%i[ properties pattern_properties dependencies ].each do |attr|
|
270
|
+
a.__send__("#{attr}=", a.__send__(attr).merge(b.__send__(attr)))
|
271
|
+
end
|
272
|
+
|
273
|
+
# override to stronger validation
|
274
|
+
%i[ additional_items additional_properties ].each do |attr|
|
275
|
+
a.__send__("#{attr}=", false) unless a.__send__(attr) && b.__send__(attr)
|
276
|
+
end
|
277
|
+
%i[ min_exclusive max_exclusive unique_items ].each do |attr|
|
278
|
+
a.__send__("#{attr}=", a.__send__(attr) & b.__send__(attr))
|
279
|
+
end
|
280
|
+
%i[ min min_length min_properties ].each do |attr|
|
281
|
+
if b.__send__(attr)
|
282
|
+
if a.__send__(attr)
|
283
|
+
a.__send__("#{attr}=", b.__send__(attr)) if b.__send__(attr) < a.__send__(attr)
|
284
|
+
else
|
285
|
+
a.__send__("#{attr}=", b.__send__(attr))
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
%i[ max max_length max_properties ].each do |attr|
|
290
|
+
if b.__send__(attr)
|
291
|
+
if a.__send__(attr)
|
292
|
+
a.__send__("#{attr}=", b.__send__(attr)) if b.__send__(attr) > a.__send__(attr)
|
293
|
+
else
|
294
|
+
a.__send__("#{attr}=", b.__send__(attr))
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
a
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_schema-faker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- okitan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json_schema
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pxeger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: generate fake data from json schema
|
112
|
+
email:
|
113
|
+
- okitakunio@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".gitmodules"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Guardfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- json_schema-faker.gemspec
|
132
|
+
- lib/json_schema/faker.rb
|
133
|
+
homepage: https://github.com/okitan/json_schema-faker
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.5.1
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: generate fake data from json schema
|
157
|
+
test_files: []
|