rspec-rails-api 0.6.0 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa6db3329e09e4356d205cf49f100e11132a3e8a8fcb681ef8ede5e22ba470dd
4
- data.tar.gz: e25b15faecc41214f92bb089f8fc9e28702f9c5ad2072daf4014251d30f23291
3
+ metadata.gz: 4771b145e32ae7cbfd7f03d6252618d3a4cd8b557930a67a562e45046d4e302b
4
+ data.tar.gz: 6bc0e55b1c2e5d51ba5bdfc52ac532efbf5ad539e138557a99895ef637e0311a
5
5
  SHA512:
6
- metadata.gz: 2c947cf296de131ece545c7a21ed093d79de1e1fd5f57af53c58985eab815c781ce4dcbba7f7269c679dbf8155d4eabf0ae5035caa70bbd88090650630ed8e11
7
- data.tar.gz: b0c4d8bef1c715b0ea369b5f7a659e8fa69344735af2a7735a51a1cb755c3fc3b642597c47a133be9568c0361d8565725ed803d2b0dd530050d1e286795ee911
6
+ metadata.gz: cafa1ebfc333e41474f85dfb9389f976df1ffa8000de62c8a412c6436088db9182a7f15ec162dff46848265e6cf86564e5a79c93e0814afcc454a242ad77c8b6
7
+ data.tar.gz: a24717ab5c36a863eaa6939c4ee3f5df3b5fbf058f45b17923d50dd0656680becca60f325d2d9c11b13db84dfaf243a4f24dd77450c33b28911086b986f9cb9e
data/CHANGELOG.md CHANGED
@@ -18,6 +18,14 @@ Maintenance, in case of rework, dependencies change
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [0.6.1] - 2024-01-17
22
+
23
+ ### Fixed
24
+
25
+ - Renderer: handle arrays of object with inline attributes (not a reference)
26
+ - Renderer: Remove the `name` attribute from `basic` authentication declaration
27
+ - Renderer: Add missing `items` key on arrays of any type
28
+
21
29
  ## [0.6.0] - 2023-07-17
22
30
 
23
31
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-rails-api (0.6.0)
4
+ rspec-rails-api (0.6.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -26,89 +26,56 @@ bundle
26
26
 
27
27
  Configuration should be made manually for now:
28
28
 
29
- **spec/acceptance_helper.rb**
29
+ **spec/support/rspec_rails_api.rb**:
30
30
 
31
31
  ```ruby
32
- require 'rails_helper'
33
32
  require 'rspec_rails_api'
34
33
 
34
+ # Associate spec/acceptance/* to acceptance tests
35
+ RSpec::Rails::DIRECTORY_MAPPINGS[:acceptance] = %w[spec acceptance]
36
+
35
37
  RSpec.configure do |config|
36
38
  config.include RSpec::Rails::Api::DSL::Example
37
- end
38
-
39
- renderer = RSpec::Rails::Api::OpenApiRenderer.new
40
- # Options here should be customized
41
- renderer.api_title = 'YourProject API'
42
- renderer.api_version = '1'
43
- renderer.api_description = 'Manage data on YourProject'
44
- # Options below are optional
45
- renderer.api_servers = [{ url: 'https://example.com' }]
46
- renderer.api_tos = 'http://example.com/tos.html'
47
- renderer.api_contact = { name: 'Admin', email: 'admin@example.com', url: 'http://example.com/contact' }
48
- renderer.api_license = { name: 'Apache', url: 'https://opensource.org/licenses/Apache-2.0' }
39
+ config.include RSpec::Rails::RequestExampleGroup, type: :acceptance
49
40
 
50
- RSpec.configuration.after(:context, type: :acceptance) do |context|
51
- renderer.merge_context context.class.metadata[:rra].to_h
52
- end
41
+ # Define the renderer if you want to generate the OpenApi documentation
42
+ renderer = RSpec::Rails::Api::OpenApiRenderer.new
43
+ # Options here should be customized
44
+ renderer.api_title = 'YourProject API'
45
+ renderer.api_version = '1'
46
+ renderer.api_description = 'Manage data on YourProject'
47
+ # Options below are optional
48
+ renderer.api_servers = [{ url: 'https://example.com' }]
49
+ renderer.api_tos = 'http://example.com/tos.html'
50
+ renderer.api_contact = { name: 'Admin', email: 'admin@example.com', url: 'http://example.com/contact' }
51
+ renderer.api_license = { name: 'Apache', url: 'https://opensource.org/licenses/Apache-2.0' }
52
+ # ... Check the "Configuration" section for all the options
53
+
54
+ config.after(:context, type: :acceptance) do |context|
55
+ renderer.merge_context context.class.metadata[:rra].to_h
56
+ end
53
57
 
54
- RSpec.configuration.after(:suite) do
55
- # Default path is 'tmp/rspec_rails_api_output.json/yaml'
56
- renderer.write_files Rails.root.join('public', 'swagger_doc'), only: [:json]
58
+ config.after(:suite) do
59
+ # Default path is 'tmp/rspec_rails_api_output.json/yaml'
60
+ renderer.write_files Rails.root.join('public', 'swagger_doc'), only: [:json]
61
+ end
57
62
  end
58
63
  ```
59
64
 
60
- **spec/rails_helper.rb**
65
+ **spec/rails_helper.rb**:
61
66
 
62
67
  ```ruby
63
- # ...
64
-
65
- RSpec::Rails::DIRECTORY_MAPPINGS[:acceptance] = %w[spec acceptance]
66
-
67
- RSpec.configure do |config|
68
- # ...
69
- config.include RSpec::Rails::RequestExampleGroup, type: :acceptance
70
- end
68
+ #...
69
+ require 'support/rspec_rails_api'
70
+ #...
71
71
  ```
72
72
 
73
73
  ## Configuration
74
74
 
75
75
  **TODO: This section is incomplete and the gem has no generator yet.**
76
76
 
77
- Here is an example configuration:
78
-
79
- ```rb
80
- # spec/rails_helper.rb
81
- require 'spec/support/rspec_rails_api'
82
- ```
83
-
84
- ```rb
85
- # spec/support/acceptance_entities.rb
86
-
87
- # This file contains common object definitions
88
- {
89
- error: {
90
- error: { type: :string, description: "Error message" }
91
- },
92
- form_error: {
93
- title: { type: :array, required: false, description: "Title errors", of: :string }
94
- },
95
- }.each do |name, attributes|
96
- RSpec::Rails::Api::Metadata.add_entity name, attributes
97
- end
98
- ```
99
77
 
100
78
  ```rb
101
- # spec/support/rspec_rails_api.rb
102
- require 'rspec_rails_api'
103
- require 'support/acceptance_entities'
104
-
105
- # Include DSL in RSpec
106
- RSpec.configure do |config|
107
- config.include RSpec::Rails::Api::DSL::Example
108
- end
109
-
110
- # Initialize and configure the renderer
111
- renderer = RSpec::Rails::Api::OpenApiRenderer.new
112
79
  # Server URL for quick reference
113
80
  server_url = 'https://example.com'
114
81
 
@@ -229,10 +196,6 @@ end
229
196
  This solution comes from [this article](https://makandracards.com/makandra/37161-rspec-devise-how-to-sign-in-users-in-request-specs)
230
197
  by Arne Hartherz (MIT license).
231
198
 
232
- ## Usage
233
-
234
- Write some spec files and run RSpec as you would usually do.
235
-
236
199
  ## Writing specs
237
200
 
238
201
  There is a [commented example](dummy/spec/acceptance/posts_spec.rb) available in
@@ -334,21 +297,23 @@ RSpec::Rails::Api::Metadata.add_entity :user,
334
297
 
335
298
  Organization of the global entities declaration is up to you.
336
299
 
300
+ For small projects, we usually put them all in one file:
301
+
337
302
  ```rb
338
- # spec/acceptance/api/users_acceptance_spec.rb
339
- require 'rails_helper'
303
+ # spec/support/acceptance_entities.rb
340
304
 
341
- RSpec.describe 'Users', type: :acceptance do
342
- resource 'Users', 'Manage users'
305
+ require 'rspec/rails/api/metadata'
343
306
 
344
- on_get '/api/users/', 'Users list' do
345
- # "user" will use the global user entity
346
- for_code 200, 'Success response', expect_many: :user do |url|
347
- test_response_of url
348
- end
349
- end
350
-
351
- #...
307
+ # This file contains common object definitions
308
+ {
309
+ error: {
310
+ error: { type: :string, description: "Error message" }
311
+ },
312
+ form_error: {
313
+ title: { type: :array, required: false, description: "Title errors", of: :string }
314
+ },
315
+ }.each do |name, attributes|
316
+ RSpec::Rails::Api::Metadata.add_entity name, attributes
352
317
  end
353
318
  ```
354
319
 
@@ -746,6 +711,11 @@ MRs to improve this are welcome.
746
711
 
747
712
  There is no support for file fields yet.
748
713
 
714
+ ### Security
715
+
716
+ `Security` mechanisms are only declared for the OpenApi documentation as a reference, and is
717
+ not checked nor enforced in the tests.
718
+
749
719
  ## Development
750
720
 
751
721
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -53,7 +53,7 @@ module RSpec
53
53
  def define_attributes(attributes)
54
54
  @attributes = case attributes
55
55
  when Hash
56
- @attributes = EntityConfig.new attributes
56
+ EntityConfig.new attributes
57
57
  when Symbol
58
58
  attributes
59
59
  end
@@ -43,7 +43,7 @@ module RSpec
43
43
  def add_security_scheme(reference, name, definition)
44
44
  raise "Security scheme #{reference} is already defined" if @api_security.key? reference
45
45
 
46
- definition[:name] = name
46
+ definition[:name] = name unless reference == :basic
47
47
  @api_security[reference] = definition
48
48
  end
49
49
 
@@ -241,6 +241,8 @@ 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
245
+ property = { type: :array, items: process_entity(field.attributes) }
244
246
  end
245
247
 
246
248
  required.push name unless field.required == false
@@ -420,7 +422,7 @@ module RSpec
420
422
  response
421
423
  end
422
424
 
423
- def response_schema(expectations) # rubocop:disable Metrics/MethodLength
425
+ def response_schema(expectations) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
424
426
  if expectations[:many]
425
427
  items = if PRIMITIVES.include?(expectations[:many])
426
428
  { type: expectations[:many] }
@@ -429,7 +431,11 @@ module RSpec
429
431
  end
430
432
  { type: 'array', items: items }
431
433
  elsif expectations[:one]
432
- if PRIMITIVES.include?(expectations[:one])
434
+ # Unspecified arrays
435
+ if expectations[:one] == :array
436
+ { type: :array, items: {} }
437
+ # Array of specified type
438
+ elsif PRIMITIVES.include?(expectations[:one])
433
439
  { type: expectations[:one] }
434
440
  else
435
441
  { '$ref' => "#/components/schemas/#{expectations[:one]}" }
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Rails
5
5
  module Api
6
- VERSION = '0.6.0'
6
+ VERSION = '0.6.1'
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.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Tancoigne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-17 00:00:00.000000000 Z
11
+ date: 2024-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport