apipie-rails 0.5.7 → 0.5.8
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/CHANGELOG.md +8 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +320 -2
- data/lib/apipie-rails.rb +2 -0
- data/lib/apipie/application.rb +1 -1
- data/lib/apipie/configuration.rb +5 -2
- data/lib/apipie/dsl_definition.rb +69 -1
- data/lib/apipie/errors.rb +6 -1
- data/lib/apipie/extractor/writer.rb +65 -42
- data/lib/apipie/method_description.rb +32 -2
- data/lib/apipie/param_description.rb +19 -1
- data/lib/apipie/resource_description.rb +3 -1
- data/lib/apipie/response_description.rb +125 -0
- data/lib/apipie/response_description_adapter.rb +199 -0
- data/lib/apipie/swagger_generator.rb +106 -16
- data/lib/apipie/version.rb +1 -1
- data/spec/controllers/apipies_controller_spec.rb +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/pets_controller.rb +391 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/lib/extractor/writer_spec.rb +32 -4
- data/spec/lib/method_description_spec.rb +27 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +4 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +489 -0
- data/spec/spec_helper.rb +94 -0
- metadata +13 -2
data/spec/spec_helper.rb
CHANGED
@@ -33,6 +33,100 @@ module Rails4Compatibility
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
|
37
|
+
#
|
38
|
+
# Matcher to validate the hierarchy of fields described in an internal 'returns' object (without checking their type)
|
39
|
+
#
|
40
|
+
# For example, code such as:
|
41
|
+
# returns_obj = Apipie.get_resource_description(...)._methods.returns.detect{|e| e.code=200})
|
42
|
+
# expect(returns_obj).to match_param_structure([:pet_name, :animal_type, :pet_measurements => [:weight, :height]])
|
43
|
+
#
|
44
|
+
# will verify that the payload structure described for the response of return code 200 is:
|
45
|
+
# {
|
46
|
+
# "pet_name": <any>,
|
47
|
+
# "animal_type": <any>,
|
48
|
+
# "pet_measurements": {
|
49
|
+
# "weight": <any>,
|
50
|
+
# "height": <any>
|
51
|
+
# }
|
52
|
+
# }
|
53
|
+
#
|
54
|
+
#
|
55
|
+
RSpec::Matchers.define :match_field_structure do |expected|
|
56
|
+
@last_message = nil
|
57
|
+
|
58
|
+
match do |actual|
|
59
|
+
deep_match?(actual, expected)
|
60
|
+
end
|
61
|
+
|
62
|
+
def deep_match?(actual, expected, breadcrumb=[])
|
63
|
+
num = 0
|
64
|
+
expected.each do |pdesc|
|
65
|
+
if pdesc.is_a? Symbol
|
66
|
+
return false unless matching_param(actual.params_ordered, pdesc, breadcrumb)
|
67
|
+
elsif pdesc.is_a? Hash
|
68
|
+
param = matching_param(actual.params_ordered, pdesc.keys[0], breadcrumb)
|
69
|
+
return false unless param
|
70
|
+
return false unless deep_match?(param.validator, pdesc.values[0], breadcrumb + [pdesc.keys[0]])
|
71
|
+
end
|
72
|
+
num+=1
|
73
|
+
end
|
74
|
+
@fail_message = "expected property count#{breadcrumb == [] ? '' : ' of ' + (breadcrumb).join('.')} (#{actual.params_ordered.count}) to be #{num}"
|
75
|
+
actual.params_ordered.count == num
|
76
|
+
end
|
77
|
+
|
78
|
+
def matching_param(params, expected_name, breadcrumb)
|
79
|
+
param = params.find { |p| p.name.to_s == expected_name.to_s }
|
80
|
+
unless param
|
81
|
+
@fail_message = "expected [#{ params.map(&:name).join(', ') }] to include #{(breadcrumb + [expected_name]).join('.')}"
|
82
|
+
end
|
83
|
+
param
|
84
|
+
end
|
85
|
+
|
86
|
+
failure_message do |actual|
|
87
|
+
@fail_message
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
#
|
94
|
+
# Matcher to validate the properties (name, type and options) of a single field in the
|
95
|
+
# internal representation of a swagger schema
|
96
|
+
#
|
97
|
+
# For example, code such as:
|
98
|
+
# schema = swagger[:paths][<path>][<method>][:responses][<code>][:schema]
|
99
|
+
# expect(schema).to have_field(:pet_name, 'string', {:required => false})
|
100
|
+
#
|
101
|
+
# will verify that the selected response schema includes a required string field called 'pet_name'
|
102
|
+
#
|
103
|
+
RSpec::Matchers.define :have_field do |name, type, opts={}|
|
104
|
+
def fail(msg)
|
105
|
+
@fail_message = msg
|
106
|
+
false
|
107
|
+
end
|
108
|
+
|
109
|
+
@fail_message = ""
|
110
|
+
|
111
|
+
failure_message do |actual|
|
112
|
+
@fail_message
|
113
|
+
end
|
114
|
+
|
115
|
+
match do |actual|
|
116
|
+
return fail("expected schema to have type 'object' (got '#{actual[:type]}')") if (actual[:type]) != 'object'
|
117
|
+
return fail("expected schema to include param named '#{name}' (got #{actual[:properties].keys})") if (prop = actual[:properties][name]).nil?
|
118
|
+
return fail("expected param '#{name}' to have type '#{type}' (got '#{prop[:type]}')") if prop[:type] != type
|
119
|
+
return fail("expected param '#{name}' to have description '#{opts[:description]}' (got '#{prop[:description]}')") if opts[:description] && prop[:description] != opts[:description]
|
120
|
+
return fail("expected param '#{name}' to have enum '#{opts[:enum]}' (got #{prop[:enum]})") if opts[:enum] && prop[:enum] != opts[:enum]
|
121
|
+
if !opts.include?(:required) || opts[:required] == true
|
122
|
+
return fail("expected param '#{name}' to be required") unless actual[:required].include?(name)
|
123
|
+
else
|
124
|
+
return fail("expected param '#{name}' to be optional") if actual[:required].include?(name)
|
125
|
+
end
|
126
|
+
true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
36
130
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
37
131
|
# in spec/support/ and its subdirectories.
|
38
132
|
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apipie-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pokorny
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- Gemfile.rails51
|
158
158
|
- MIT-LICENSE
|
159
159
|
- NOTICE
|
160
|
+
- PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md
|
160
161
|
- README.rst
|
161
162
|
- Rakefile
|
162
163
|
- apipie-rails.gemspec
|
@@ -220,6 +221,8 @@ files:
|
|
220
221
|
- lib/apipie/param_description.rb
|
221
222
|
- lib/apipie/railtie.rb
|
222
223
|
- lib/apipie/resource_description.rb
|
224
|
+
- lib/apipie/response_description.rb
|
225
|
+
- lib/apipie/response_description_adapter.rb
|
223
226
|
- lib/apipie/routes_formatter.rb
|
224
227
|
- lib/apipie/routing.rb
|
225
228
|
- lib/apipie/see_description.rb
|
@@ -257,6 +260,9 @@ files:
|
|
257
260
|
- spec/dummy/app/controllers/extended_controller.rb
|
258
261
|
- spec/dummy/app/controllers/files_controller.rb
|
259
262
|
- spec/dummy/app/controllers/overridden_concerns_controller.rb
|
263
|
+
- spec/dummy/app/controllers/pets_controller.rb
|
264
|
+
- spec/dummy/app/controllers/pets_using_auto_views_controller.rb
|
265
|
+
- spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb
|
260
266
|
- spec/dummy/app/controllers/twitter_example_controller.rb
|
261
267
|
- spec/dummy/app/controllers/users_controller.rb
|
262
268
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -296,6 +302,7 @@ files:
|
|
296
302
|
- spec/lib/resource_description_spec.rb
|
297
303
|
- spec/lib/swagger/openapi_2_0_schema.json
|
298
304
|
- spec/lib/swagger/rake_swagger_spec.rb
|
305
|
+
- spec/lib/swagger/swagger_dsl_spec.rb
|
299
306
|
- spec/lib/validator_spec.rb
|
300
307
|
- spec/lib/validators/array_validator_spec.rb
|
301
308
|
- spec/spec_helper.rb
|
@@ -346,6 +353,9 @@ test_files:
|
|
346
353
|
- spec/dummy/app/controllers/extended_controller.rb
|
347
354
|
- spec/dummy/app/controllers/files_controller.rb
|
348
355
|
- spec/dummy/app/controllers/overridden_concerns_controller.rb
|
356
|
+
- spec/dummy/app/controllers/pets_controller.rb
|
357
|
+
- spec/dummy/app/controllers/pets_using_auto_views_controller.rb
|
358
|
+
- spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb
|
349
359
|
- spec/dummy/app/controllers/twitter_example_controller.rb
|
350
360
|
- spec/dummy/app/controllers/users_controller.rb
|
351
361
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -385,6 +395,7 @@ test_files:
|
|
385
395
|
- spec/lib/resource_description_spec.rb
|
386
396
|
- spec/lib/swagger/openapi_2_0_schema.json
|
387
397
|
- spec/lib/swagger/rake_swagger_spec.rb
|
398
|
+
- spec/lib/swagger/swagger_dsl_spec.rb
|
388
399
|
- spec/lib/validator_spec.rb
|
389
400
|
- spec/lib/validators/array_validator_spec.rb
|
390
401
|
- spec/spec_helper.rb
|