rspec-rails-api 0.3.1 → 0.3.2
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 -0
- data/CHANGELOG.md +7 -0
- data/lib/rspec/rails/api/dsl/example.rb +1 -1
- data/lib/rspec/rails/api/field_config.rb +4 -3
- data/lib/rspec/rails/api/metadata.rb +10 -20
- data/lib/rspec/rails/api/open_api_renderer.rb +15 -13
- data/lib/rspec/rails/api/utils.rb +2 -2
- data/lib/rspec/rails/api/version.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: d574f6e06c94fc87d2db77079f80a341da7455b5776c3513a7e84b5b80165090
|
4
|
+
data.tar.gz: 23ddbfe59c098baa1ffcec4dce21d5d6ba25f8fe0143d965d11a8bee25771aad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3430d1d5da42f6c7bf9d28f6c6e6a74ff332fb3cd31cf92d170d9c87f76527dd0d64d6ae510ae19873d7ca078c4405a05154d867f100f804e806c6e6fc342049
|
7
|
+
data.tar.gz: f251c30d40efaeef76bfd3ea0f313834dc7323ab56dc07ddf1ecc845b033160dd29afd053d3de3b0a2d7afee7092e858a1844795296e6593d9598f0d17f4df58
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
## Not released
|
5
5
|
|
6
|
+
## 0.3.2 - 2021-03-09
|
7
|
+
- Fix YAML rendering (ruby objects were sometimes rendered in documentation)
|
8
|
+
- Render examples results as YAML/JSON objects instead of text blocks.
|
9
|
+
|
10
|
+
## 0.3.1 - 2020-04-09
|
11
|
+
- Add support for "test only" examples, allowing to write examples without documentation.
|
12
|
+
|
6
13
|
## 0.3.0 - 2019-12-26
|
7
14
|
|
8
15
|
### Changed
|
@@ -11,7 +11,7 @@ module RSpec
|
|
11
11
|
class FieldConfig
|
12
12
|
attr_accessor :required, :type, :attributes, :description
|
13
13
|
|
14
|
-
def initialize(type:, required: true,
|
14
|
+
def initialize(type:, description:, required: true, attributes: nil, of: nil)
|
15
15
|
@required = required
|
16
16
|
@description = description
|
17
17
|
raise "Field type not allowed: '#{type}'" unless Utils.check_attribute_type(type)
|
@@ -40,9 +40,10 @@ module RSpec
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def define_attributes(attributes)
|
43
|
-
@attributes =
|
43
|
+
@attributes = case attributes
|
44
|
+
when Hash
|
44
45
|
@attributes = EntityConfig.new attributes
|
45
|
-
|
46
|
+
when Symbol
|
46
47
|
attributes
|
47
48
|
end
|
48
49
|
end
|
@@ -87,7 +87,7 @@ module RSpec
|
|
87
87
|
@current_method = method
|
88
88
|
end
|
89
89
|
|
90
|
-
# rubocop:disable
|
90
|
+
# rubocop:disable Layout/LineLength
|
91
91
|
def add_status_code(status_code, description)
|
92
92
|
check_current_context :resource, :url, :method
|
93
93
|
|
@@ -97,7 +97,7 @@ module RSpec
|
|
97
97
|
example: { response: nil })
|
98
98
|
@current_code = status_code
|
99
99
|
end
|
100
|
-
# rubocop:enable
|
100
|
+
# rubocop:enable Layout/LineLength
|
101
101
|
|
102
102
|
# rubocop:disable Metrics/ParameterLists
|
103
103
|
def add_request_example(url: nil, action: nil, status_code: nil, response: nil, path_params: nil, params: nil)
|
@@ -125,25 +125,14 @@ module RSpec
|
|
125
125
|
|
126
126
|
private
|
127
127
|
|
128
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
129
|
-
def check_current_context(*scope)
|
128
|
+
def check_current_context(*scope) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
130
129
|
scope ||= []
|
131
|
-
if scope.include?(:resource)
|
132
|
-
|
133
|
-
|
134
|
-
if scope.include?(:
|
135
|
-
raise 'No action declared' unless @current_method
|
136
|
-
end
|
137
|
-
if scope.include?(:url)
|
138
|
-
raise 'No url declared' unless @current_url
|
139
|
-
end
|
140
|
-
if scope.include?(:code)
|
141
|
-
raise 'No status code declared' unless @current_code
|
142
|
-
end
|
130
|
+
raise 'No resource declared' if scope.include?(:resource) && !@current_resource
|
131
|
+
raise 'No action declared' if scope.include?(:method) && !@current_method
|
132
|
+
raise 'No url declared' if scope.include?(:url) && !@current_url
|
133
|
+
raise 'No status code declared' if scope.include?(:code) && !@current_code
|
143
134
|
end
|
144
135
|
|
145
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Style/GuardClause
|
146
|
-
|
147
136
|
def path_param_scope(url_chunks, name)
|
148
137
|
if /:#{name}/.match?(url_chunks[0])
|
149
138
|
:path
|
@@ -154,11 +143,12 @@ module RSpec
|
|
154
143
|
end
|
155
144
|
end
|
156
145
|
|
157
|
-
def organize_params(fields) # rubocop:disable Metrics/AbcSize
|
146
|
+
def organize_params(fields) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
158
147
|
out = { properties: {} }
|
159
148
|
required = []
|
149
|
+
allowed_types = %i[array object]
|
160
150
|
fields.each do |name, field|
|
161
|
-
allowed_type =
|
151
|
+
allowed_type = allowed_types.include?(field[:type]) || PARAM_TYPES.key?(field[:type])
|
162
152
|
raise "Field type not allowed: #{field[:type]}" unless allowed_type
|
163
153
|
|
164
154
|
required.push name.to_s if field[:required]
|
@@ -39,10 +39,12 @@ module RSpec
|
|
39
39
|
content = prepare_metadata
|
40
40
|
path ||= ::Rails.root.join('tmp', 'rspec_api_rails')
|
41
41
|
|
42
|
+
file_types = %i[yaml json]
|
43
|
+
|
42
44
|
only.each do |type|
|
43
|
-
next unless
|
45
|
+
next unless file_types.include? type
|
44
46
|
|
45
|
-
File.write "#{path}.#{type}", content.send("to_#{type}")
|
47
|
+
File.write "#{path}.#{type}", JSON.parse(JSON.pretty_generate(content)).send("to_#{type}")
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -89,13 +91,14 @@ module RSpec
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def process_resource(resource: nil, resource_config: nil) # rubocop:disable Metrics/MethodLength
|
94
|
+
http_verbs = %i[get post put patch delete]
|
92
95
|
resource_config[:paths].each do |path_key, path|
|
93
96
|
url = path_with_params path_key.to_s
|
94
97
|
actions = {}
|
95
98
|
parameters = path.key?(:path_params) ? process_path_params(path[:path_params]) : []
|
96
99
|
|
97
100
|
path[:actions].each_key do |action|
|
98
|
-
next unless
|
101
|
+
next unless http_verbs.include? action
|
99
102
|
|
100
103
|
actions[action] = process_action resource: resource,
|
101
104
|
path: path_key,
|
@@ -117,7 +120,7 @@ module RSpec
|
|
117
120
|
parameters
|
118
121
|
end
|
119
122
|
|
120
|
-
def process_path_param(name, param) # rubocop:disable Metrics/MethodLength
|
123
|
+
def process_path_param(name, param) # rubocop:disable Metrics/MethodLength
|
121
124
|
parameter = {
|
122
125
|
name: name.to_s,
|
123
126
|
description: param[:description],
|
@@ -138,13 +141,12 @@ module RSpec
|
|
138
141
|
responses = {}
|
139
142
|
request_body = nil
|
140
143
|
|
141
|
-
if %i[post put
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
144
|
+
if %i[post put
|
145
|
+
patch].include?(action_config) && path_config[:actions][action_config][:params].keys.count.positive?
|
146
|
+
schema = path_config[:actions][action_config][:params]
|
147
|
+
schema_ref = escape_operation_id("#{action_config}_#{path}")
|
148
|
+
examples = process_examples(path_config[:actions][action_config][:statuses])
|
149
|
+
request_body = process_request_body schema: schema, ref: schema_ref, examples: examples
|
148
150
|
end
|
149
151
|
|
150
152
|
path_config[:actions][action_config][:statuses].each do |status_key, status|
|
@@ -190,7 +192,7 @@ module RSpec
|
|
190
192
|
|
191
193
|
response[:content] = {
|
192
194
|
'application/json': {
|
193
|
-
examples: { default: { value: JSON.
|
195
|
+
examples: { default: { value: JSON.parse(content) } },
|
194
196
|
},
|
195
197
|
}
|
196
198
|
|
@@ -220,7 +222,7 @@ module RSpec
|
|
220
222
|
string.downcase.gsub(/[^\w]+/, '_')
|
221
223
|
end
|
222
224
|
|
223
|
-
def api_infos
|
225
|
+
def api_infos
|
224
226
|
@api_infos = {
|
225
227
|
title: @api_title || 'Some sample app',
|
226
228
|
version: @api_version || '1.0',
|
@@ -11,7 +11,7 @@ module RSpec
|
|
11
11
|
path.split('.').inject(hash) do |sub_hash, key|
|
12
12
|
return nil unless sub_hash.is_a?(Hash) && sub_hash.key?(key.to_sym)
|
13
13
|
|
14
|
-
sub_hash[key.to_sym]
|
14
|
+
sub_hash[key.to_sym] # rubocop:disable Lint/UnmodifiedReduceAccumulator
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -27,7 +27,7 @@ module RSpec
|
|
27
27
|
hash
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.check_value_type(type, value)
|
30
|
+
def self.check_value_type(type, value)
|
31
31
|
return true if type == :boolean && (value.is_a?(TrueClass) || value.is_a?(FalseClass))
|
32
32
|
return true if type == :array && value.is_a?(Array)
|
33
33
|
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Tancoigne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|