apipie-rails 0.5.10 → 0.5.11
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/CHANGELOG.md +7 -0
- data/Gemfile.rails50 +2 -1
- data/README.rst +6 -0
- data/lib/apipie-rails.rb +1 -0
- data/lib/apipie/dsl_definition.rb +9 -1
- data/lib/apipie/extractor.rb +8 -1
- data/lib/apipie/method_description.rb +11 -0
- data/lib/apipie/resource_description.rb +3 -2
- data/lib/apipie/swagger_generator.rb +19 -2
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/version.rb +1 -1
- data/spec/controllers/apipies_controller_spec.rb +1 -0
- data/spec/controllers/users_controller_spec.rb +2 -1
- data/spec/dummy/app/controllers/pets_controller.rb +8 -0
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +1 -1
- data/spec/lib/swagger/openapi_2_0_schema.json +1 -1
- data/spec/lib/swagger/rake_swagger_spec.rb +8 -0
- data/spec/lib/swagger/response_validation_spec.rb +1 -1
- data/spec/lib/swagger/swagger_dsl_spec.rb +48 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d88dded075d493175af924c28b12d0a5f8bf1e
|
4
|
+
data.tar.gz: ecb35e91359fe60787a7364a9b427f0322260f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdd586c211924d6c84830aa2d014355edef2e7c63fd7e3e90e2c02beba0ad440e756244fadaf96178b57d9a2fce45c3e0177ef95d941a6096ce876f8c318f68c
|
7
|
+
data.tar.gz: 17381631aa321f511da743d329b6c0cbfd08d4b12581ab83b2f15f9ba07ab0ef02fbc11fadacdc7bdcbd13797262278f1df71a460c75e90cf0a44721ead062c7
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
Changelog
|
2
2
|
===========
|
3
3
|
|
4
|
+
v0.5.11
|
5
|
+
-------
|
6
|
+
|
7
|
+
- Adds swagger tags in swagger output [\#634](https://github.com/Apipie/apipie-rails/pull/634) ([enrique-guillen](https://github.com/enrique-guillen))
|
8
|
+
- Generate swagger with headers [\#630](https://github.com/Apipie/apipie-rails/pull/630) ([Uysim](https://github.com/Uysim))
|
9
|
+
- Fix examples not being generated for Rails < 5.0.0 [\#633](https://github.com/Apipie/apipie-rails/pull/633) ([RomanKapitonov](https://github.com/RomanKapitonov))
|
10
|
+
|
4
11
|
v0.5.10
|
5
12
|
------
|
6
13
|
|
data/Gemfile.rails50
CHANGED
data/README.rst
CHANGED
@@ -222,6 +222,12 @@ param
|
|
222
222
|
returns
|
223
223
|
Look at `Response description`_ section for details.
|
224
224
|
|
225
|
+
tags
|
226
|
+
Adds tags for grouping operations together in Swagger outputs. See `swagger`_
|
227
|
+
for more details. You can also provide tags in the `Resource Description`_
|
228
|
+
block so that they are automatically prepended to all action tags in the
|
229
|
+
controller.
|
230
|
+
|
225
231
|
formats
|
226
232
|
Method level request / response formats.
|
227
233
|
|
data/lib/apipie-rails.rb
CHANGED
@@ -15,6 +15,7 @@ require "apipie/error_description"
|
|
15
15
|
require "apipie/response_description"
|
16
16
|
require "apipie/response_description_adapter"
|
17
17
|
require "apipie/see_description"
|
18
|
+
require "apipie/tag_list_description"
|
18
19
|
require "apipie/validator"
|
19
20
|
require "apipie/railtie"
|
20
21
|
require 'apipie/extractor'
|
@@ -32,10 +32,11 @@ module Apipie
|
|
32
32
|
:api_args => [],
|
33
33
|
:api_from_routes => nil,
|
34
34
|
:errors => [],
|
35
|
+
:tag_list => [],
|
35
36
|
:returns => {},
|
36
37
|
:params => [],
|
37
38
|
:headers => [],
|
38
|
-
:resource_id
|
39
|
+
:resource_id => nil,
|
39
40
|
:short_description => nil,
|
40
41
|
:description => nil,
|
41
42
|
:examples => [],
|
@@ -222,6 +223,13 @@ module Apipie
|
|
222
223
|
_apipie_dsl_data[:errors] << [code_or_options, desc, options]
|
223
224
|
end
|
224
225
|
|
226
|
+
# Add tags to resources and actions group operations together.
|
227
|
+
def tags(*args)
|
228
|
+
return unless Apipie.active_dsl?
|
229
|
+
tags = args.length == 1 ? args.first : args
|
230
|
+
_apipie_dsl_data[:tag_list] += tags
|
231
|
+
end
|
232
|
+
|
225
233
|
def _apipie_define_validators(description)
|
226
234
|
|
227
235
|
# [re]define method only if validation is turned on
|
data/lib/apipie/extractor.rb
CHANGED
@@ -16,7 +16,14 @@ class Apipie::Railtie
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
app.middleware.use ::Apipie::Extractor::Recorder::Middleware
|
19
|
-
|
19
|
+
|
20
|
+
if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
|
21
|
+
ActionController::TestCase::Behavior.instance_eval do
|
22
|
+
prepend Apipie::Extractor::Recorder::FunctionalTestRecording
|
23
|
+
end
|
24
|
+
else
|
25
|
+
ActionController::TestCase.send(:prepend, Apipie::Extractor::Recorder::FunctionalTestRecording)
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
@@ -34,6 +34,8 @@ module Apipie
|
|
34
34
|
Apipie::ErrorDescription.from_dsl_data(args)
|
35
35
|
end
|
36
36
|
|
37
|
+
@tag_list = dsl_data[:tag_list]
|
38
|
+
|
37
39
|
@returns = dsl_data[:returns].map do |code,args|
|
38
40
|
Apipie::ResponseDescription.from_dsl_data(self, code, args)
|
39
41
|
end
|
@@ -94,6 +96,15 @@ module Apipie
|
|
94
96
|
@returns
|
95
97
|
end
|
96
98
|
|
99
|
+
def tag_list
|
100
|
+
all_tag_list = []
|
101
|
+
parent = Apipie.get_resource_description(@resource.controller.superclass)
|
102
|
+
|
103
|
+
# get tags from parent resource description
|
104
|
+
parent_tags = [parent, @resource].flat_map { |resource| resource._tag_list_arg }
|
105
|
+
Apipie::TagListDescription.new((parent_tags + @tag_list).uniq.compact)
|
106
|
+
end
|
107
|
+
|
97
108
|
def returns
|
98
109
|
all_returns = []
|
99
110
|
parent = Apipie.get_resource_description(@resource.controller.superclass)
|
@@ -14,8 +14,8 @@ module Apipie
|
|
14
14
|
class ResourceDescription
|
15
15
|
|
16
16
|
attr_reader :controller, :_short_description, :_full_description, :_methods, :_id,
|
17
|
-
:_path, :_name, :_params_args, :_returns_args, :
|
18
|
-
:_headers, :_deprecated
|
17
|
+
:_path, :_name, :_params_args, :_returns_args, :_tag_list_arg, :_errors_args,
|
18
|
+
:_formats, :_parent, :_metadata, :_headers, :_deprecated
|
19
19
|
|
20
20
|
def initialize(controller, resource_name, dsl_data = nil, version = nil, &block)
|
21
21
|
|
@@ -42,6 +42,7 @@ module Apipie
|
|
42
42
|
@_errors_args = dsl_data[:errors]
|
43
43
|
@_params_args = dsl_data[:params]
|
44
44
|
@_returns_args = dsl_data[:returns]
|
45
|
+
@_tag_list_arg = dsl_data[:tag_list]
|
45
46
|
@_metadata = dsl_data[:meta]
|
46
47
|
@_api_base_url = dsl_data[:api_base_url]
|
47
48
|
@_headers = dsl_data[:headers]
|
@@ -224,7 +224,7 @@ module Apipie
|
|
224
224
|
@current_http_method = method_key
|
225
225
|
|
226
226
|
methods[method_key] = {
|
227
|
-
tags: [tag_name_for_resource(ruby_method.resource)] + warning_tags,
|
227
|
+
tags: [tag_name_for_resource(ruby_method.resource)] + warning_tags + ruby_method.tag_list.tags,
|
228
228
|
consumes: params_in_body? ? ['application/json'] : ['application/x-www-form-urlencoded', 'multipart/form-data'],
|
229
229
|
operationId: op_id,
|
230
230
|
summary: Apipie.app.translate(api.short_description, @current_lang),
|
@@ -643,10 +643,27 @@ module Apipie
|
|
643
643
|
add_params_from_hash(swagger_result, body_param_defs_hash)
|
644
644
|
end
|
645
645
|
|
646
|
+
add_headers_from_hash(swagger_result, method.headers) if method.headers.present?
|
647
|
+
|
646
648
|
swagger_result
|
647
649
|
end
|
648
650
|
|
649
651
|
|
652
|
+
def add_headers_from_hash(swagger_params_array, headers)
|
653
|
+
swagger_headers = headers.map do |header|
|
654
|
+
{
|
655
|
+
name: header[:name],
|
656
|
+
in: 'header',
|
657
|
+
required: header[:options][:required],
|
658
|
+
description: header[:description],
|
659
|
+
type: header[:options][:type] || 'string'
|
660
|
+
}
|
661
|
+
|
662
|
+
end
|
663
|
+
swagger_params_array.push(*swagger_headers)
|
664
|
+
end
|
665
|
+
|
666
|
+
|
650
667
|
def add_params_from_hash(swagger_params_array, param_defs, prefix=nil, default_value_for_in=nil)
|
651
668
|
|
652
669
|
if default_value_for_in
|
@@ -684,7 +701,7 @@ module Apipie
|
|
684
701
|
end
|
685
702
|
end
|
686
703
|
end
|
687
|
-
|
704
|
+
|
688
705
|
end
|
689
706
|
|
690
707
|
end
|
data/lib/apipie/version.rb
CHANGED
@@ -395,6 +395,14 @@ class PetsController < ApplicationController
|
|
395
395
|
end
|
396
396
|
|
397
397
|
|
398
|
+
#-----------------------------------------------------------
|
399
|
+
# A method with simple tags.
|
400
|
+
#-----------------------------------------------------------
|
401
|
+
api!
|
402
|
+
tags(%w[Dogs Cats LivingBeings])
|
403
|
+
def show_plain_response_with_tags
|
404
|
+
render :plain => "showing pet properties"
|
405
|
+
end
|
398
406
|
|
399
407
|
end
|
400
408
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# The TagsController defined here provides an example of a resource_description
|
3
|
+
# defining a set of tags for the contained methods to include.
|
4
|
+
#
|
5
|
+
|
6
|
+
class TaggedCatsController < ApplicationController
|
7
|
+
resource_description do
|
8
|
+
description 'A controller to test "returns"'
|
9
|
+
short 'Pets'
|
10
|
+
path '/pets'
|
11
|
+
|
12
|
+
tags(%w[Dogs Pets])
|
13
|
+
end
|
14
|
+
|
15
|
+
#-----------------------------------------------------------
|
16
|
+
# simple 'returns' example: a method that returns a cat record
|
17
|
+
#-----------------------------------------------------------
|
18
|
+
api :GET, "/pets/:id/as_properties", "Get a cat record"
|
19
|
+
tags(%w[Animals])
|
20
|
+
def show_as_properties
|
21
|
+
render :plain => "showing pet properties"
|
22
|
+
end
|
23
|
+
|
24
|
+
#-----------------------------------------------------------
|
25
|
+
# simple 'returns' example: a method that returns another cat record
|
26
|
+
#-----------------------------------------------------------
|
27
|
+
api :GET, "/pets/:id/as_same_properties", "Get a cat record"
|
28
|
+
tags("Puma", "Animals")
|
29
|
+
def show_as_same_properties
|
30
|
+
render :plain => "showing pet properties"
|
31
|
+
end
|
32
|
+
end
|
@@ -299,4 +299,9 @@ class TwitterExampleController < ApplicationController
|
|
299
299
|
render :text => 'twitter example'
|
300
300
|
end
|
301
301
|
|
302
|
+
api :GET, '/twitter_example/{id}/followers', 'Find the followers for the given screen name'
|
303
|
+
tags %w[following index search]
|
304
|
+
def followers
|
305
|
+
render :text => 'followers'
|
306
|
+
end
|
302
307
|
end
|
@@ -291,7 +291,7 @@ class UsersController < ApplicationController
|
|
291
291
|
|
292
292
|
api :GET, '/users/action_with_headers'
|
293
293
|
header :RequredHeaderName, 'Required header description', required: true
|
294
|
-
header :OptionalHeaderName, 'Optional header description', required: false
|
294
|
+
header :OptionalHeaderName, 'Optional header description', required: false, type: 'string'
|
295
295
|
def action_with_headers
|
296
296
|
end
|
297
297
|
end
|
@@ -51,6 +51,10 @@ describe 'rake tasks' do
|
|
51
51
|
expect(param[field]).to eq(value)
|
52
52
|
end
|
53
53
|
|
54
|
+
def expect_tags_def(http_method, path, value)
|
55
|
+
params = apidoc_swagger["paths"][path][http_method]["tags"]
|
56
|
+
expect(params).to eq(value)
|
57
|
+
end
|
54
58
|
|
55
59
|
def body_param_def(http_method, path, param_name)
|
56
60
|
params = apidoc_swagger["paths"][path][http_method]["parameters"]
|
@@ -88,6 +92,8 @@ describe 'rake tasks' do
|
|
88
92
|
expect_param_def("get", "/users/by_department", "department", "in", "query")
|
89
93
|
expect_param_def("get", "/users/by_department", "department", "enum",
|
90
94
|
["finance", "operations", "sales", "marketing", "HR"])
|
95
|
+
|
96
|
+
expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
|
91
97
|
end
|
92
98
|
|
93
99
|
it "generates a valid swagger file" do
|
@@ -113,6 +119,8 @@ describe 'rake tasks' do
|
|
113
119
|
expect_param_def("get", "/users/by_department", "department", "enum",
|
114
120
|
["finance", "operations", "sales", "marketing", "HR"])
|
115
121
|
|
122
|
+
expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
|
123
|
+
|
116
124
|
end
|
117
125
|
|
118
126
|
it "generates a valid swagger file" do
|
@@ -166,6 +166,19 @@ describe "Swagger Responses" do
|
|
166
166
|
|
167
167
|
end
|
168
168
|
|
169
|
+
describe "PetsController#show_plain_response_with_tags" do
|
170
|
+
subject do
|
171
|
+
desc._methods[:show_plain_response_with_tags]
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should return tags with 'Dogs', 'Cats', and 'LivingBeings'" do
|
175
|
+
returns_obj = subject.tag_list
|
176
|
+
puts returns_obj.inspect
|
177
|
+
|
178
|
+
expect(returns_obj.tags).to eq(%w[Dogs Cats LivingBeings])
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
169
182
|
describe "PetsController#show_as_properties" do
|
170
183
|
subject do
|
171
184
|
desc._methods[:show_as_properties]
|
@@ -435,6 +448,40 @@ describe "Swagger Responses" do
|
|
435
448
|
|
436
449
|
end
|
437
450
|
|
451
|
+
#==============================================================================
|
452
|
+
# TaggedCatsController is a demonstration of how tags may be defined in the
|
453
|
+
# controller's resource description so that they may be automatically prefixed
|
454
|
+
# to a particular operation's tags.
|
455
|
+
#==============================================================================
|
456
|
+
|
457
|
+
describe TaggedCatsController do
|
458
|
+
describe "TaggedCatsController#show_as_properties" do
|
459
|
+
subject do
|
460
|
+
desc._methods[:show_as_properties]
|
461
|
+
end
|
462
|
+
|
463
|
+
it "should return tags with 'Dogs', 'Pets', and 'Animals'" do
|
464
|
+
returns_obj = subject.tag_list
|
465
|
+
puts returns_obj.inspect
|
466
|
+
|
467
|
+
expect(returns_obj.tags).to eq(%w[Dogs Pets Animals])
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
describe "TaggedCatsController#show_as_same_properties" do
|
472
|
+
subject do
|
473
|
+
desc._methods[:show_as_same_properties]
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should return tags with 'Dogs', 'Pets', 'Puma', and 'Animals'" do
|
477
|
+
returns_obj = subject.tag_list
|
478
|
+
puts returns_obj.inspect
|
479
|
+
|
480
|
+
expect(returns_obj.tags).to eq(%w[Dogs Pets Puma Animals])
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
438
485
|
#==============================================================================
|
439
486
|
# PetsUsingSelfDescribingClassesController is a demonstration of how
|
440
487
|
# responses can be described using manual generation of a property description
|
@@ -558,6 +605,7 @@ describe "Swagger Responses" do
|
|
558
605
|
|
559
606
|
expect(returns_obj.code).to eq(200)
|
560
607
|
expect(returns_obj.is_array?).to eq(false)
|
608
|
+
|
561
609
|
expect(returns_obj).to match_field_structure([:pet_name, :animal_type, :age])
|
562
610
|
end
|
563
611
|
|
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.
|
4
|
+
version: 0.5.11
|
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-
|
12
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -229,6 +229,7 @@ files:
|
|
229
229
|
- lib/apipie/see_description.rb
|
230
230
|
- lib/apipie/static_dispatcher.rb
|
231
231
|
- lib/apipie/swagger_generator.rb
|
232
|
+
- lib/apipie/tag_list_description.rb
|
232
233
|
- lib/apipie/validator.rb
|
233
234
|
- lib/apipie/version.rb
|
234
235
|
- lib/generators/apipie/install/README
|
@@ -264,6 +265,7 @@ files:
|
|
264
265
|
- spec/dummy/app/controllers/pets_controller.rb
|
265
266
|
- spec/dummy/app/controllers/pets_using_auto_views_controller.rb
|
266
267
|
- spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb
|
268
|
+
- spec/dummy/app/controllers/tagged_cats_controller.rb
|
267
269
|
- spec/dummy/app/controllers/twitter_example_controller.rb
|
268
270
|
- spec/dummy/app/controllers/users_controller.rb
|
269
271
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -358,6 +360,7 @@ test_files:
|
|
358
360
|
- spec/dummy/app/controllers/pets_controller.rb
|
359
361
|
- spec/dummy/app/controllers/pets_using_auto_views_controller.rb
|
360
362
|
- spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb
|
363
|
+
- spec/dummy/app/controllers/tagged_cats_controller.rb
|
361
364
|
- spec/dummy/app/controllers/twitter_example_controller.rb
|
362
365
|
- spec/dummy/app/controllers/users_controller.rb
|
363
366
|
- spec/dummy/app/views/layouts/application.html.erb
|