apipie-rails 0.5.13 → 0.5.14

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
- SHA1:
3
- metadata.gz: 7a003368791253c56f130f6ff692225f71d51736
4
- data.tar.gz: b0d9ea7bba052e5afbb460c6c2c2650609afdad3
2
+ SHA256:
3
+ metadata.gz: '018d734565f6849bf6c073c6774b2a99082bd6b88f15221999ae80b40c0efacc'
4
+ data.tar.gz: 00711a809dbdab171df9f447a3a6e7a8613cc89fa3ec7d632a036b5e2970c83d
5
5
  SHA512:
6
- metadata.gz: 003c59006f91cab87c478740a851d06926fc4ee029420d054ede2d619245929f13af84ed53704a1708263b4e825ac37eb8e429f8927e7ca6e30ea05397ab6846
7
- data.tar.gz: 8d3648f85b07e59313ae749397ed4ce965aed7dadd9d801f55dc1cefc296cb641e1740ba7be0141321b8347a844ea385655b58e1f75766605b536609b0c690d1
6
+ metadata.gz: 239806146c1a87920924fcb3ea63d8401edb21aa69b13a1f1305cdd4c2404c05f000cda9684fbdddd785b4124c0dde5540c6eaf78371e3e30172a96af6c54ac5
7
+ data.tar.gz: 1a58f612309c9c58c646805dabb64543257e26aa77e0132e8fc7b7d23fbe270008d449e39b00f4e89cc20b4920a044e428721df88c7427d6f114c7a3ee3b2423
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  Changelog
2
2
  ===========
3
3
 
4
+ v0.5.14
5
+ -------
6
+ - HTML escape validator values [\#645](https://github.com/Apipie/apipie-rails/pull/645) ([ekohl](https://github.com/ekohl))
7
+ - Support for adding new params via `update\_api` [\#642](https://github.com/Apipie/apipie-rails/pull/642) ([iNecas](https://github.com/iNecas))
8
+ - Allow the "null" JSON string to be used as a parameter in Apipie spec examples \(`show\_in\_doc`\) [\#641](https://github.com/Apipie/apipie-rails/pull/641) ([enrique-guillen](https://github.com/enrique-guillen))
9
+ - Fix examples recording for specific cases [\#640](https://github.com/Apipie/apipie-rails/pull/640) ([Marri](https://github.com/Marri))
10
+ - Add description section to response [\#639](https://github.com/Apipie/apipie-rails/pull/639) ([X1ting](https://github.com/X1ting))
11
+
12
+
4
13
  v0.5.13
5
14
  -------
6
15
  - Fix swagger generation if a controller's parent doesn't define a resource_description [\#637](https://github.com/Apipie/apipie-rails/pull/637) ([enrique-guillen](https://github.com/enrique-guillen))
data/Gemfile CHANGED
@@ -1 +1 @@
1
- Gemfile.rails50
1
+ ./Gemfile.rails50
@@ -40,6 +40,10 @@
40
40
  <%= heading(t('apipie.returns'), h_level) %>
41
41
  <% method[:returns].each do |item| %>
42
42
  <%= heading("#{t('apipie.code')}: #{item[:code]}", h_level + 1) %>
43
+ <% if item[:description] %>
44
+ <%= heading("#{t('apipie.description')}:", h_level + 2) %>
45
+ <p><%= item[:description] %></p>
46
+ <% end %>
43
47
  <table class='table'>
44
48
  <thead>
45
49
  <tr>
@@ -498,7 +498,7 @@ module Apipie
498
498
  params_ordered = dsl_data[:params].map do |args|
499
499
  Apipie::ParamDescription.from_dsl_data(method_description, args)
500
500
  end
501
- ParamDescription.unify(method_description.params_ordered_self + params_ordered)
501
+ ParamDescription.merge(method_description.params_ordered_self, params_ordered)
502
502
  end
503
503
  end
504
504
 
@@ -23,6 +23,7 @@ class Apipie::Railtie
23
23
  end
24
24
  else
25
25
  ActionController::TestCase.send(:prepend, Apipie::Extractor::Recorder::FunctionalTestRecording)
26
+ ActionController::TestCase::Behavior.send(:prepend, Apipie::Extractor::Recorder::FunctionalTestRecording)
26
27
  end
27
28
  end
28
29
  end
@@ -13,12 +13,13 @@ module Apipie
13
13
  @query = env["QUERY_STRING"] unless env["QUERY_STRING"].blank?
14
14
  @params = Rack::Utils.parse_nested_query(@query)
15
15
  @params.merge!(env["action_dispatch.request.request_parameters"] || {})
16
- if data = parse_data(env["rack.input"].read)
16
+ rack_input = env["rack.input"]
17
+ if data = parse_data(rack_input.read)
17
18
  @request_data = data
18
- env["rack.input"].rewind
19
19
  elsif form_hash = env["rack.request.form_hash"]
20
20
  @request_data = reformat_multipart_data(form_hash)
21
21
  end
22
+ rack_input.rewind
22
23
  end
23
24
 
24
25
  def analyse_controller(controller)
@@ -197,6 +197,14 @@ module Apipie
197
197
  end.sort_by { |param| ordering.index(param.name) }
198
198
  end
199
199
 
200
+ def self.merge(target_params, source_params)
201
+ params_to_merge, params_to_add = source_params.partition do |source_param|
202
+ target_params.any? { |target_param| source_param.name == target_param.name }
203
+ end
204
+ unify(target_params + params_to_merge)
205
+ target_params.concat(params_to_add)
206
+ end
207
+
200
208
  # action awareness is being inherited from ancestors (in terms of
201
209
  # nested params)
202
210
  def action_aware?
@@ -57,6 +57,10 @@ module Apipie
57
57
  "TODO: validator description"
58
58
  end
59
59
 
60
+ def format_description_value(value)
61
+ "<code>#{CGI::escapeHTML(value.to_s)}</code>"
62
+ end
63
+
60
64
  def error
61
65
  ParamInvalid.new(param_name, @error_value, description)
62
66
  end
@@ -148,7 +152,7 @@ module Apipie
148
152
  end
149
153
 
150
154
  def description
151
- "Must match regular expression <code>/#{@regexp.source}/</code>."
155
+ "Must match regular expression #{format_description_value("/#{@regexp.source}/")}."
152
156
  end
153
157
  end
154
158
 
@@ -172,7 +176,7 @@ module Apipie
172
176
  end
173
177
 
174
178
  def description
175
- string = @array.map { |value| "<code>#{value}</code>" }.join(', ')
179
+ string = @array.map { |value| format_description_value(value) }.join(', ')
176
180
  "Must be one of: #{string}."
177
181
  end
178
182
  end
@@ -272,7 +276,8 @@ module Apipie
272
276
  end
273
277
 
274
278
  def description
275
- "Must be one of: #{@array.join(', ')}."
279
+ string = @array.map { |value| format_description_value(value) }.join(', ')
280
+ "Must be one of: #{string}."
276
281
  end
277
282
  end
278
283
 
@@ -467,8 +472,8 @@ module Apipie
467
472
  end
468
473
 
469
474
  def description
470
- string = %w(true false 1 0).map { |value| "<code>#{value}</code>" }.join(', ')
471
- "Must be one of: #{string}"
475
+ string = %w(true false 1 0).map { |value| format_description_value(value) }.join(', ')
476
+ "Must be one of: #{string}."
472
477
  end
473
478
  end
474
479
 
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.5.13'
2
+ VERSION = '0.5.14'
3
3
  end
@@ -3,6 +3,7 @@ require "spec_helper"
3
3
  describe ExtendedController do
4
4
 
5
5
  it 'should include params from both original controller and extending concern' do
6
+ expect(Apipie["extended#create"].params.keys).to eq [:oauth, :user, :admin]
6
7
  user_param = Apipie["extended#create"].params[:user]
7
8
  expect(user_param.validator.params_ordered.map(&:name)).to eq [:name, :password, :from_concern]
8
9
  end
@@ -7,4 +7,8 @@ class ExtendedController < ApplicationController
7
7
  end
8
8
  def create
9
9
  end
10
+
11
+ apipie_update_params([:create]) do
12
+ param :admin, :boolean
13
+ end
10
14
  end
@@ -73,18 +73,28 @@ describe "Swagger Responses" do
73
73
  end
74
74
 
75
75
  def deep_match?(actual, expected, breadcrumb=[])
76
- num = 0
77
- for pdesc in expected do
78
- if pdesc.is_a? Symbol
79
- return false unless fields_match?(actual.params_ordered[num], pdesc, breadcrumb)
80
- elsif pdesc.is_a? Hash
81
- return false unless fields_match?(actual.params_ordered[num], pdesc.keys[0], breadcrumb)
82
- return false unless deep_match?(actual.params_ordered[num].validator, pdesc.values[0], breadcrumb + [pdesc.keys[0]])
76
+ pending_params = actual.params_ordered.dup
77
+ expected.each do |expected_param|
78
+ expected_param_name = expected_param.is_a?(Hash) ? expected_param.keys.first : expected_param
79
+ actual_param = pending_params.find { |param| param.name.to_s == expected_param_name.to_s }
80
+ unless actual_param
81
+ @fail_message = "Couldn't find #{expected_param_name.inspect} among #{pending_params.map(&:name)} in #{breadcrumb.join('.')}"
82
+ return false
83
+ else
84
+ pending_params.delete_if { |p| p.object_id == actual_param.object_id }
83
85
  end
84
- num+=1
86
+
87
+ return false unless fields_match?(actual_param, expected_param_name, breadcrumb)
88
+ if expected_param.is_a? Hash
89
+ return false unless deep_match?(actual_param.validator, expected_param.values[0], breadcrumb + [expected_param.keys.first])
90
+ end
91
+ end
92
+
93
+ unless pending_params.empty?
94
+ @fail_message = "Unexpected properties #{pending_params.map(&:name)} in #{breadcrumb.join('.')}"
95
+ return false
85
96
  end
86
- @fail_message = "expected property count#{breadcrumb == [] ? '' : ' of ' + (breadcrumb).join('.')} (#{actual.params_ordered.count}) to be #{num}"
87
- actual.params_ordered.count == num
97
+ true
88
98
  end
89
99
 
90
100
  def fields_match?(param, expected_name, breadcrumb)
@@ -50,6 +50,23 @@ describe Apipie::Validator do
50
50
  end
51
51
  end
52
52
 
53
+ describe 'BooleanValidator' do
54
+ it "should validate by object class" do
55
+ validator = Apipie::Validator::BooleanValidator.new(params_desc)
56
+ expect(validator.validate("1")).to be_truthy
57
+ expect(validator.validate(1)).to be_truthy
58
+ expect(validator.validate(true)).to be_truthy
59
+ expect(validator.validate(0)).to be_truthy
60
+ expect(validator.validate(false)).to be_truthy
61
+ expect(validator.validate({ 1 => 1 })).to be_falsey
62
+ end
63
+
64
+ it "should have a valid description" do
65
+ validator = Apipie::Validator::BooleanValidator.new(params_desc)
66
+ expect(validator.description).to eq('Must be one of: <code>true</code>, <code>false</code>, <code>1</code>, <code>0</code>.')
67
+ end
68
+ end
69
+
53
70
  describe 'ArrayClassValidator' do
54
71
  it "should validate by object class" do
55
72
  validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Fixnum, String])
@@ -57,5 +74,40 @@ describe Apipie::Validator do
57
74
  expect(validator.validate(1)).to be_truthy
58
75
  expect(validator.validate({ 1 => 1 })).to be_falsey
59
76
  end
77
+
78
+ it "should have a valid description" do
79
+ validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Float, String])
80
+ expect(validator.description).to eq('Must be one of: <code>Float</code>, <code>String</code>.')
81
+ end
82
+ end
83
+
84
+ describe 'RegexpValidator' do
85
+ it "should validate by object class" do
86
+ validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
87
+ expect(validator.validate("valid")).to be_truthy
88
+ expect(validator.validate("valid extra")).to be_truthy
89
+ expect(validator.validate("valid extra extra")).to be_truthy
90
+ expect(validator.validate("invalid")).to be_falsey
91
+ end
92
+
93
+ it "should have a valid description" do
94
+ validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
95
+ expect(validator.description).to eq('Must match regular expression <code>/^valid( extra)*$/</code>.')
96
+ end
97
+ end
98
+
99
+ describe 'EnumValidator' do
100
+ it "should validate by object class" do
101
+ validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
102
+ expect(validator.validate("first")).to be_truthy
103
+ expect(validator.validate("second & third")).to be_truthy
104
+ expect(validator.validate(1)).to be_falsey
105
+ expect(validator.validate({ 1 => 1 })).to be_falsey
106
+ end
107
+
108
+ it "should have a valid description" do
109
+ validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
110
+ expect(validator.description).to eq('Must be one of: <code>first</code>, <code>second &amp; third</code>.')
111
+ end
60
112
  end
61
113
  end
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: 0.5.13
4
+ version: 0.5.14
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: 2018-10-19 00:00:00.000000000 Z
12
+ date: 2018-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -331,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
331
331
  version: '0'
332
332
  requirements: []
333
333
  rubyforge_project:
334
- rubygems_version: 2.5.1
334
+ rubygems_version: 2.7.6
335
335
  signing_key:
336
336
  specification_version: 4
337
337
  summary: Rails REST API documentation tool