apipie-rails 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +21 -12
- data/CHANGELOG.md +8 -0
- data/README.rst +6 -3
- data/lib/apipie/dsl_definition.rb +5 -4
- data/lib/apipie/errors.rb +14 -0
- data/lib/apipie/extractor.rb +6 -3
- data/lib/apipie/generator/swagger/config.rb +3 -1
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +6 -3
- data/lib/apipie/validator.rb +20 -6
- data/lib/apipie/version.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +10 -0
- data/spec/dummy/app/controllers/users_controller.rb +6 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +13 -0
- data/spec/test_engine/memes_controller_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 555b019a70732e777c4f42b25dd62362be62674c55f31dba9106434969ff7f9f
|
4
|
+
data.tar.gz: e63cd96de5768bc21b4a86b755b883440a36ca8c8914ec5af4c89dfe525d94ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d6aca2dea2281738587924ee7e3388b1b36beb25d9bac7e46f05044080535f52fb77a3523d9262344410f3d76683c0d33a7d0188d99a51d957a9f9392ba7a3e
|
7
|
+
data.tar.gz: 7f74cc96e3694406b579649cbd44b8a9ab7d7c273b57d93a7530e1b67a2e32dca27efa408b27a10d87f342abc5badde819e7f02e363ff3d924d3988db33501f2
|
data/.rubocop.yml
CHANGED
@@ -46,7 +46,7 @@ Metrics/ClassLength:
|
|
46
46
|
- spec/dummy/app/controllers/users_controller.rb
|
47
47
|
|
48
48
|
Metrics/BlockLength:
|
49
|
-
Max:
|
49
|
+
Max: 26 # default
|
50
50
|
Exclude:
|
51
51
|
- app/controllers/apipie/apipies_controller.rb
|
52
52
|
- lib/apipie/generator/swagger/param_description/composite.rb
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config --exclude-limit 180`
|
3
|
-
# on 2023-06-
|
3
|
+
# on 2023-06-09 05:29:05 UTC using RuboCop version 1.52.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -118,7 +118,7 @@ Layout/ElseAlignment:
|
|
118
118
|
- 'lib/apipie/param_description.rb'
|
119
119
|
- 'lib/apipie/resource_description.rb'
|
120
120
|
|
121
|
-
# Offense count:
|
121
|
+
# Offense count: 58
|
122
122
|
# This cop supports safe autocorrection (--autocorrect).
|
123
123
|
Layout/EmptyLineAfterGuardClause:
|
124
124
|
Exclude:
|
@@ -783,6 +783,12 @@ Lint/Void:
|
|
783
783
|
Metrics/AbcSize:
|
784
784
|
Max: 96
|
785
785
|
|
786
|
+
# Offense count: 1
|
787
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
788
|
+
# AllowedMethods: refine
|
789
|
+
Metrics/BlockLength:
|
790
|
+
Max: 26
|
791
|
+
|
786
792
|
# Offense count: 4
|
787
793
|
# Configuration parameters: CountBlocks.
|
788
794
|
Metrics/BlockNesting:
|
@@ -793,11 +799,16 @@ Metrics/BlockNesting:
|
|
793
799
|
Metrics/CyclomaticComplexity:
|
794
800
|
Max: 24
|
795
801
|
|
796
|
-
# Offense count:
|
802
|
+
# Offense count: 79
|
797
803
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
798
804
|
Metrics/MethodLength:
|
799
805
|
Max: 58
|
800
806
|
|
807
|
+
# Offense count: 1
|
808
|
+
# Configuration parameters: CountComments, CountAsOne.
|
809
|
+
Metrics/ModuleLength:
|
810
|
+
Max: 101
|
811
|
+
|
801
812
|
# Offense count: 4
|
802
813
|
# Configuration parameters: CountKeywordArgs.
|
803
814
|
Metrics/ParameterLists:
|
@@ -1048,7 +1059,7 @@ RSpec/EmptyLineAfterHook:
|
|
1048
1059
|
RSpec/ExampleLength:
|
1049
1060
|
Max: 85
|
1050
1061
|
|
1051
|
-
# Offense count:
|
1062
|
+
# Offense count: 159
|
1052
1063
|
# This cop supports safe autocorrection (--autocorrect).
|
1053
1064
|
# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples.
|
1054
1065
|
# DisallowedExamples: works
|
@@ -1137,7 +1148,7 @@ RSpec/MessageSpies:
|
|
1137
1148
|
RSpec/MultipleExpectations:
|
1138
1149
|
Max: 19
|
1139
1150
|
|
1140
|
-
# Offense count:
|
1151
|
+
# Offense count: 156
|
1141
1152
|
# Configuration parameters: AllowSubject.
|
1142
1153
|
RSpec/MultipleMemoizedHelpers:
|
1143
1154
|
Max: 15
|
@@ -1162,18 +1173,17 @@ RSpec/NamedSubject:
|
|
1162
1173
|
- 'spec/lib/swagger/rake_swagger_spec.rb'
|
1163
1174
|
- 'spec/lib/swagger/swagger_dsl_spec.rb'
|
1164
1175
|
|
1165
|
-
# Offense count:
|
1176
|
+
# Offense count: 94
|
1166
1177
|
# Configuration parameters: AllowedGroups.
|
1167
1178
|
RSpec/NestedGroups:
|
1168
1179
|
Max: 6
|
1169
1180
|
|
1170
|
-
# Offense count:
|
1181
|
+
# Offense count: 1
|
1171
1182
|
# Configuration parameters: AllowedPatterns.
|
1172
1183
|
# AllowedPatterns: ^expect_, ^assert_
|
1173
1184
|
RSpec/NoExpectationExample:
|
1174
1185
|
Exclude:
|
1175
1186
|
- 'spec/controllers/users_controller_spec.rb'
|
1176
|
-
- 'spec/test_engine/memes_controller_spec.rb'
|
1177
1187
|
|
1178
1188
|
# Offense count: 2
|
1179
1189
|
# This cop supports safe autocorrection (--autocorrect).
|
@@ -1366,7 +1376,7 @@ Style/AndOr:
|
|
1366
1376
|
Exclude:
|
1367
1377
|
- 'lib/apipie/param_description.rb'
|
1368
1378
|
|
1369
|
-
# Offense count:
|
1379
|
+
# Offense count: 18
|
1370
1380
|
# This cop supports safe autocorrection (--autocorrect).
|
1371
1381
|
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
1372
1382
|
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
|
@@ -1522,7 +1532,7 @@ Style/EmptyElse:
|
|
1522
1532
|
- 'lib/apipie/extractor/recorder.rb'
|
1523
1533
|
- 'lib/apipie/extractor/writer.rb'
|
1524
1534
|
|
1525
|
-
# Offense count:
|
1535
|
+
# Offense count: 27
|
1526
1536
|
# This cop supports safe autocorrection (--autocorrect).
|
1527
1537
|
# Configuration parameters: EnforcedStyle.
|
1528
1538
|
# SupportedStyles: compact, expanded
|
@@ -1765,7 +1775,6 @@ Style/Proc:
|
|
1765
1775
|
Style/RaiseArgs:
|
1766
1776
|
Exclude:
|
1767
1777
|
- 'lib/apipie/application.rb'
|
1768
|
-
- 'lib/apipie/dsl_definition.rb'
|
1769
1778
|
- 'lib/apipie/extractor/writer.rb'
|
1770
1779
|
- 'lib/apipie/param_description.rb'
|
1771
1780
|
- 'lib/apipie/see_description.rb'
|
@@ -1917,7 +1926,7 @@ Style/StringConcatenation:
|
|
1917
1926
|
- 'lib/apipie/application.rb'
|
1918
1927
|
- 'lib/apipie/extractor/writer.rb'
|
1919
1928
|
|
1920
|
-
# Offense count:
|
1929
|
+
# Offense count: 1212
|
1921
1930
|
# This cop supports safe autocorrection (--autocorrect).
|
1922
1931
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
1923
1932
|
# SupportedStyles: single_quotes, double_quotes
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
Changelog
|
2
2
|
===========
|
3
3
|
|
4
|
+
## [v1.2.1](https://github.com/Apipie/apipie-rails/tree/v1.2.1) (2023-06-09)
|
5
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.2.0...v1.2.1)
|
6
|
+
* rspec: Fixes deprecated matcher ([#882](https://github.com/Apipie/apipie-rails/pull/882)) (David Wessman)
|
7
|
+
* Fix streaming bug ([#677](https://github.com/Apipie/apipie-rails/pull/677)) (Hunter Braun)
|
8
|
+
* Update README URLs based on HTTP redirects ([#448](https://github.com/Apipie/apipie-rails/pull/448)) (ReadmeCritic)
|
9
|
+
* Swagger: Adds option to skip default tags ([#881](https://github.com/Apipie/apipie-rails/pull/881)) (David Wessman)
|
10
|
+
* Parameter validation: Raises error for all missing ([#886](https://github.com/Apipie/apipie-rails/pull/886)) (David Wessman)
|
11
|
+
|
4
12
|
## [v1.2.0](https://github.com/Apipie/apipie-rails/tree/v1.2.0) (2023-06-03)
|
5
13
|
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.1.0...v1.2.0)
|
6
14
|
* Allow resource_name to be inherited ([#872](https://github.com/Apipie/apipie-rails/pull/872)) (Eric Hankins)
|
data/README.rst
CHANGED
@@ -56,7 +56,7 @@ Run your application and see the result at
|
|
56
56
|
use ``http://localhost:3000/apipie.json``.
|
57
57
|
|
58
58
|
For a more comprehensive getting started guide, see
|
59
|
-
`this demo <https://github.com/
|
59
|
+
`this demo <https://github.com/Apipie/apipie-demo>`_, which includes
|
60
60
|
features such as generating documentation from tests, recording examples etc.
|
61
61
|
|
62
62
|
Screenshots
|
@@ -78,7 +78,7 @@ See `Contributors page <https://github.com/Apipie/apipie-rails/graphs/contribut
|
|
78
78
|
License
|
79
79
|
-------
|
80
80
|
|
81
|
-
Apipie-rails is released under the `MIT License <
|
81
|
+
Apipie-rails is released under the `MIT License <https://opensource.org/licenses/MIT>`_
|
82
82
|
|
83
83
|
===============
|
84
84
|
Documentation
|
@@ -1730,6 +1730,9 @@ There are several configuration parameters that determine the structure of the g
|
|
1730
1730
|
See [https://swagger.io/docs/specification/2-0/authentication/] for details of what values can be specified
|
1731
1731
|
By default, no security is defined.
|
1732
1732
|
|
1733
|
+
``config.generator.swagger.skip_default_tags``
|
1734
|
+
By setting ``false`` (default): The resource name for e.g. ``/pets/{petId}`` will automatically be added as a tag ``pets``.
|
1735
|
+
By setting ``true``: The tags needs to be explicitly added to the resource using the DSL.
|
1733
1736
|
|
1734
1737
|
Known limitations of the current implementation
|
1735
1738
|
-------------------------------------------------
|
@@ -1940,7 +1943,7 @@ Then, you can install dependencies and run the test suite:
|
|
1940
1943
|
Disqus Integration
|
1941
1944
|
====================
|
1942
1945
|
|
1943
|
-
You can setup `Disqus <
|
1946
|
+
You can setup `Disqus <https://disqus.com/>`_ discussion within
|
1944
1947
|
your documentation. Just set the credentials in the Apipie
|
1945
1948
|
configuration:
|
1946
1949
|
|
@@ -241,9 +241,11 @@ module Apipie
|
|
241
241
|
method_params = self.class._apipie_get_method_params(action_name)
|
242
242
|
|
243
243
|
if Apipie.configuration.validate_presence?
|
244
|
-
|
245
|
-
|
246
|
-
|
244
|
+
Validator::BaseValidator.raise_if_missing_params do |missing|
|
245
|
+
method_params.each do |_, param|
|
246
|
+
# check if required parameters are present
|
247
|
+
missing << param if param.required && !params.key?(param.name)
|
248
|
+
end
|
247
249
|
end
|
248
250
|
end
|
249
251
|
|
@@ -285,7 +287,6 @@ module Apipie
|
|
285
287
|
old_method.bind(self).call(*args)
|
286
288
|
end
|
287
289
|
end
|
288
|
-
|
289
290
|
end
|
290
291
|
end
|
291
292
|
|
data/lib/apipie/errors.rb
CHANGED
@@ -24,6 +24,20 @@ module Apipie
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
class ParamMultipleMissing < ParamError
|
28
|
+
attr_accessor :params
|
29
|
+
|
30
|
+
def initialize(params)
|
31
|
+
@params = params
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
params.map do |param|
|
36
|
+
ParamMissing.new(param).to_s
|
37
|
+
end.join("\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
class ParamMissing < DefinedParamError
|
28
42
|
def to_s
|
29
43
|
unless @param.options[:missing_message].nil?
|
data/lib/apipie/extractor.rb
CHANGED
@@ -15,10 +15,13 @@ class Apipie::Railtie
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
app.middleware.use ::Apipie::Extractor::Recorder::Middleware
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
if Apipie.configuration.record
|
20
|
+
app.middleware.use ::Apipie::Extractor::Recorder::Middleware
|
21
|
+
|
22
|
+
ActionController::TestCase.send(:prepend, Apipie::Extractor::Recorder::FunctionalTestRecording)
|
23
|
+
ActionController::TestCase::Behavior.send(:prepend, Apipie::Extractor::Recorder::FunctionalTestRecording)
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -10,7 +10,7 @@ module Apipie
|
|
10
10
|
:json_input_uses_refs, :suppress_warnings, :api_host,
|
11
11
|
:generate_x_computed_id_field, :allow_additional_properties_in_response,
|
12
12
|
:responses_use_refs, :schemes, :security_definitions,
|
13
|
-
:global_security].freeze
|
13
|
+
:global_security, :skip_default_tags].freeze
|
14
14
|
|
15
15
|
attr_accessor(*CONFIG_ATTRIBUTES)
|
16
16
|
|
@@ -43,6 +43,7 @@ module Apipie
|
|
43
43
|
alias include_warning_tags? include_warning_tags
|
44
44
|
alias json_input_uses_refs? json_input_uses_refs
|
45
45
|
alias responses_use_refs? responses_use_refs
|
46
|
+
alias skip_default_tags? skip_default_tags
|
46
47
|
alias generate_x_computed_id_field? generate_x_computed_id_field
|
47
48
|
alias swagger_include_warning_tags? swagger_include_warning_tags
|
48
49
|
alias swagger_json_input_uses_refs? swagger_json_input_uses_refs
|
@@ -61,6 +62,7 @@ module Apipie
|
|
61
62
|
@schemes = [:https]
|
62
63
|
@security_definitions = {}
|
63
64
|
@global_security = []
|
65
|
+
@skip_default_tags = false
|
64
66
|
end
|
65
67
|
|
66
68
|
def self.deprecated_methods
|
@@ -47,9 +47,12 @@ class Apipie::Generator::Swagger::MethodDescription::ApiSchemaService
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def tags
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
tags = if Apipie.configuration.generator.swagger.skip_default_tags?
|
51
|
+
[]
|
52
|
+
else
|
53
|
+
[@method_description.resource._id]
|
54
|
+
end
|
55
|
+
tags + warning_tags + @method_description.tag_list.tags
|
53
56
|
end
|
54
57
|
|
55
58
|
def warning_tags
|
data/lib/apipie/validator.rb
CHANGED
@@ -38,6 +38,16 @@ module Apipie
|
|
38
38
|
return nil
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.raise_if_missing_params
|
42
|
+
missing_params = []
|
43
|
+
yield missing_params
|
44
|
+
if missing_params.size > 1
|
45
|
+
raise ParamMultipleMissing.new(missing_params)
|
46
|
+
elsif missing_params.size == 1
|
47
|
+
raise ParamMissing.new(missing_params.first)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
41
51
|
# check if value is valid
|
42
52
|
def valid?(value)
|
43
53
|
if self.validate(value)
|
@@ -345,14 +355,18 @@ module Apipie
|
|
345
355
|
|
346
356
|
def validate(value)
|
347
357
|
return false if !value.is_a? Hash
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
358
|
+
|
359
|
+
BaseValidator.raise_if_missing_params do |missing|
|
360
|
+
@hash_params&.each do |k, p|
|
361
|
+
if Apipie.configuration.validate_presence?
|
362
|
+
missing << p if p.required && !value.key?(k)
|
363
|
+
end
|
364
|
+
if Apipie.configuration.validate_value?
|
365
|
+
p.validate(value[k]) if value.key?(k)
|
366
|
+
end
|
354
367
|
end
|
355
368
|
end
|
369
|
+
|
356
370
|
return true
|
357
371
|
end
|
358
372
|
|
data/lib/apipie/version.rb
CHANGED
@@ -37,6 +37,7 @@ describe UsersController do
|
|
37
37
|
expect(methods.keys).to include(:update)
|
38
38
|
expect(methods.keys).to include(:two_urls)
|
39
39
|
expect(methods.keys).to include(:action_with_headers)
|
40
|
+
expect(methods.keys).to include(:multiple_required_params)
|
40
41
|
end
|
41
42
|
|
42
43
|
it "should contain info about resource" do
|
@@ -101,6 +102,10 @@ describe UsersController do
|
|
101
102
|
expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
102
103
|
end
|
103
104
|
|
105
|
+
it "should fail if multiple required parameters are missing" do
|
106
|
+
expect { get :multiple_required_params }.to raise_error(Apipie::ParamMultipleMissing, /required_param1.*\n.*required_param2|required_param2.*\n.*required_parameter1/)
|
107
|
+
end
|
108
|
+
|
104
109
|
it "should pass if required parameter has wrong type" do
|
105
110
|
expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
|
106
111
|
expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
|
@@ -246,6 +251,11 @@ describe UsersController do
|
|
246
251
|
post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } }
|
247
252
|
}.to raise_error(Apipie::ParamInvalid, /membership/)
|
248
253
|
|
254
|
+
# Should include both pass and name
|
255
|
+
expect {
|
256
|
+
post :create, :params => { :user => { :membership => "standard" } }
|
257
|
+
}.to raise_error(Apipie::ParamMultipleMissing, /pass.*\n.*name|name.*\n.*pass/)
|
258
|
+
|
249
259
|
expect {
|
250
260
|
post :create, :params => { :user => { :name => "root" } }
|
251
261
|
}.to raise_error(Apipie::ParamMissing, /pass/)
|
@@ -301,4 +301,10 @@ class UsersController < ApplicationController
|
|
301
301
|
header :HeaderNameWithDefaultValue, 'Header with default value', required: true, default: 'default value'
|
302
302
|
def action_with_headers
|
303
303
|
end
|
304
|
+
|
305
|
+
api :GET, '/users/multiple_required_params'
|
306
|
+
param :required_param1, String, required: true
|
307
|
+
param :required_param2, String, required: true
|
308
|
+
def multiple_required_params
|
309
|
+
end
|
304
310
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -64,6 +64,19 @@ describe Apipie::Generator::Swagger::MethodDescription::ApiSchemaService do
|
|
64
64
|
it { is_expected.to include(*tags) }
|
65
65
|
end
|
66
66
|
|
67
|
+
context 'when Apipie.configuration.generator.swagger.skip_default_tags is enabled' do
|
68
|
+
before { Apipie.configuration.generator.swagger.skip_default_tags = true }
|
69
|
+
after { Apipie.configuration.generator.swagger.skip_default_tags = false }
|
70
|
+
|
71
|
+
it { is_expected.to be_empty }
|
72
|
+
|
73
|
+
context 'when tags are available' do
|
74
|
+
let(:tags) { ['Tag 1', 'Tag 2'] }
|
75
|
+
|
76
|
+
it { is_expected.to eq(tags) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
67
80
|
context 'when Apipie.configuration.generator.swagger.include_warning_tags is enabled' do
|
68
81
|
before { Apipie.configuration.generator.swagger.include_warning_tags = true }
|
69
82
|
|
@@ -4,7 +4,7 @@ describe TestEngine::MemesController do
|
|
4
4
|
|
5
5
|
describe "#index" do
|
6
6
|
it "should have the full mounted path of engine" do
|
7
|
-
Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path].
|
7
|
+
expect(Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path]).to eq("/test/memes")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
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: 1.2.
|
4
|
+
version: 1.2.1
|
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: 2023-06-
|
12
|
+
date: 2023-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|