apipie-rails 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/.rubocop_todo.yml +22 -28
- data/CHANGELOG.md +13 -0
- data/README.rst +6 -3
- data/lib/apipie/dsl_definition.rb +7 -8
- data/lib/apipie/errors.rb +1 -1
- data/lib/apipie/extractor/collector.rb +1 -1
- data/lib/apipie/extractor/recorder.rb +1 -1
- data/lib/apipie/extractor/writer.rb +1 -1
- data/lib/apipie/generator/swagger/config.rb +1 -1
- data/lib/apipie/generator/swagger/method_description/parameters_service.rb +1 -1
- data/lib/apipie/generator/swagger/param_description/builder.rb +10 -1
- data/lib/apipie/generator/swagger/param_description/type.rb +15 -2
- data/lib/apipie/generator/swagger/resource_description_collection.rb +2 -2
- data/lib/apipie/response_description_adapter.rb +2 -2
- data/lib/apipie/static_dispatcher.rb +7 -1
- data/lib/apipie/version.rb +1 -1
- data/lib/tasks/apipie.rake +3 -3
- data/spec/dummy/app/controllers/pets_controller.rb +1 -1
- data/spec/lib/apipie/apipies_controller_spec.rb +1 -2
- data/spec/lib/apipie/extractor_spec.rb +1 -1
- data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +6 -6
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +49 -11
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +6 -1
- data/spec/lib/apipie/swagger_generator_spec.rb +2 -2
- data/spec/lib/swagger/rake_swagger_spec.rb +6 -1
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51731d3325c2241c36c5cf0e19062525d982c2b98fa0d5e0b76a5ba8625ddacd
|
4
|
+
data.tar.gz: 45db678d7324e76064a8d8a632ac5e72048d85ba7d32329168202bd48723219b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dc8a4c009d6dc3daee4ac98d2509d832edbf2dc8d9ec08a9f9205d9ef7614c0480ed60132f33116c6a09dd9a0ec3b056c60fc52e3e6a61b6cf67eb913985619
|
7
|
+
data.tar.gz: 4621285ca2c82670ec63c0b5a240b0d6024d37e445c724a243782e492c5c6be65091187ee07ef874ff7d0320d68109577277d885b8ea4a28e2aed8c2a94490cf
|
data/.github/workflows/build.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config --exclude-limit
|
3
|
-
# on 2023-
|
2
|
+
# `rubocop --auto-gen-config --exclude-limit 200`
|
3
|
+
# on 2023-10-11 12:02:42 UTC using RuboCop version 1.57.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: 59
|
122
122
|
# This cop supports safe autocorrection (--autocorrect).
|
123
123
|
Layout/EmptyLineAfterGuardClause:
|
124
124
|
Exclude:
|
@@ -140,7 +140,7 @@ Layout/EmptyLineAfterGuardClause:
|
|
140
140
|
|
141
141
|
# Offense count: 13
|
142
142
|
# This cop supports safe autocorrection (--autocorrect).
|
143
|
-
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
|
143
|
+
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
|
144
144
|
Layout/EmptyLineBetweenDefs:
|
145
145
|
Exclude:
|
146
146
|
- 'app/controllers/apipie/apipies_controller.rb'
|
@@ -597,14 +597,13 @@ Layout/SpaceInsideParens:
|
|
597
597
|
- 'spec/lib/apipie/method_description/apis_service_spec.rb'
|
598
598
|
- 'spec/lib/swagger/swagger_dsl_spec.rb'
|
599
599
|
|
600
|
-
# Offense count:
|
600
|
+
# Offense count: 14
|
601
601
|
# This cop supports safe autocorrection (--autocorrect).
|
602
602
|
# Configuration parameters: EnforcedStyle.
|
603
603
|
# SupportedStyles: final_newline, final_blank_line
|
604
604
|
Layout/TrailingEmptyLines:
|
605
605
|
Exclude:
|
606
606
|
- 'Rakefile'
|
607
|
-
- 'lib/apipie/extractor/collector.rb'
|
608
607
|
- 'lib/apipie/method_description/apis_service.rb'
|
609
608
|
- 'lib/apipie/rspec/response_validation_helper.rb'
|
610
609
|
- 'spec/controllers/concerns_controller_spec.rb'
|
@@ -778,23 +777,17 @@ Lint/Void:
|
|
778
777
|
Exclude:
|
779
778
|
- 'spec/controllers/users_controller_spec.rb'
|
780
779
|
|
781
|
-
# Offense count:
|
780
|
+
# Offense count: 60
|
782
781
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
783
782
|
Metrics/AbcSize:
|
784
783
|
Max: 96
|
785
784
|
|
786
|
-
# Offense count:
|
787
|
-
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
788
|
-
# AllowedMethods: refine
|
789
|
-
Metrics/BlockLength:
|
790
|
-
Max: 26
|
791
|
-
|
792
|
-
# Offense count: 4
|
785
|
+
# Offense count: 3
|
793
786
|
# Configuration parameters: CountBlocks.
|
794
787
|
Metrics/BlockNesting:
|
795
788
|
Max: 4
|
796
789
|
|
797
|
-
# Offense count:
|
790
|
+
# Offense count: 25
|
798
791
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
799
792
|
Metrics/CyclomaticComplexity:
|
800
793
|
Max: 24
|
@@ -807,7 +800,7 @@ Metrics/MethodLength:
|
|
807
800
|
# Offense count: 1
|
808
801
|
# Configuration parameters: CountComments, CountAsOne.
|
809
802
|
Metrics/ModuleLength:
|
810
|
-
Max:
|
803
|
+
Max: 119
|
811
804
|
|
812
805
|
# Offense count: 4
|
813
806
|
# Configuration parameters: CountKeywordArgs.
|
@@ -815,7 +808,7 @@ Metrics/ParameterLists:
|
|
815
808
|
MaxOptionalParameters: 5
|
816
809
|
Max: 6
|
817
810
|
|
818
|
-
# Offense count:
|
811
|
+
# Offense count: 21
|
819
812
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
820
813
|
Metrics/PerceivedComplexity:
|
821
814
|
Max: 25
|
@@ -961,7 +954,7 @@ RSpec/Be:
|
|
961
954
|
- 'spec/controllers/concerns_controller_spec.rb'
|
962
955
|
- 'spec/controllers/users_controller_spec.rb'
|
963
956
|
|
964
|
-
# Offense count:
|
957
|
+
# Offense count: 60
|
965
958
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
966
959
|
RSpec/BeEq:
|
967
960
|
Exclude:
|
@@ -1054,7 +1047,7 @@ RSpec/EmptyLineAfterHook:
|
|
1054
1047
|
Exclude:
|
1055
1048
|
- 'spec/lib/apipie/apipies_controller_spec.rb'
|
1056
1049
|
|
1057
|
-
# Offense count:
|
1050
|
+
# Offense count: 52
|
1058
1051
|
# Configuration parameters: CountAsOne.
|
1059
1052
|
RSpec/ExampleLength:
|
1060
1053
|
Max: 85
|
@@ -1148,12 +1141,12 @@ RSpec/MessageSpies:
|
|
1148
1141
|
RSpec/MultipleExpectations:
|
1149
1142
|
Max: 19
|
1150
1143
|
|
1151
|
-
# Offense count:
|
1144
|
+
# Offense count: 160
|
1152
1145
|
# Configuration parameters: AllowSubject.
|
1153
1146
|
RSpec/MultipleMemoizedHelpers:
|
1154
1147
|
Max: 15
|
1155
1148
|
|
1156
|
-
# Offense count:
|
1149
|
+
# Offense count: 85
|
1157
1150
|
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
1158
1151
|
# SupportedStyles: always, named_only
|
1159
1152
|
RSpec/NamedSubject:
|
@@ -1173,7 +1166,7 @@ RSpec/NamedSubject:
|
|
1173
1166
|
- 'spec/lib/swagger/rake_swagger_spec.rb'
|
1174
1167
|
- 'spec/lib/swagger/swagger_dsl_spec.rb'
|
1175
1168
|
|
1176
|
-
# Offense count:
|
1169
|
+
# Offense count: 96
|
1177
1170
|
# Configuration parameters: AllowedGroups.
|
1178
1171
|
RSpec/NestedGroups:
|
1179
1172
|
Max: 6
|
@@ -1235,14 +1228,14 @@ RSpec/StubbedMock:
|
|
1235
1228
|
- 'spec/lib/apipie/extractor/writer_spec.rb'
|
1236
1229
|
- 'spec/lib/apipie/param_description_spec.rb'
|
1237
1230
|
|
1238
|
-
# Offense count:
|
1231
|
+
# Offense count: 6
|
1239
1232
|
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
|
1240
1233
|
RSpec/VerifiedDoubles:
|
1241
1234
|
Exclude:
|
1242
1235
|
- 'spec/lib/apipie/apipies_controller_spec.rb'
|
1236
|
+
- 'spec/lib/apipie/extractor/recorder_spec.rb'
|
1243
1237
|
- 'spec/lib/apipie/extractor/writer_spec.rb'
|
1244
1238
|
- 'spec/lib/validators/array_validator_spec.rb'
|
1245
|
-
- 'spec/lib/apipie/extractor/recorder_spec.rb'
|
1246
1239
|
|
1247
1240
|
# Offense count: 1
|
1248
1241
|
RSpec/VoidExpect:
|
@@ -1266,6 +1259,7 @@ Rails/Delegate:
|
|
1266
1259
|
- 'lib/apipie/response_description_adapter.rb'
|
1267
1260
|
|
1268
1261
|
# Offense count: 24
|
1262
|
+
# This cop supports safe autocorrection (--autocorrect).
|
1269
1263
|
# Configuration parameters: EnforcedStyle.
|
1270
1264
|
# SupportedStyles: slashes, arguments
|
1271
1265
|
Rails/FilePath:
|
@@ -1455,7 +1449,7 @@ Style/ClassCheck:
|
|
1455
1449
|
- 'lib/apipie/validator.rb'
|
1456
1450
|
|
1457
1451
|
# Offense count: 2
|
1458
|
-
# This cop supports
|
1452
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
1459
1453
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
1460
1454
|
# AllowedMethods: ==, equal?, eql?
|
1461
1455
|
Style/ClassEqualityComparison:
|
@@ -1747,7 +1741,7 @@ Style/ParallelAssignment:
|
|
1747
1741
|
- 'lib/apipie/extractor.rb'
|
1748
1742
|
- 'lib/apipie/extractor/recorder.rb'
|
1749
1743
|
|
1750
|
-
# Offense count:
|
1744
|
+
# Offense count: 8
|
1751
1745
|
# This cop supports safe autocorrection (--autocorrect).
|
1752
1746
|
# Configuration parameters: PreferredDelimiters.
|
1753
1747
|
Style/PercentLiteralDelimiters:
|
@@ -1826,7 +1820,7 @@ Style/RedundantPercentQ:
|
|
1826
1820
|
Exclude:
|
1827
1821
|
- 'apipie-rails.gemspec'
|
1828
1822
|
|
1829
|
-
# Offense count:
|
1823
|
+
# Offense count: 29
|
1830
1824
|
# This cop supports safe autocorrection (--autocorrect).
|
1831
1825
|
# Configuration parameters: AllowMultipleReturnValues.
|
1832
1826
|
Style/RedundantReturn:
|
@@ -1927,7 +1921,7 @@ Style/StringConcatenation:
|
|
1927
1921
|
- 'lib/apipie/application.rb'
|
1928
1922
|
- 'lib/apipie/extractor/writer.rb'
|
1929
1923
|
|
1930
|
-
# Offense count:
|
1924
|
+
# Offense count: 1214
|
1931
1925
|
# This cop supports safe autocorrection (--autocorrect).
|
1932
1926
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
1933
1927
|
# SupportedStyles: single_quotes, double_quotes
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
Changelog
|
2
2
|
===========
|
3
3
|
|
4
|
+
## [v1.3.0](https://github.com/Apipie/apipie-rails/tree/v1.3.0) (2023-12-19)
|
5
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.2.3...v1.3.0)
|
6
|
+
* rubocop fixes ([#897](https://github.com/Apipie/apipie-rails/pull/897)) (Mathieu Jobin)
|
7
|
+
* Fix usage of deprecated Rack::File in Rack 3.0 ([#896](https://github.com/Apipie/apipie-rails/pull/896)) (James Dean Shepherd)
|
8
|
+
* add rails 7.1 to the build matrix ([#898](https://github.com/Apipie/apipie-rails/pull/898)) (Mathieu Jobin)
|
9
|
+
* super small typo fix ([#900](https://github.com/Apipie/apipie-rails/pull/900)) (Eric Pugh)
|
10
|
+
* support for property example ([#901](https://github.com/Apipie/apipie-rails/pull/901)) (Chien-Wei Huang (Michael))
|
11
|
+
* Use array items type from validator ([#904](https://github.com/Apipie/apipie-rails/pull/)) (Panos Dalitsouris)
|
12
|
+
|
13
|
+
## [v1.2.3](https://github.com/Apipie/apipie-rails/tree/v1.2.3) (2023-10-11)
|
14
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.2.2...v1.2.3)
|
15
|
+
* Fix param: Consider default_value: nil as valid config ([#894](https://github.com/Apipie/apipie-rails/pull/894)) (davidwessman)
|
16
|
+
|
4
17
|
## [v1.2.2](https://github.com/Apipie/apipie-rails/tree/v1.2.2) (2023-07-18)
|
5
18
|
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.2.1...v1.2.2)
|
6
19
|
* Fixed Swagger warnings for properties ([#892](https://github.com/Apipie/apipie-rails/pull/892)) (shev-vadim-net)
|
data/README.rst
CHANGED
@@ -317,6 +317,9 @@ desc
|
|
317
317
|
required
|
318
318
|
Set this true/false to make it required/optional. Default is optional
|
319
319
|
|
320
|
+
example
|
321
|
+
Provide the example for this parameter.
|
322
|
+
|
320
323
|
allow_nil
|
321
324
|
Setting this to true means that ``nil`` can be passed.
|
322
325
|
|
@@ -349,8 +352,8 @@ Example:
|
|
349
352
|
.. code:: ruby
|
350
353
|
|
351
354
|
param :user, Hash, :desc => "User info" do
|
352
|
-
param :username, String, :desc => "Username for login", :required => true
|
353
|
-
param :password, String, :desc => "Password for login", :required => true
|
355
|
+
param :username, String, :desc => "Username for login", :required => true, :example => 'John'
|
356
|
+
param :password, String, :desc => "Password for login", :required => true, :example => '1234567'
|
354
357
|
param :membership, ["standard","premium"], :desc => "User membership"
|
355
358
|
param :admin_override, String, :desc => "Not shown in documentation", :show => false
|
356
359
|
param :ip_address, String, :desc => "IP address", :required => true, :missing_message => lambda { I18n.t("ip_address.required") }
|
@@ -1030,7 +1033,7 @@ layout
|
|
1030
1033
|
|
1031
1034
|
ignored
|
1032
1035
|
An array of controller names (strings) (might include actions as well)
|
1033
|
-
to be ignored when
|
1036
|
+
to be ignored when generating the documentation
|
1034
1037
|
e.g. ``%w[Api::CommentsController Api::PostsController#post]``
|
1035
1038
|
|
1036
1039
|
namespaced_resources
|
@@ -242,7 +242,7 @@ module Apipie
|
|
242
242
|
|
243
243
|
if Apipie.configuration.validate_presence?
|
244
244
|
Validator::BaseValidator.raise_if_missing_params do |missing|
|
245
|
-
method_params.
|
245
|
+
method_params.each_value do |param|
|
246
246
|
# check if required parameters are present
|
247
247
|
missing << param if param.required && !params.key?(param.name)
|
248
248
|
end
|
@@ -250,7 +250,7 @@ module Apipie
|
|
250
250
|
end
|
251
251
|
|
252
252
|
if Apipie.configuration.validate_value?
|
253
|
-
method_params.
|
253
|
+
method_params.each_value do |param|
|
254
254
|
# params validations
|
255
255
|
param.validate(params[:"#{param.name}"]) if params.key?(param.name)
|
256
256
|
end
|
@@ -267,12 +267,11 @@ module Apipie
|
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
end
|
270
|
+
return unless Apipie.configuration.process_value?
|
271
|
+
@api_params ||= {}
|
272
|
+
method_params.each_value do |param|
|
273
|
+
# params processing
|
274
|
+
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
|
276
275
|
end
|
277
276
|
end
|
278
277
|
end
|
data/lib/apipie/errors.rb
CHANGED
@@ -90,7 +90,7 @@ module Apipie
|
|
90
90
|
lines << '' << %{... contents of "#{attrs[:name]}" ...}
|
91
91
|
else
|
92
92
|
# Look for subelements that contain a part.
|
93
|
-
attrs.
|
93
|
+
attrs.each_value { |v| v.is_a?(Hash) and reformat_hash(boundary, v, lines) }
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -80,7 +80,7 @@ module Apipie
|
|
80
80
|
|
81
81
|
def write_docs
|
82
82
|
descriptions = @collector.finalize_descriptions
|
83
|
-
descriptions.
|
83
|
+
descriptions.each_value do |desc|
|
84
84
|
if desc[:api].empty?
|
85
85
|
logger.warn("REST_API: Couldn't find any path for #{desc_to_s(desc)}")
|
86
86
|
next
|
@@ -96,7 +96,7 @@ class Apipie::Generator::Swagger::MethodDescription::ParametersService
|
|
96
96
|
def path_param_descriptions
|
97
97
|
@path_param_descriptions ||= all_params
|
98
98
|
.select { |k, _| @path.param?(k) }
|
99
|
-
.
|
99
|
+
.each_value { |desc| desc.required = true }
|
100
100
|
.values
|
101
101
|
end
|
102
102
|
|
@@ -53,6 +53,7 @@ class Apipie::Generator::Swagger::ParamDescription::Builder
|
|
53
53
|
|
54
54
|
definition.merge!(for_default)
|
55
55
|
definition.merge!(for_required)
|
56
|
+
definition.merge!(for_example)
|
56
57
|
definition.merge!(@description.to_hash) if @description.present?
|
57
58
|
|
58
59
|
warn_optional_without_default_value(definition)
|
@@ -71,13 +72,21 @@ class Apipie::Generator::Swagger::ParamDescription::Builder
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def for_default
|
74
|
-
return {}
|
75
|
+
return {} unless @param_description.options.key?(:default_value)
|
75
76
|
|
76
77
|
{
|
77
78
|
default: @param_description.options[:default_value],
|
78
79
|
}
|
79
80
|
end
|
80
81
|
|
82
|
+
def for_example
|
83
|
+
return {} unless @param_description.options.key?(:example)
|
84
|
+
|
85
|
+
{
|
86
|
+
example: @param_description.options[:example],
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
81
90
|
def required?
|
82
91
|
required_from_path? || @param_description.required
|
83
92
|
end
|
@@ -56,7 +56,7 @@ class Apipie::Generator::Swagger::ParamDescription::Type
|
|
56
56
|
|
57
57
|
def for_array_type
|
58
58
|
validator_opts = validator.param_description.options
|
59
|
-
items_type = validator_opts[:of]
|
59
|
+
items_type = (validator_opts[:of] || validator_opts[:array_of]).to_s
|
60
60
|
|
61
61
|
if items_type == 'Hash' && params_in_body_use_reference?
|
62
62
|
reference_name = Apipie::Generator::Swagger::OperationId.
|
@@ -67,7 +67,7 @@ class Apipie::Generator::Swagger::ParamDescription::Type
|
|
67
67
|
'$ref' => reference_name
|
68
68
|
}
|
69
69
|
else
|
70
|
-
items = { type:
|
70
|
+
items = { type: array_items_type(items_type).to_s }
|
71
71
|
end
|
72
72
|
|
73
73
|
enum = @param_description.options[:in]
|
@@ -80,6 +80,19 @@ class Apipie::Generator::Swagger::ParamDescription::Type
|
|
80
80
|
}
|
81
81
|
end
|
82
82
|
|
83
|
+
# @param [String] items_type
|
84
|
+
#
|
85
|
+
# @return [Apipie::Generator::Swagger::Type]
|
86
|
+
def array_items_type(items_type)
|
87
|
+
type = Apipie::Generator::Swagger::TypeExtractor::TYPES[items_type.downcase.to_sym]
|
88
|
+
|
89
|
+
if type == 'object' || type.blank?
|
90
|
+
Apipie::Generator::Swagger::TypeExtractor::TYPES[:string]
|
91
|
+
else
|
92
|
+
type
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
83
96
|
def for_enum_type
|
84
97
|
{
|
85
98
|
type: 'string',
|
@@ -19,9 +19,9 @@ class Apipie::Generator::Swagger::ResourceDescriptionsCollection
|
|
19
19
|
|
20
20
|
if method_name.present?
|
21
21
|
resources = resources.select do |resource_description|
|
22
|
-
resource_description._methods.
|
22
|
+
resource_description._methods.any? do |method_description_name, _|
|
23
23
|
method_description_name == method_name
|
24
|
-
end
|
24
|
+
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -57,7 +57,7 @@ module Apipie
|
|
57
57
|
attr_reader :expected_type
|
58
58
|
|
59
59
|
def [](key)
|
60
|
-
|
60
|
+
self.send(key) if self.respond_to?(key.to_s)
|
61
61
|
end
|
62
62
|
|
63
63
|
def initialize(expected_type, enum_values = nil, sub_properties = nil)
|
@@ -102,7 +102,7 @@ module Apipie
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def [](key)
|
105
|
-
|
105
|
+
self.send(key) if self.respond_to?(key.to_s)
|
106
106
|
end
|
107
107
|
|
108
108
|
def add_sub_property(prop_desc)
|
@@ -4,7 +4,13 @@ module Apipie
|
|
4
4
|
def initialize(root)
|
5
5
|
@root = root.chomp('/')
|
6
6
|
@compiled_root = /^#{Regexp.escape(root)}/
|
7
|
-
@file_server = ::Rack::
|
7
|
+
@file_server = if defined?(::Rack::Files)
|
8
|
+
::Rack::Files.new(@root)
|
9
|
+
else
|
10
|
+
# Deprecated in Rack 3.0, kept
|
11
|
+
# for backward compatibility
|
12
|
+
::Rack::File.new(@root)
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
def match?(path)
|
data/lib/apipie/version.rb
CHANGED
data/lib/tasks/apipie.rake
CHANGED
@@ -186,11 +186,11 @@ namespace :apipie do
|
|
186
186
|
av = renderer
|
187
187
|
File.open(file_name, "w") do |f|
|
188
188
|
variables.each do |var, val|
|
189
|
-
av.instance_variable_set("@#{var}", val)
|
189
|
+
av.instance_variable_set(:"@#{var}", val)
|
190
190
|
end
|
191
191
|
f.write av.render(
|
192
192
|
:template => "#{template}",
|
193
|
-
:layout =>
|
193
|
+
:layout => layout && "apipie/#{layout}")
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -259,7 +259,7 @@ namespace :apipie do
|
|
259
259
|
end
|
260
260
|
|
261
261
|
def generate_resource_pages(version, file_base, doc, include_json = false, lang = nil)
|
262
|
-
doc[:docs][:resources].
|
262
|
+
doc[:docs][:resources].each_key do |resource_id|
|
263
263
|
resource_file_base = File.join(file_base, resource_id.to_s)
|
264
264
|
FileUtils.mkdir_p(File.dirname(resource_file_base)) unless File.exist?(File.dirname(resource_file_base))
|
265
265
|
|
@@ -23,7 +23,7 @@ class PetsController < ApplicationController
|
|
23
23
|
#-----------------------------------------------------------
|
24
24
|
api :GET, "/pets/:id/as_properties", "Get a pet record"
|
25
25
|
returns :code => 200 do
|
26
|
-
property :pet_name, String, :desc => "Name of pet", :required => false
|
26
|
+
property :pet_name, String, :desc => "Name of pet", :required => false, :example => 'mypet'
|
27
27
|
property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # required by default, because this is a 'property'
|
28
28
|
end
|
29
29
|
returns :code => 404 do
|
@@ -57,8 +57,7 @@ describe Apipie::ApipiesController, type: :controller do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "succeeds on method details with the default language" do
|
60
|
-
allow(Apipie.configuration).to
|
61
|
-
allow(Apipie.configuration).to receive(:languages).and_return([])
|
60
|
+
allow(Apipie.configuration).to receive_messages(default_locale: "en", languages: [])
|
62
61
|
|
63
62
|
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.en" }
|
64
63
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Apipie::Extractor do
|
4
4
|
it 'handles routes without (.:format)' do
|
5
|
-
Apipie::Extractor.apis_from_routes.
|
5
|
+
Apipie::Extractor.apis_from_routes.each_value do |apis|
|
6
6
|
apis.each { |api| expect(api[:path]).not_to be_nil }
|
7
7
|
end
|
8
8
|
end
|
@@ -19,8 +19,8 @@ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
|
|
19
19
|
|
20
20
|
let(:response_description_dsl) do
|
21
21
|
proc do
|
22
|
-
property :a_number, Integer
|
23
|
-
property :an_optional_number, Integer, required: false
|
22
|
+
property :a_number, Integer, example: 1
|
23
|
+
property :an_optional_number, Integer, required: false, example: 2
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -56,10 +56,10 @@ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
|
|
56
56
|
expect(properties).to eq(
|
57
57
|
{
|
58
58
|
a_number: {
|
59
|
-
type: 'number', required: true
|
59
|
+
type: 'number', required: true, example: 1
|
60
60
|
},
|
61
61
|
an_optional_number: {
|
62
|
-
type: 'number'
|
62
|
+
type: 'number', example: 2
|
63
63
|
}
|
64
64
|
}
|
65
65
|
)
|
@@ -72,10 +72,10 @@ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
|
|
72
72
|
expect(properties).to eq(
|
73
73
|
{
|
74
74
|
a_number: {
|
75
|
-
type: %w[number null], required: true
|
75
|
+
type: %w[number null], required: true, example: 1
|
76
76
|
},
|
77
77
|
an_optional_number: {
|
78
|
-
type: %w[number null]
|
78
|
+
type: %w[number null], example: 2
|
79
79
|
}
|
80
80
|
}
|
81
81
|
)
|
@@ -102,23 +102,49 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
|
|
102
102
|
|
103
103
|
subject { generated_block }
|
104
104
|
|
105
|
-
context 'when is
|
106
|
-
let(:base_param_description_options) { { required:
|
105
|
+
context 'when required is true' do
|
106
|
+
let(:base_param_description_options) { { required: true } }
|
107
|
+
|
108
|
+
it 'does not output an option without default warning' do
|
109
|
+
expect { subject }.not_to output(
|
110
|
+
/is optional but default value is not specified/
|
111
|
+
).to_stderr
|
112
|
+
end
|
113
|
+
end
|
107
114
|
|
108
|
-
|
109
|
-
|
115
|
+
context 'when required is false' do
|
116
|
+
context 'when default_value is nil' do
|
117
|
+
let(:base_param_description_options) do
|
118
|
+
{ required: false, default_value: nil }
|
119
|
+
end
|
110
120
|
|
111
|
-
it '
|
112
|
-
expect { subject }.
|
121
|
+
it 'will not warn' do
|
122
|
+
expect { subject }.not_to output(
|
123
|
+
/is optional but default value is not specified/
|
124
|
+
).to_stderr
|
113
125
|
end
|
114
126
|
end
|
115
|
-
end
|
116
127
|
|
117
|
-
|
118
|
-
|
128
|
+
context 'when default_value is 123' do
|
129
|
+
let(:base_param_description_options) do
|
130
|
+
{ required: false, default_value: 123 }
|
131
|
+
end
|
119
132
|
|
120
|
-
|
121
|
-
|
133
|
+
it 'will not warn' do
|
134
|
+
expect { subject }.not_to output(
|
135
|
+
/is optional but default value is not specified/
|
136
|
+
).to_stderr
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'default_value not given' do
|
141
|
+
let(:base_param_description_options) { { required: false } }
|
142
|
+
|
143
|
+
it 'warns' do
|
144
|
+
expect { subject }.to output(
|
145
|
+
/is optional but default value is not specified/
|
146
|
+
).to_stderr
|
147
|
+
end
|
122
148
|
end
|
123
149
|
end
|
124
150
|
end
|
@@ -174,4 +200,16 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
|
|
174
200
|
it { is_expected.to be_present }
|
175
201
|
end
|
176
202
|
end
|
203
|
+
|
204
|
+
describe 'example' do
|
205
|
+
subject { generated_block[:example] }
|
206
|
+
|
207
|
+
it { is_expected.to be_blank }
|
208
|
+
|
209
|
+
context 'when example is assigned' do
|
210
|
+
let(:base_param_description_options) { { example: 'example' } }
|
211
|
+
|
212
|
+
it { is_expected.to eq('example') }
|
213
|
+
end
|
214
|
+
end
|
177
215
|
end
|
@@ -115,10 +115,15 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
|
|
115
115
|
it 'returns the reference' do
|
116
116
|
expect(subject).to eq({ '$ref' => reference })
|
117
117
|
end
|
118
|
-
|
119
118
|
end
|
120
119
|
end
|
121
120
|
|
121
|
+
context 'of a Swagger type' do
|
122
|
+
let(:validator_options) { { of: Integer } }
|
123
|
+
|
124
|
+
it { is_expected.to eq({ type: 'integer' }) }
|
125
|
+
end
|
126
|
+
|
122
127
|
describe 'enum' do
|
123
128
|
subject { items[:enum] }
|
124
129
|
|
@@ -7,7 +7,7 @@ describe Apipie::SwaggerGenerator do
|
|
7
7
|
|
8
8
|
let(:response_description_dsl) do
|
9
9
|
proc do
|
10
|
-
property :a_number, Integer
|
10
|
+
property :a_number, Integer, example: 1
|
11
11
|
property :an_optional_number, Integer, required: false
|
12
12
|
end
|
13
13
|
end
|
@@ -61,7 +61,7 @@ describe Apipie::SwaggerGenerator do
|
|
61
61
|
expect(properties).to eq(
|
62
62
|
{
|
63
63
|
a_number: {
|
64
|
-
type: 'number', required: true
|
64
|
+
type: 'number', required: true, example: 1
|
65
65
|
},
|
66
66
|
an_optional_number: {
|
67
67
|
type: 'number'
|
@@ -82,6 +82,10 @@ describe 'rake tasks' do
|
|
82
82
|
expect(param[field]).to eq(value)
|
83
83
|
end
|
84
84
|
|
85
|
+
def expect_response_params_def(http_method, path, response_code, param_name, field, value)
|
86
|
+
param = apidoc_swagger["paths"][path][http_method]["responses"][response_code.to_s]["schema"]["properties"][param_name]
|
87
|
+
expect(param[field]).to eq(value)
|
88
|
+
end
|
85
89
|
|
86
90
|
describe 'apipie:static_swagger_json[development,json,_tmp]' do
|
87
91
|
it "generates static swagger files for the default version of apipie docs" do
|
@@ -105,6 +109,7 @@ describe 'rake tasks' do
|
|
105
109
|
%w[finance operations sales marketing HR])
|
106
110
|
|
107
111
|
expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
|
112
|
+
expect_response_params_def("get", "/pets/{id}/as_properties", 200, "pet_name", "example", "mypet")
|
108
113
|
end
|
109
114
|
|
110
115
|
it "generates a valid swagger file" do
|
@@ -146,7 +151,7 @@ describe 'rake tasks' do
|
|
146
151
|
|
147
152
|
describe 'apipie:did_swagger_change[development,form_data,_tmp]' do
|
148
153
|
it "keeps a reference file" do
|
149
|
-
expect(Pathname(ref_output).children.count).to eq(2)
|
154
|
+
expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
|
150
155
|
end
|
151
156
|
end
|
152
157
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 1.3.0
|
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-
|
12
|
+
date: 2023-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -472,7 +472,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
472
|
- !ruby/object:Gem::Version
|
473
473
|
version: '0'
|
474
474
|
requirements: []
|
475
|
-
rubygems_version: 3.4.
|
475
|
+
rubygems_version: 3.4.22
|
476
476
|
signing_key:
|
477
477
|
specification_version: 4
|
478
478
|
summary: Rails REST API documentation tool
|