openapi_parser 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/.rubocop_ignore.yml +6 -0
  4. data/.travis.yml +33 -4
  5. data/CHANGELOG.md +9 -0
  6. data/README.md +39 -6
  7. data/lib/openapi_parser/concern.rb +2 -1
  8. data/lib/openapi_parser/concerns/expandable.rb +52 -44
  9. data/lib/openapi_parser/concerns/media_type_selectable.rb +26 -0
  10. data/lib/openapi_parser/concerns/parser.rb +43 -0
  11. data/lib/openapi_parser/concerns/parser/core.rb +21 -0
  12. data/lib/openapi_parser/concerns/parser/hash.rb +10 -0
  13. data/lib/openapi_parser/concerns/parser/hash_body.rb +12 -0
  14. data/lib/openapi_parser/concerns/parser/list.rb +10 -0
  15. data/lib/openapi_parser/concerns/parser/object.rb +14 -0
  16. data/lib/openapi_parser/concerns/parser/value.rb +14 -0
  17. data/lib/openapi_parser/concerns/schema_loader.rb +58 -0
  18. data/lib/openapi_parser/concerns/schema_loader/base.rb +28 -0
  19. data/lib/openapi_parser/concerns/schema_loader/creator.rb +48 -0
  20. data/lib/openapi_parser/concerns/schema_loader/hash_body_loader.rb +37 -0
  21. data/lib/openapi_parser/concerns/schema_loader/hash_objects_loader.rb +29 -0
  22. data/lib/openapi_parser/concerns/schema_loader/list_loader.rb +28 -0
  23. data/lib/openapi_parser/concerns/schema_loader/objects_loader.rb +21 -0
  24. data/lib/openapi_parser/concerns/schema_loader/values_loader.rb +10 -0
  25. data/lib/openapi_parser/config.rb +1 -1
  26. data/lib/openapi_parser/errors.rb +9 -0
  27. data/lib/openapi_parser/path_item_finder.rb +18 -18
  28. data/lib/openapi_parser/request_operation.rb +4 -4
  29. data/lib/openapi_parser/schema_validator.rb +77 -54
  30. data/lib/openapi_parser/schema_validators/all_of_validator.rb +16 -0
  31. data/lib/openapi_parser/schema_validators/any_of_validator.rb +1 -1
  32. data/lib/openapi_parser/schema_validators/array_validator.rb +2 -4
  33. data/lib/openapi_parser/schema_validators/base.rb +9 -6
  34. data/lib/openapi_parser/schema_validators/boolean_validator.rb +11 -9
  35. data/lib/openapi_parser/schema_validators/float_validator.rb +8 -10
  36. data/lib/openapi_parser/schema_validators/integer_validator.rb +11 -10
  37. data/lib/openapi_parser/schema_validators/nil_validator.rb +1 -0
  38. data/lib/openapi_parser/schema_validators/object_validator.rb +3 -3
  39. data/lib/openapi_parser/schema_validators/string_validator.rb +13 -13
  40. data/lib/openapi_parser/schemas/base.rb +1 -2
  41. data/lib/openapi_parser/schemas/media_type.rb +3 -1
  42. data/lib/openapi_parser/schemas/openapi.rb +1 -1
  43. data/lib/openapi_parser/schemas/operation.rb +17 -14
  44. data/lib/openapi_parser/schemas/parameter.rb +2 -2
  45. data/lib/openapi_parser/schemas/request_body.rb +12 -5
  46. data/lib/openapi_parser/schemas/response.rb +4 -4
  47. data/lib/openapi_parser/schemas/responses.rb +21 -3
  48. data/lib/openapi_parser/version.rb +1 -1
  49. data/openapi_parser.gemspec +3 -2
  50. metadata +51 -19
  51. data/lib/openapi_parser/concerns/parseable.rb +0 -238
@@ -1,3 +1,3 @@
1
1
  module OpenAPIParser
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
@@ -24,9 +24,10 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.16'
26
26
  spec.add_development_dependency 'fincop'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
29
27
  spec.add_development_dependency 'pry'
30
28
  spec.add_development_dependency 'pry-byebug'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
31
  spec.add_development_dependency 'rspec-parameterized'
32
+ spec.add_development_dependency 'simplecov'
32
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ota42y
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-23 00:00:00.000000000 Z
11
+ date: 2018-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,49 +39,63 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: pry-byebug
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
+ - !ruby/object:Gem::Dependency
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '3.0'
75
+ version: '10.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '3.0'
82
+ version: '10.0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: pry
84
+ name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '3.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '3.0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: pry-byebug
98
+ name: rspec-parameterized
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: rspec-parameterized
112
+ name: simplecov
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -118,7 +132,9 @@ files:
118
132
  - ".gitignore"
119
133
  - ".rspec"
120
134
  - ".rubocop.yml"
135
+ - ".rubocop_ignore.yml"
121
136
  - ".travis.yml"
137
+ - CHANGELOG.md
122
138
  - CODE_OF_CONDUCT.md
123
139
  - Gemfile
124
140
  - LICENSE.txt
@@ -130,7 +146,22 @@ files:
130
146
  - lib/openapi_parser/concern.rb
131
147
  - lib/openapi_parser/concerns/expandable.rb
132
148
  - lib/openapi_parser/concerns/findable.rb
133
- - lib/openapi_parser/concerns/parseable.rb
149
+ - lib/openapi_parser/concerns/media_type_selectable.rb
150
+ - lib/openapi_parser/concerns/parser.rb
151
+ - lib/openapi_parser/concerns/parser/core.rb
152
+ - lib/openapi_parser/concerns/parser/hash.rb
153
+ - lib/openapi_parser/concerns/parser/hash_body.rb
154
+ - lib/openapi_parser/concerns/parser/list.rb
155
+ - lib/openapi_parser/concerns/parser/object.rb
156
+ - lib/openapi_parser/concerns/parser/value.rb
157
+ - lib/openapi_parser/concerns/schema_loader.rb
158
+ - lib/openapi_parser/concerns/schema_loader/base.rb
159
+ - lib/openapi_parser/concerns/schema_loader/creator.rb
160
+ - lib/openapi_parser/concerns/schema_loader/hash_body_loader.rb
161
+ - lib/openapi_parser/concerns/schema_loader/hash_objects_loader.rb
162
+ - lib/openapi_parser/concerns/schema_loader/list_loader.rb
163
+ - lib/openapi_parser/concerns/schema_loader/objects_loader.rb
164
+ - lib/openapi_parser/concerns/schema_loader/values_loader.rb
134
165
  - lib/openapi_parser/config.rb
135
166
  - lib/openapi_parser/errors.rb
136
167
  - lib/openapi_parser/parameter_validator.rb
@@ -138,6 +169,7 @@ files:
138
169
  - lib/openapi_parser/reference_expander.rb
139
170
  - lib/openapi_parser/request_operation.rb
140
171
  - lib/openapi_parser/schema_validator.rb
172
+ - lib/openapi_parser/schema_validators/all_of_validator.rb
141
173
  - lib/openapi_parser/schema_validators/any_of_validator.rb
142
174
  - lib/openapi_parser/schema_validators/array_validator.rb
143
175
  - lib/openapi_parser/schema_validators/base.rb
@@ -185,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
217
  - !ruby/object:Gem::Version
186
218
  version: '0'
187
219
  requirements: []
188
- rubygems_version: 3.0.0.beta3
220
+ rubygems_version: 3.0.1
189
221
  signing_key:
190
222
  specification_version: 4
191
223
  summary: OpenAPI3 parser
@@ -1,238 +0,0 @@
1
- module OpenAPIParser::Parseable
2
- def self.included(base)
3
- base.extend(ClassMethods)
4
- end
5
- module ClassMethods
6
- attr_reader :_openapi_attr_values,
7
- :_openapi_attr_list_objects,
8
- :_openapi_attr_objects,
9
- :_openapi_attr_hash_objects,
10
- :_openapi_attr_hash_body_objects
11
-
12
- # no option support
13
- def openapi_attr_values(*names)
14
- names.each { |name| openapi_attr_value(name) }
15
- end
16
-
17
- def openapi_attr_value(name, options = {})
18
- @_openapi_attr_values = {} unless defined?(@_openapi_attr_values)
19
-
20
- attr_reader name
21
- @_openapi_attr_values[name] = options
22
- end
23
-
24
- # no option support
25
- def openapi_attr_objects(*names, klass)
26
- names.each { |name| openapi_attr_object(name, klass) }
27
- end
28
-
29
- def openapi_attr_object(name, klass, options = {})
30
- @_openapi_attr_objects = {} unless defined?(@_openapi_attr_objects )
31
-
32
- attr_reader name
33
- @_openapi_attr_objects[name] = options.merge(klass: klass)
34
- end
35
-
36
- def openapi_attr_list_object(name, klass, options = {})
37
- @_openapi_attr_list_objects = {} unless defined?(@_openapi_attr_list_objects)
38
-
39
- attr_reader name
40
- @_openapi_attr_list_objects[name] = options.merge(klass: klass)
41
- end
42
-
43
- def openapi_attr_hash_object(name, klass, options = {})
44
- @_openapi_attr_hash_objects = {} unless defined?(@_openapi_attr_hash_objects)
45
-
46
- attr_reader name
47
- @_openapi_attr_hash_objects[name] = options.merge(klass: klass)
48
- end
49
-
50
- def openapi_attr_hash_body_objects(name, klass, options = {})
51
- @_openapi_attr_hash_body_objects = {} unless defined?(@_openapi_attr_hash_body_objects)
52
-
53
- options[:reject_keys] = options[:reject_keys] ? options[:reject_keys].map(&:to_s) : []
54
-
55
- attr_reader name
56
- @_openapi_attr_hash_body_objects[name] = options.merge(klass: klass)
57
- end
58
- end
59
-
60
- def child_from_reference(reference)
61
- _openapi_all_child_objects[reference]
62
- end
63
-
64
- def _openapi_all_child_objects
65
- @_openapi_all_child_objects ||= {}
66
- end
67
-
68
- def _add_child_object(object)
69
- return unless object.is_a?(OpenAPIParser::Parseable)
70
- _openapi_all_child_objects[object.object_reference] = object
71
- end
72
-
73
- def _update_child_object(old, new)
74
- _openapi_all_child_objects[old.object_reference] = new
75
- end
76
-
77
- def load_data
78
- create_attr_values(self.class._openapi_attr_values)
79
-
80
- create_attr_objects(self.class._openapi_attr_objects)
81
- create_attr_list_objects(self.class._openapi_attr_list_objects)
82
- create_attr_hash_objects(self.class._openapi_attr_hash_objects)
83
- create_attr_hash_body_objects(self.class._openapi_attr_hash_body_objects)
84
- end
85
-
86
- def create_attr_list_objects(settings)
87
- return unless settings
88
-
89
- settings.each do |variable_name, options|
90
- ref_name_base = options[:schema_key] ? options[:schema_key] : variable_name
91
- klass = options[:klass]
92
- allow_reference = options[:reference] || false
93
- allow_data_type = options[:allow_data_type]
94
-
95
- create_attr_list_object(variable_name, raw_schema[ref_name_base.to_s], ref_name_base, klass, allow_reference, allow_data_type)
96
- end
97
- end
98
-
99
- def create_attr_hash_objects(settings)
100
- return unless settings
101
-
102
- settings.each do |variable_name, options|
103
- ref_name_base = options[:schema_key] ? options[:schema_key] : variable_name
104
- klass = options[:klass]
105
- allow_reference = options[:reference] || false
106
- allow_data_type = options[:allow_data_type]
107
-
108
- create_attr_hash_object(variable_name, raw_schema[ref_name_base .to_s], ref_name_base, klass, allow_reference, allow_data_type)
109
- end
110
- end
111
-
112
- def create_attr_objects(values)
113
- return unless values
114
-
115
- values.each do |name, options|
116
- key = options[:schema_key] ? options[:schema_key] : name
117
- klass = options[:klass]
118
- allow_reference = options[:reference] || false
119
- allow_data_type = options[:allow_data_type]
120
-
121
- obj = create_attr_object(name, key, raw_schema[key.to_s], klass, allow_reference, allow_data_type)
122
- _add_child_object(obj)
123
- end
124
- end
125
-
126
- def create_attr_hash_body_objects(values)
127
- return unless values
128
-
129
- values.each do |name, options|
130
- klass = options[:klass]
131
- allow_reference = options[:reference] || false
132
- allow_data_type = options[:allow_data_type]
133
- reject_keys = options[:reject_keys]
134
-
135
- create_hash_body_objects(name, raw_schema, klass, allow_reference, allow_data_type, reject_keys)
136
- end
137
- end
138
-
139
- def create_attr_values(values)
140
- return unless values
141
-
142
- values.each do |variable_name, options|
143
- key = options[:schema_key] ? options[:schema_key] : variable_name
144
-
145
- create_variable(variable_name, raw_schema[key.to_s])
146
- end
147
- end
148
-
149
-
150
- # for responses and paths object
151
- def create_hash_body_objects(name, schema, klass, allow_reference, allow_data_type, reject_keys)
152
- unless schema
153
- create_variable(name, nil)
154
- return
155
- end
156
-
157
- objects = schema.reject{|k, _| reject_keys.include?(k)}.map do |name, child_schema|
158
- [
159
- name.to_s, # support string key only in OpenAPI3
160
- build_openapi_object(escape_reference(name), child_schema, klass, allow_reference, allow_data_type)
161
- ]
162
- end.to_h
163
-
164
- create_variable(name, objects)
165
- objects.values.each { |o| _add_child_object(o) }
166
- end
167
-
168
- # @return [OpenAPIParser::Schemas::Base]
169
- def create_attr_object(variable_name, ref_name, schema, klass, allow_reference, allow_data_type)
170
- data = build_openapi_object(ref_name, schema, klass, allow_reference, allow_data_type)
171
- create_variable(variable_name, data)
172
- data
173
- end
174
-
175
- def create_attr_hash_object(variable_name, hash_schema, ref_name_base, klass, allow_reference, allow_data_type)
176
- data = if hash_schema
177
- hash_schema.map { |key, s| [key, build_openapi_object([ref_name_base, key], s, klass, allow_reference, allow_data_type) ]}.to_h
178
- else
179
- nil
180
- end
181
-
182
- create_variable(variable_name, data)
183
- data.values.each { |obj| _add_child_object(obj) } if data
184
- end
185
-
186
- def create_attr_list_object(variable_name, array_schema, ref_name_base, klass, allow_reference, allow_data_type)
187
- data = if array_schema
188
- array_schema.map.with_index { |s, idx| build_openapi_object([ref_name_base, idx], s, klass, allow_reference, allow_data_type) }
189
- else
190
- nil
191
- end
192
-
193
- create_variable(variable_name, data)
194
- data.each { |obj| _add_child_object(obj) } if data
195
- end
196
-
197
-
198
- # create instance variable @variable_name using data
199
- # @param [String] variable_name
200
- # @param [Object] data
201
- def create_variable(variable_name, data)
202
- instance_variable_set("@#{variable_name}", data)
203
- end
204
-
205
- # return nil, klass, Reference
206
- def build_openapi_object(ref_names, schema, klass, allow_reference, allow_data_type)
207
- return nil unless schema
208
-
209
- if allow_data_type && !check_object_schema?(schema)
210
- schema
211
- elsif allow_reference && check_reference_schema?(schema)
212
- OpenAPIParser::Schemas::Reference.new(build_object_reference(ref_names), self, self.root, schema)
213
- else
214
- klass.new(build_object_reference(ref_names), self, self.root, schema)
215
- end
216
- end
217
-
218
- # @return Boolean
219
- def check_reference_schema?(check_schema)
220
- check_object_schema?(check_schema) && !check_schema['$ref'].nil?
221
- end
222
-
223
- def check_object_schema?(check_schema)
224
- check_schema.is_a?(Hash)
225
- end
226
-
227
- def escape_reference(str)
228
- str.to_s.gsub('/', '~1')
229
- end
230
-
231
- # @return [String]
232
- def build_object_reference(names)
233
- names = [names] unless names.is_a?(Array)
234
- ref = names.map{ |n| escape_reference(n)}.join('/')
235
-
236
- "#{object_reference}/#{ref}"
237
- end
238
- end