rspec-api-blueprint-formatter 0.2.1 → 0.2.2
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 +4 -4
- data/lib/api_blueprint.rb +1 -1
- data/lib/api_blueprint/action_formatter.rb +6 -1
- data/lib/api_blueprint/example_formatter.rb +5 -1
- data/lib/api_blueprint/version.rb +1 -1
- data/spec/api_blueprint/action_formatter_spec.rb +18 -0
- data/spec/api_blueprint/example_formatter_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68a3f26247af518145dd22bcb32ca8e724445311
|
4
|
+
data.tar.gz: 2dcd00052e7280ab6ad3cc4de602a423affd2ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4087c2a9d82868d9cfddb61489235c59c4c52c6c02b5baa33a8717d24871e93b068a66a05dfa82cc9ec98f78f5c86035aaf1a55033c4dffba2454bf48b5a7382
|
7
|
+
data.tar.gz: 314532515763924052e2c9caa7a6581dec9a49dd6d02a203cd202ced631ad9236b70445c842ea28fa0dbe091186f5d3443a0d1297e7e4618ff60554a351e5c65
|
data/lib/api_blueprint.rb
CHANGED
@@ -80,7 +80,7 @@ class ApiBlueprint < RSpec::Core::Formatters::BaseFormatter
|
|
80
80
|
end
|
81
81
|
output.puts "# #{resource_name}"
|
82
82
|
|
83
|
-
http_verbs = actions.keys.map {|action| action.scan(
|
83
|
+
http_verbs = actions.keys.map {|action| action.scan(/(GET|HEAD|POST|PATCH|PUT|DELETE|OPTIONS)/).flatten[0] }
|
84
84
|
|
85
85
|
unless http_verbs.length == http_verbs.uniq.length
|
86
86
|
raise "Action HTTP verbs are not unique #{actions.keys.inspect} for resource: '#{resource_name}'"
|
@@ -60,7 +60,7 @@ module ApiBlueprintFormatter
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def action_header(param, data)
|
63
|
-
param_signature = "#{param}#{param_attributes_string(data)}"
|
63
|
+
param_signature = "#{param}#{params_example_string(data)}#{param_attributes_string(data)}"
|
64
64
|
multiline_description = !members(param).empty?
|
65
65
|
|
66
66
|
header = "+ #{param_signature}"
|
@@ -75,6 +75,11 @@ module ApiBlueprintFormatter
|
|
75
75
|
" (#{param_attributes.join(', ')})" unless param_attributes.empty?
|
76
76
|
end
|
77
77
|
|
78
|
+
def params_example_string(data)
|
79
|
+
return '' unless data[:example]
|
80
|
+
": #{data[:example]}"
|
81
|
+
end
|
82
|
+
|
78
83
|
def members(param)
|
79
84
|
@action_metadata[:parameters][param].fetch(:members, [])
|
80
85
|
end
|
@@ -30,13 +30,17 @@ module ApiBlueprintFormatter
|
|
30
30
|
"\n" \
|
31
31
|
" #{example_metadata[:request][:parameters]}\n" \
|
32
32
|
"\n" \
|
33
|
-
" Location: #{
|
33
|
+
" Location: #{format_location}\n" \
|
34
34
|
" Source code:\n" \
|
35
35
|
"\n" \
|
36
36
|
"#{indent_lines(8, example_metadata[:source])}\n" \
|
37
37
|
"\n"
|
38
38
|
end
|
39
39
|
|
40
|
+
def format_location
|
41
|
+
example_metadata[:location].gsub(/:\d+/,'') # remove line numbers from location
|
42
|
+
end
|
43
|
+
|
40
44
|
def format_response
|
41
45
|
"+ Response #{example_metadata[:response][:status]} (#{example_metadata[:request][:format]})\n" \
|
42
46
|
"\n" \
|
@@ -75,6 +75,24 @@ RSpec.describe ApiBlueprintFormatter::ActionFormatter do
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
context 'descriptive param with: type, optionality and example value' do
|
79
|
+
let(:action_parameters) do
|
80
|
+
{
|
81
|
+
amount: { description: 'Id of a post', type: :number, optional: true, example: 123 }
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it do
|
86
|
+
is_expected.to eq <<-EOF
|
87
|
+
#{action_header}
|
88
|
+
|
89
|
+
+ Parameters
|
90
|
+
+ amount: 123 (number, optional) - Id of a post
|
91
|
+
|
92
|
+
EOF
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
78
96
|
context 'descriptive param with: type, optionality, default value' do
|
79
97
|
let(:action_parameters) do
|
80
98
|
{
|
@@ -17,7 +17,7 @@ RSpec.describe ApiBlueprintFormatter::ExampleFormatter do
|
|
17
17
|
|
18
18
|
let(:request_metadata) { { parameters: {}, format: 'application/json' } }
|
19
19
|
let(:response_metadata) { { status: 200, body: JSON.generate({a:1, b:2, c:3}) } }
|
20
|
-
let(:location) { "spec/api_blueprint/example_formatter_spec.rb" }
|
20
|
+
let(:location) { "spec/api_blueprint/example_formatter_spec.rb:42" }
|
21
21
|
let(:source) { "it 'returns standard APi Blueprint format' do\n ;\nend" }
|
22
22
|
|
23
23
|
|