rspec-rails-api 0.6.1 → 0.6.3

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: 4771b145e32ae7cbfd7f03d6252618d3a4cd8b557930a67a562e45046d4e302b
4
- data.tar.gz: 6bc0e55b1c2e5d51ba5bdfc52ac532efbf5ad539e138557a99895ef637e0311a
3
+ metadata.gz: 4a96138e6fbb4608ddbf6a4e03912e3e2e262610bc0f98dadf5ad2c26a756ce8
4
+ data.tar.gz: 8bfaf96bafa6a8420db600978af05499e398d06ae6db0d18cfdc7cde86c68119
5
5
  SHA512:
6
- metadata.gz: cafa1ebfc333e41474f85dfb9389f976df1ffa8000de62c8a412c6436088db9182a7f15ec162dff46848265e6cf86564e5a79c93e0814afcc454a242ad77c8b6
7
- data.tar.gz: a24717ab5c36a863eaa6939c4ee3f5df3b5fbf058f45b17923d50dd0656680becca60f325d2d9c11b13db84dfaf243a4f24dd77450c33b28911086b986f9cb9e
6
+ metadata.gz: '04593f5aed1d220b4293da9571e9e8dfffef8564b49c76a64598c28565094cd14b6dfaf828074de51604cb5e861eaac35a536c9774edf227770f984929481d39'
7
+ data.tar.gz: 7857727829cf0e9df507566f31fc01ec6f1da45cbd0181cf8340f6f96245f0f0935eb5dc7f01c8b607335e98a9e0c7f6bedad5a44ec7d19bec8c058256732b83
data/CHANGELOG.md CHANGED
@@ -18,6 +18,19 @@ Maintenance, in case of rework, dependencies change
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [0.6.3] - 2024-01-24
22
+
23
+ ### Fixed
24
+
25
+ - `required` fields/parameters now can be false
26
+ - Querystring parameters are better handled and documented: no more need to specify the whole querystring in URL
27
+
28
+ ## [0.6.2] - 2024-01-17
29
+
30
+ ### Fixed
31
+
32
+ - Renderer: handle arrays of object with inline attributes
33
+
21
34
  ## [0.6.1] - 2024-01-17
22
35
 
23
36
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-rails-api (0.6.1)
4
+ rspec-rails-api (0.6.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -451,13 +451,31 @@ These methods are available:
451
451
 
452
452
  Defines the path parameters that are used in the URL.
453
453
 
454
+ Any field that is not referenced in the URL will end in querystring parameters.
455
+
454
456
  ```ruby
455
- on_get '/api/users/:id/posts/:post_slug?full=:full_post' do
457
+ on_get '/api/users/:id/posts/:post_slug' do
456
458
  path_params fields: {
459
+ # "path" parameters
457
460
  id: { type: :integer, description: 'The user ID' },
458
461
  post_slug: { type: :string, description: 'The post slug' },
459
- full_post: { type: :boolean, required: false, description: 'Returns the full post if `true`, or only an excerpt' } }
462
+ # "query" parameters
463
+ full_post: { type: :boolean, required: false, description: 'Returns the full post if `true`, or only an excerpt' },
464
+ }
465
+ # ...
466
+ end
467
+ ```
460
468
 
469
+ If the querystring parameters are visible in the URL for some reason, they will still be treated as `query` parameters:
470
+
471
+ ```ruby
472
+ on_get '/api/users/:id?full_bio=:full_bio_flag' do
473
+ path_params fields: {
474
+ # "path" parameters
475
+ id: { type: :integer, description: 'The user ID' },
476
+ # "query" parameters
477
+ full_bio_flag: { type: :boolean, required: false, description: 'Returns the full biography' },
478
+ }
461
479
  # ...
462
480
  end
463
481
  ```
@@ -465,7 +483,7 @@ end
465
483
  - `type` is the field type (check _entity definition_ for a list).
466
484
  - `description` should be some valid
467
485
  [CommonMark](https://commonmark.org/)
468
- - `required` is optional an defaults to `true`.
486
+ - `required` is optional and defaults to `true`.
469
487
 
470
488
  Alternative with defined parameters:
471
489
 
@@ -128,15 +128,20 @@ module RSpec
128
128
  end
129
129
 
130
130
  ##
131
- # Replace path params by values
131
+ # Replace path params by values and completes querystring
132
132
  #
133
133
  # @param url [String] Url definition
134
134
  # @param request_params [Hash] Request parameters
135
135
  #
136
136
  # @return [String] Actual path to visit
137
- def prepare_request_url(url, request_params)
138
- url.gsub(/(?::(\w*))/) do |e|
137
+ def prepare_request_url(url, request_params) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
138
+ used_path_params = []
139
+
140
+ # Replace any ":xyz" in url
141
+ url = url.gsub(/(?::(\w*))/) do |e|
139
142
  symbol = e.sub(':', '').to_sym
143
+ used_path_params << symbol
144
+
140
145
  if request_params.key?(symbol)
141
146
  request_params[symbol]
142
147
  elsif respond_to?(symbol)
@@ -145,6 +150,13 @@ module RSpec
145
150
  puts "! Define #{symbol} (let(:#{symbol}){ value }) or pass it to 'visit'"
146
151
  end
147
152
  end
153
+
154
+ # Use everything else in query string
155
+ uri = URI.parse(url)
156
+ query_params = request_params.select { |k| used_path_params.exclude? k }
157
+ uri.query = URI.encode_www_form(query_params) unless query_params.blank?
158
+
159
+ uri.to_s
148
160
  end
149
161
 
150
162
  ##
@@ -72,7 +72,7 @@ module RSpec
72
72
  raise "Parameter #{name} is already defined" if @parameters[name]
73
73
 
74
74
  fields.each_value do |field|
75
- field[:required] = true unless field[:required] == false
75
+ field[:required] = field[:required] != false
76
76
  field[:schema] = { type: field[:of] } if field[:type] == :array && PRIMITIVES.include?(field[:of])
77
77
  end
78
78
  @parameters[name] = fields
@@ -97,7 +97,7 @@ module RSpec
97
97
  Utils.deep_set(@resources, [@current_resource, 'paths', @current_url, 'path_params', name],
98
98
  description: field[:description] || nil,
99
99
  type: field[:type] || nil,
100
- required: field[:required] || true,
100
+ required: field[:required] != false,
101
101
  scope: scope)
102
102
  end
103
103
  end
@@ -282,10 +282,8 @@ module RSpec
282
282
  def path_param_scope(url_chunks, name)
283
283
  if /:#{name}/.match?(url_chunks[0])
284
284
  :path
285
- elsif url_chunks[1] && /:#{name}/ =~ url_chunks[1]
286
- :query
287
285
  else
288
- raise "#{name} not found in URL #{@current_url}"
286
+ :query
289
287
  end
290
288
  end
291
289
 
@@ -241,7 +241,7 @@ module RSpec
241
241
  property = { '$ref' => "#/components/schemas/#{field.attributes}" }
242
242
  elsif field.type == :array && field.attributes.is_a?(Symbol)
243
243
  property = { type: :array, items: { '$ref' => "#/components/schemas/#{field.attributes}" } }
244
- elsif field.type == :array
244
+ elsif field.type == :array && field.attributes
245
245
  property = { type: :array, items: process_entity(field.attributes) }
246
246
  end
247
247
 
@@ -267,7 +267,7 @@ module RSpec
267
267
  parameter = {
268
268
  name: name.to_s,
269
269
  description: param[:description].presence&.strip || '',
270
- required: param[:required] || true,
270
+ required: param[:required] != false,
271
271
  in: param[:scope].to_s,
272
272
  schema: {
273
273
  type: PARAM_TYPES[param[:type]][:type],
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Rails
5
5
  module Api
6
- VERSION = '0.6.1'
6
+ VERSION = '0.6.3'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Tancoigne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -222,7 +222,7 @@ metadata:
222
222
  bug_tracker_uri: https://gitlab.com/experimentslabs/rspec-rails-api/issues
223
223
  changelog_uri: https://gitlab.com/experimentslabs/rspec-rails-api/blob/master/CHANGELOG.md
224
224
  rubygems_mfa_required: 'true'
225
- post_install_message:
225
+ post_install_message:
226
226
  rdoc_options: []
227
227
  require_paths:
228
228
  - lib
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  version: '0'
239
239
  requirements: []
240
240
  rubygems_version: 3.4.1
241
- signing_key:
241
+ signing_key:
242
242
  specification_version: 4
243
243
  summary: Tests standard Rails API responses and generate doc
244
244
  test_files: []