apipie-rails 1.2.3 → 1.4.0

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +5 -4
  3. data/.github/workflows/rubocop-challenger.yml +1 -3
  4. data/.github/workflows/rubocop.yml +1 -1
  5. data/.rubocop_todo.yml +22 -28
  6. data/CHANGELOG.md +22 -0
  7. data/Gemfile +2 -3
  8. data/README.md +2088 -0
  9. data/apipie-rails.gemspec +7 -1
  10. data/app/views/apipie/apipies/_method_detail.erb +2 -0
  11. data/app/views/apipie/apipies/_params.html.erb +1 -0
  12. data/app/views/apipie/apipies/_params_plain.html.erb +1 -0
  13. data/config/locales/en.yml +1 -0
  14. data/config/locales/ko.yml +1 -0
  15. data/lib/apipie/application.rb +1 -1
  16. data/lib/apipie/dsl_definition.rb +10 -11
  17. data/lib/apipie/errors.rb +1 -1
  18. data/lib/apipie/extractor/collector.rb +1 -1
  19. data/lib/apipie/extractor/recorder.rb +1 -1
  20. data/lib/apipie/extractor/writer.rb +2 -2
  21. data/lib/apipie/generator/swagger/config.rb +1 -1
  22. data/lib/apipie/generator/swagger/method_description/parameters_service.rb +1 -1
  23. data/lib/apipie/generator/swagger/method_description/response_service.rb +14 -1
  24. data/lib/apipie/generator/swagger/param_description/builder.rb +9 -0
  25. data/lib/apipie/generator/swagger/param_description/type.rb +15 -2
  26. data/lib/apipie/generator/swagger/resource_description_collection.rb +2 -2
  27. data/lib/apipie/param_description.rb +1 -1
  28. data/lib/apipie/response_description.rb +34 -9
  29. data/lib/apipie/response_description_adapter.rb +3 -3
  30. data/lib/apipie/routes_formatter.rb +1 -1
  31. data/lib/apipie/static_dispatcher.rb +7 -1
  32. data/lib/apipie/version.rb +1 -1
  33. data/lib/tasks/apipie.rake +3 -3
  34. data/rel-eng/gem_release.ipynb +5 -5
  35. data/spec/controllers/users_controller_spec.rb +1 -1
  36. data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +1 -1
  37. data/spec/dummy/app/controllers/pets_controller.rb +2 -2
  38. data/spec/dummy/app/controllers/twitter_example_controller.rb +3 -3
  39. data/spec/lib/apipie/apipies_controller_spec.rb +1 -1
  40. data/spec/lib/apipie/extractor_spec.rb +1 -1
  41. data/spec/lib/apipie/file_handler_spec.rb +1 -1
  42. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +6 -6
  43. data/spec/lib/apipie/generator/swagger/method_description/response_service_spec.rb +62 -0
  44. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +14 -2
  45. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +6 -1
  46. data/spec/lib/apipie/param_description_spec.rb +1 -1
  47. data/spec/lib/apipie/response_description/response_object_spec.rb +22 -0
  48. data/spec/lib/apipie/response_description_spec.rb +56 -0
  49. data/spec/lib/apipie/swagger_generator_spec.rb +2 -2
  50. data/spec/lib/swagger/rake_swagger_spec.rb +6 -1
  51. data/spec/lib/swagger/swagger_dsl_spec.rb +1 -1
  52. data/spec/spec_helper.rb +1 -1
  53. metadata +12 -6
  54. data/README.rst +0 -1965
@@ -19,8 +19,8 @@ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
19
19
 
20
20
  let(:response_description_dsl) do
21
21
  proc do
22
- property :a_number, Integer
23
- property :an_optional_number, Integer, required: false
22
+ property :a_number, Integer, example: 1
23
+ property :an_optional_number, Integer, required: false, example: 2
24
24
  end
25
25
  end
26
26
 
@@ -56,10 +56,10 @@ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
56
56
  expect(properties).to eq(
57
57
  {
58
58
  a_number: {
59
- type: 'number', required: true
59
+ type: 'number', required: true, example: 1
60
60
  },
61
61
  an_optional_number: {
62
- type: 'number'
62
+ type: 'number', example: 2
63
63
  }
64
64
  }
65
65
  )
@@ -72,10 +72,10 @@ describe Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService do
72
72
  expect(properties).to eq(
73
73
  {
74
74
  a_number: {
75
- type: %w[number null], required: true
75
+ type: %w[number null], required: true, example: 1
76
76
  },
77
77
  an_optional_number: {
78
- type: %w[number null]
78
+ type: %w[number null], example: 2
79
79
  }
80
80
  }
81
81
  )
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::MethodDescription::ResponseService do
4
+ let(:http_method) { nil }
5
+ let(:language) { :en }
6
+ let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
7
+
8
+ let(:method_description) do
9
+ Apipie::Generator::Swagger::MethodDescription::Decorator.new(
10
+ Apipie::MethodDescription.new(
11
+ 'create',
12
+ Apipie::ResourceDescription.new(ApplicationController, 'pets'),
13
+ dsl_data
14
+ )
15
+ )
16
+ end
17
+
18
+ let(:returns) { [] }
19
+
20
+ let(:service) do
21
+ described_class.new(
22
+ method_description,
23
+ http_method: http_method,
24
+ language: language
25
+ )
26
+ end
27
+
28
+ describe '#call' do
29
+ describe 'headers' do
30
+ subject(:headers) { service.call[status_code][:headers] }
31
+
32
+ let(:status_code) { 200 }
33
+
34
+ it { is_expected.to be_blank }
35
+
36
+ context 'when headers exists' do
37
+ let(:dsl_data) { super().merge({ returns: returns }) }
38
+ let(:returns) { { status_code => [{}, nil, returns_dsl, nil] } }
39
+
40
+ let(:returns_dsl) do
41
+ proc do
42
+ header 'link', String, 'Relative links'
43
+ header 'Current-Page', Integer, 'The current page'
44
+ end
45
+ end
46
+
47
+ it 'returns the correct format headers' do
48
+ expect(headers).to eq({
49
+ 'link' => {
50
+ description: 'Relative links',
51
+ type: 'string'
52
+ },
53
+ 'Current-Page' => {
54
+ description: 'The current page',
55
+ type: 'integer'
56
+ }
57
+ })
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -118,7 +118,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
118
118
  { required: false, default_value: nil }
119
119
  end
120
120
 
121
- it 'will not warn' do
121
+ it 'does not warn' do
122
122
  expect { subject }.not_to output(
123
123
  /is optional but default value is not specified/
124
124
  ).to_stderr
@@ -130,7 +130,7 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
130
130
  { required: false, default_value: 123 }
131
131
  end
132
132
 
133
- it 'will not warn' do
133
+ it 'does not warn' do
134
134
  expect { subject }.not_to output(
135
135
  /is optional but default value is not specified/
136
136
  ).to_stderr
@@ -200,4 +200,16 @@ describe Apipie::Generator::Swagger::ParamDescription::Builder do
200
200
  it { is_expected.to be_present }
201
201
  end
202
202
  end
203
+
204
+ describe 'example' do
205
+ subject { generated_block[:example] }
206
+
207
+ it { is_expected.to be_blank }
208
+
209
+ context 'when example is assigned' do
210
+ let(:base_param_description_options) { { example: 'example' } }
211
+
212
+ it { is_expected.to eq('example') }
213
+ end
214
+ end
203
215
  end
@@ -115,10 +115,15 @@ describe Apipie::Generator::Swagger::ParamDescription::Type do
115
115
  it 'returns the reference' do
116
116
  expect(subject).to eq({ '$ref' => reference })
117
117
  end
118
-
119
118
  end
120
119
  end
121
120
 
121
+ context 'of a Swagger type' do
122
+ let(:validator_options) { { of: Integer } }
123
+
124
+ it { is_expected.to eq({ type: 'integer' }) }
125
+ end
126
+
122
127
  describe 'enum' do
123
128
  subject { items[:enum] }
124
129
 
@@ -21,7 +21,7 @@ describe Apipie::ParamDescription do
21
21
 
22
22
  it "should return the metadata" do
23
23
  meta = {
24
- :lenght => 32,
24
+ :length => 32,
25
25
  :weight => '830g'
26
26
  }
27
27
  param = Apipie::ParamDescription.new(method_desc, :some_param, String, :meta => meta)
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::ResponseDescription::ResponseObject do
4
+ describe '#header' do
5
+ let(:response_object) { described_class.new(nil, nil, nil, nil) }
6
+ let(:name) { 'Current-Page' }
7
+ let(:description) { 'The current page in the pagination' }
8
+
9
+ before { response_object.header(name, String, description) }
10
+
11
+ it 'adds it to the headers' do
12
+ expect(response_object.headers).to(
13
+ contain_exactly({
14
+ name: name,
15
+ description: description,
16
+ validator: 'string',
17
+ options: {}
18
+ })
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::ResponseDescription do
4
+ let(:resource_description) do
5
+ Apipie::ResourceDescription.new(PetsController, 'pets')
6
+ end
7
+
8
+ let(:method_description) do
9
+ Apipie::MethodDescription.new(
10
+ 'create',
11
+ resource_description,
12
+ ActionController::Base.send(:_apipie_dsl_data_init)
13
+ )
14
+ end
15
+
16
+ let(:response_description_dsl) { proc {} }
17
+ let(:options) { {} }
18
+
19
+ let(:response_description) do
20
+ described_class.new(
21
+ method_description,
22
+ 204,
23
+ options,
24
+ PetsController,
25
+ response_description_dsl,
26
+ nil
27
+ )
28
+ end
29
+
30
+ describe '#to_json' do
31
+ let(:to_json) { response_description.to_json }
32
+
33
+ describe 'headers' do
34
+ subject(:headers) { to_json[:headers] }
35
+
36
+ it { is_expected.to be_blank }
37
+
38
+ context 'when response has headers' do
39
+ let(:response_description_dsl) do
40
+ proc do
41
+ header 'Current-Page', Integer, 'The current page in the pagination', required: true
42
+ end
43
+ end
44
+
45
+ it 'returns the header' do
46
+ expect(headers).to contain_exactly({
47
+ name: 'Current-Page',
48
+ description: 'The current page in the pagination',
49
+ validator: 'integer',
50
+ options: { required: true }
51
+ })
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -7,7 +7,7 @@ describe Apipie::SwaggerGenerator do
7
7
 
8
8
  let(:response_description_dsl) do
9
9
  proc do
10
- property :a_number, Integer
10
+ property :a_number, Integer, example: 1
11
11
  property :an_optional_number, Integer, required: false
12
12
  end
13
13
  end
@@ -61,7 +61,7 @@ describe Apipie::SwaggerGenerator do
61
61
  expect(properties).to eq(
62
62
  {
63
63
  a_number: {
64
- type: 'number', required: true
64
+ type: 'number', required: true, example: 1
65
65
  },
66
66
  an_optional_number: {
67
67
  type: 'number'
@@ -82,6 +82,10 @@ describe 'rake tasks' do
82
82
  expect(param[field]).to eq(value)
83
83
  end
84
84
 
85
+ def expect_response_params_def(http_method, path, response_code, param_name, field, value)
86
+ param = apidoc_swagger["paths"][path][http_method]["responses"][response_code.to_s]["schema"]["properties"][param_name]
87
+ expect(param[field]).to eq(value)
88
+ end
85
89
 
86
90
  describe 'apipie:static_swagger_json[development,json,_tmp]' do
87
91
  it "generates static swagger files for the default version of apipie docs" do
@@ -105,6 +109,7 @@ describe 'rake tasks' do
105
109
  %w[finance operations sales marketing HR])
106
110
 
107
111
  expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
112
+ expect_response_params_def("get", "/pets/{id}/as_properties", 200, "pet_name", "example", "mypet")
108
113
  end
109
114
 
110
115
  it "generates a valid swagger file" do
@@ -146,7 +151,7 @@ describe 'rake tasks' do
146
151
 
147
152
  describe 'apipie:did_swagger_change[development,form_data,_tmp]' do
148
153
  it "keeps a reference file" do
149
- expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
154
+ expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
150
155
  end
151
156
  end
152
157
  end
@@ -283,7 +283,7 @@ describe "Swagger Responses" do
283
283
  expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'})
284
284
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
285
285
  expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
286
- expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false})
286
+ expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false}) # rubocop:disable Capybara/NegationMatcher
287
287
  end
288
288
 
289
289
  it "creates a swagger definition with all input parameters" do
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
4
  require 'simplecov'
5
- SimpleCov.minimum_coverage 89
5
+ SimpleCov.minimum_coverage 91
6
6
  SimpleCov.start
7
7
 
8
8
  ENV["RAILS_ENV"] ||= 'test'
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: 1.2.3
4
+ version: 1.4.0
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: 2023-10-11 00:00:00.000000000 Z
12
+ date: 2024-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -215,7 +215,7 @@ files:
215
215
  - MIT-LICENSE
216
216
  - NOTICE
217
217
  - PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md
218
- - README.rst
218
+ - README.md
219
219
  - Rakefile
220
220
  - apipie-rails.gemspec
221
221
  - app/controllers/apipie/apipies_controller.rb
@@ -419,6 +419,7 @@ files:
419
419
  - spec/lib/apipie/generator/swagger/context_spec.rb
420
420
  - spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb
421
421
  - spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb
422
+ - spec/lib/apipie/generator/swagger/method_description/response_service_spec.rb
422
423
  - spec/lib/apipie/generator/swagger/operation_id_spec.rb
423
424
  - spec/lib/apipie/generator/swagger/param_description/builder_spec.rb
424
425
  - spec/lib/apipie/generator/swagger/param_description/composite_spec.rb
@@ -442,6 +443,8 @@ files:
442
443
  - spec/lib/apipie/param_description_spec.rb
443
444
  - spec/lib/apipie/param_group_spec.rb
444
445
  - spec/lib/apipie/resource_description_spec.rb
446
+ - spec/lib/apipie/response_description/response_object_spec.rb
447
+ - spec/lib/apipie/response_description_spec.rb
445
448
  - spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb
446
449
  - spec/lib/apipie/swagger_generator_spec.rb
447
450
  - spec/lib/apipie/validator_spec.rb
@@ -454,9 +457,12 @@ files:
454
457
  - spec/support/custom_bool_validator.rb
455
458
  - spec/support/rake.rb
456
459
  - spec/test_engine/memes_controller_spec.rb
457
- homepage: http://github.com/Apipie/apipie-rails
460
+ homepage: https://github.com/Apipie/apipie-rails
458
461
  licenses: []
459
- metadata: {}
462
+ metadata:
463
+ bug_tracker_uri: https://github.com/Apipie/apipie-rails/issues
464
+ changelog_uri: https://github.com/Apipie/apipie-rails/blob/master/CHANGELOG.md
465
+ source_code_uri: https://github.com/Apipie/apipie-rails
460
466
  post_install_message:
461
467
  rdoc_options: []
462
468
  require_paths:
@@ -472,7 +478,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
472
478
  - !ruby/object:Gem::Version
473
479
  version: '0'
474
480
  requirements: []
475
- rubygems_version: 3.4.18
481
+ rubygems_version: 3.5.9
476
482
  signing_key:
477
483
  specification_version: 4
478
484
  summary: Rails REST API documentation tool