apipie-rails 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 589dc3b1a0a39f1b2fae7fa811e27969b3f8de5c6eb2e187ca1c61e3d77edd5a
4
- data.tar.gz: b99b476c03dadcce53f6fe2c4e712a9e6a30960762de9fead0b755ef3d6ebee2
3
+ metadata.gz: 51731d3325c2241c36c5cf0e19062525d982c2b98fa0d5e0b76a5ba8625ddacd
4
+ data.tar.gz: 45db678d7324e76064a8d8a632ac5e72048d85ba7d32329168202bd48723219b
5
5
  SHA512:
6
- metadata.gz: 765673e5c7ca984ad30d1d1f815f583f92d3f9dfdd595228c74e73b9fac3fd0e60260f65e6f9e8eb6b19f24de1f8b814cb917f38bf312ec8a30c52b8e1eea901
7
- data.tar.gz: 3afe26c57541633e04017eb022f4f526ed08c22b4d1a2ad7ca44364a49ce88f5e868e1651a468e5d0707325bf4abdc2fc15c1bbc8bebae0bc288b795ac6f0848
6
+ metadata.gz: 1dc8a4c009d6dc3daee4ac98d2509d832edbf2dc8d9ec08a9f9205d9ef7614c0480ed60132f33116c6a09dd9a0ec3b056c60fc52e3e6a61b6cf67eb913985619
7
+ data.tar.gz: 4621285ca2c82670ec63c0b5a240b0d6024d37e445c724a243782e492c5c6be65091187ee07ef874ff7d0320d68109577277d885b8ea4a28e2aed8c2a94490cf
@@ -8,7 +8,7 @@ jobs:
8
8
  strategy:
9
9
  fail-fast: false
10
10
  matrix:
11
- rails: ["7.0", "6.1", "6.0"]
11
+ rails: ["7.1", "7.0", "6.1", "6.0"]
12
12
  ruby: ["3.2.2", "3.1.4", "3.0.6", "2.7.8"]
13
13
  include:
14
14
  - rails: "5.2"
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
- # `rubocop --auto-gen-config --exclude-limit 180`
3
- # on 2023-06-09 05:29:05 UTC using RuboCop version 1.52.0.
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: 58
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: 15
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: 58
780
+ # Offense count: 60
782
781
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
783
782
  Metrics/AbcSize:
784
783
  Max: 96
785
784
 
786
- # Offense count: 1
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: 24
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: 101
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: 20
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: 59
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: 51
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: 156
1144
+ # Offense count: 160
1152
1145
  # Configuration parameters: AllowSubject.
1153
1146
  RSpec/MultipleMemoizedHelpers:
1154
1147
  Max: 15
1155
1148
 
1156
- # Offense count: 82
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: 94
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: 5
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 safe autocorrection (--autocorrect).
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: 6
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: 27
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: 1212
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,15 @@
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
+
4
13
  ## [v1.2.3](https://github.com/Apipie/apipie-rails/tree/v1.2.3) (2023-10-11)
5
14
  [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v1.2.2...v1.2.3)
6
15
  * Fix param: Consider default_value: nil as valid config ([#894](https://github.com/Apipie/apipie-rails/pull/894)) (davidwessman)
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 generationg the documentation
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.each do |_, param|
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.each do |_, param|
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
- if Apipie.configuration.process_value?
271
- @api_params ||= {}
272
- method_params.each do |_, param|
273
- # params processing
274
- @api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
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
@@ -62,7 +62,7 @@ module Apipie
62
62
  attr_accessor :value, :error
63
63
 
64
64
  def initialize(param, value, error)
65
- super param
65
+ super(param)
66
66
  @value = value
67
67
  @error = error
68
68
  end
@@ -89,7 +89,7 @@ module Apipie
89
89
  end
90
90
 
91
91
  def finalize_descriptions
92
- @descriptions.each do |method, desc|
92
+ @descriptions.each_value do |desc|
93
93
  add_routes_info(desc)
94
94
  end
95
95
  return @descriptions
@@ -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.each { |k,v| v.is_a?(Hash) and reformat_hash(boundary, v, lines) }
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.each do |_, desc|
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
@@ -24,7 +24,7 @@ module Apipie
24
24
  HEREDOC
25
25
  )
26
26
 
27
- send("#{attribute}=", value)
27
+ send(:"#{attribute}=", value)
28
28
  end
29
29
 
30
30
  old_setter_method = "swagger_#{attribute}"
@@ -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
- .each { |_, desc| desc.required = true }
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)
@@ -78,6 +79,14 @@ class Apipie::Generator::Swagger::ParamDescription::Builder
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].to_s || validator_opts[:array_of].to_s
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: 'string' }
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.select do |method_description_name, _|
22
+ resource_description._methods.any? do |method_description_name, _|
23
23
  method_description_name == method_name
24
- end.present?
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
- return self.send(key) if self.respond_to?(key.to_s)
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
- return self.send(key) if self.respond_to?(key.to_s)
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::File.new(@root)
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)
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -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 => (layout && "apipie/#{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].each do |resource_id, _|
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
@@ -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.each do |(controller, action), apis|
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
  )
@@ -200,4 +200,16 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
200
200
  it { is_expected.to be_present }
201
201
  end
202
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
203
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) # one file for each language
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
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
4
  require 'simplecov'
5
- SimpleCov.minimum_coverage 89
5
+ SimpleCov.minimum_coverage 91
6
6
  SimpleCov.start
7
7
 
8
8
  ENV["RAILS_ENV"] ||= 'test'
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.3
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-10-11 00:00:00.000000000 Z
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.18
475
+ rubygems_version: 3.4.22
476
476
  signing_key:
477
477
  specification_version: 4
478
478
  summary: Rails REST API documentation tool