jsonapi_swagger_helpers 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jsonapi_swagger_helpers.gemspec +3 -0
- data/lib/jsonapi_swagger_helpers/configuration.rb +2 -1
- data/lib/jsonapi_swagger_helpers/destroy_action.rb +1 -1
- data/lib/jsonapi_swagger_helpers/errors.rb +1 -1
- data/lib/jsonapi_swagger_helpers/readable.rb +9 -5
- data/lib/jsonapi_swagger_helpers/resource_mixin.rb +19 -40
- data/lib/jsonapi_swagger_helpers/show_action.rb +1 -1
- data/lib/jsonapi_swagger_helpers/update_action.rb +1 -1
- data/lib/jsonapi_swagger_helpers/util.rb +1 -1
- data/lib/jsonapi_swagger_helpers/version.rb +1 -1
- data/lib/jsonapi_swagger_helpers/writeable.rb +11 -7
- metadata +45 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 120127d5171433f69fb65d417989dc398c21741b
|
4
|
+
data.tar.gz: 06017e09e6276039f7707fb0e79a7991038ebb99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d037d7b0d6b6b1f9b1397503eab836e3ddce5d29e556703cabfc1cd2d2a3dc38251459af9f32635e2583b6cf362bd379c591754d37755fcf27bc4209a5ee8d
|
7
|
+
data.tar.gz: 0bb06960deed1908866deda9e5d0f543cb9ea7f1f23628b7b54fa398970d802d896bb0d9382dc675b03575599f816069795f4f64022425c8e22937f3ca45e3e8
|
@@ -22,8 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
# TODO: above 0.4.2
|
23
23
|
spec.add_dependency 'jsonapi_spec_helpers', ['< 1']
|
24
24
|
spec.add_dependency 'jsonapi_compliable', ['~> 0.10']
|
25
|
+
spec.add_runtime_dependency 'strong_resources', '>= 0'
|
25
26
|
|
27
|
+
spec.add_development_dependency "activesupport", ">= 4.1"
|
26
28
|
spec.add_development_dependency "bundler", "~> 1.12"
|
29
|
+
spec.add_development_dependency "byebug", ">= 0"
|
27
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
32
|
end
|
@@ -1,21 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JsonapiSwaggerHelpers
|
2
4
|
module Readable
|
3
5
|
def self.included(klass)
|
4
6
|
klass.class_eval do
|
5
7
|
attr_reader :node,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
:controller,
|
9
|
+
:resource,
|
10
|
+
:description,
|
11
|
+
:tags,
|
12
|
+
:singular
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
13
|
-
def initialize(node, controller, description: nil, tags: [])
|
16
|
+
def initialize(node, controller, description: nil, tags: [], singular: false)
|
14
17
|
@node = node
|
15
18
|
@controller = controller
|
16
19
|
@resource = controller._jsonapi_compliable
|
17
20
|
@description = description || default_description
|
18
21
|
@tags = tags
|
22
|
+
@singular = singular
|
19
23
|
end
|
20
24
|
|
21
25
|
def default_description
|
@@ -5,13 +5,15 @@ module JsonapiSwaggerHelpers
|
|
5
5
|
tags: [],
|
6
6
|
descriptions: {},
|
7
7
|
only: [],
|
8
|
-
except: []
|
8
|
+
except: [],
|
9
|
+
singular: false)
|
9
10
|
self.resources << {
|
10
11
|
base_path: base_path,
|
11
12
|
tags: tags,
|
12
13
|
descriptions: descriptions,
|
13
14
|
only: only,
|
14
|
-
except: except
|
15
|
+
except: except,
|
16
|
+
singular: singular
|
15
17
|
}
|
16
18
|
end
|
17
19
|
|
@@ -21,8 +23,9 @@ module JsonapiSwaggerHelpers
|
|
21
23
|
descriptions = config[:descriptions]
|
22
24
|
only = config[:only]
|
23
25
|
except = config[:except]
|
26
|
+
singular = config[:singular]
|
24
27
|
|
25
|
-
actions = [
|
28
|
+
actions = %i[index show create update destroy]
|
26
29
|
actions.select! { |a| only.include?(a) } unless only.empty?
|
27
30
|
actions.reject! { |a| except.include?(a) } unless except.empty?
|
28
31
|
|
@@ -30,43 +33,19 @@ module JsonapiSwaggerHelpers
|
|
30
33
|
full_path = [prefix, base_path].join('/').gsub('//', '/')
|
31
34
|
controller = JsonapiSwaggerHelpers::Util.controller_for(full_path)
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
if [:show, :update, :destroy].any? { |a| actions.include?(a) }
|
51
|
-
ctx = self
|
52
|
-
swagger_path "#{base_path}/{id}" do
|
53
|
-
if actions.include?(:show) && controller.action_methods.include?('show')
|
54
|
-
show_action = JsonapiSwaggerHelpers::ShowAction.new \
|
55
|
-
self, controller, tags: tags, description: descriptions[:show]
|
56
|
-
show_action.generate
|
57
|
-
end
|
58
|
-
|
59
|
-
if actions.include?(:update) && controller.action_methods.include?('update')
|
60
|
-
update_action = JsonapiSwaggerHelpers::UpdateAction.new \
|
61
|
-
self, controller, tags: tags, description: descriptions[:update]
|
62
|
-
update_action.generate
|
63
|
-
end
|
64
|
-
|
65
|
-
if actions.include?(:destroy) && controller.action_methods.include?('destroy')
|
66
|
-
destroy_action = JsonapiSwaggerHelpers::DestroyAction.new \
|
67
|
-
self, controller, tags: tags, description: descriptions[:destroy]
|
68
|
-
destroy_action.generate
|
69
|
-
end
|
36
|
+
actions.each do |action|
|
37
|
+
next unless controller.action_methods.include?(action.to_s)
|
38
|
+
path = if !singular && %i[show update destroy].include?(action)
|
39
|
+
"#{base_path}/{id}"
|
40
|
+
else
|
41
|
+
base_path
|
42
|
+
end
|
43
|
+
swagger_path path do
|
44
|
+
action_class_name = "#{action.to_s.camelize}Action"
|
45
|
+
action_class = JsonapiSwaggerHelpers.const_get(action_class_name)
|
46
|
+
action_object = action_class.new \
|
47
|
+
self, controller, tags: tags, description: descriptions[action], singular: singular
|
48
|
+
action_object.generate
|
70
49
|
end
|
71
50
|
end
|
72
51
|
end
|
@@ -7,7 +7,7 @@ module JsonapiSwaggerHelpers
|
|
7
7
|
if route
|
8
8
|
"#{route[:controller]}_controller".classify.constantize
|
9
9
|
else
|
10
|
-
|
10
|
+
raise ArgumentError.new("JsonapiSwaggerHelpers: No controller found for #{path}!")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -1,21 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JsonapiSwaggerHelpers
|
2
4
|
module Writeable
|
3
5
|
def self.included(klass)
|
4
6
|
klass.class_eval do
|
5
7
|
attr_reader :node,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
:controller,
|
9
|
+
:resource,
|
10
|
+
:description,
|
11
|
+
:tags,
|
12
|
+
:singular
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
13
|
-
def initialize(node, controller, description: nil, tags: [])
|
16
|
+
def initialize(node, controller, description: nil, tags: [], singular: false)
|
14
17
|
@node = node
|
15
18
|
@controller = controller
|
16
19
|
@resource = controller._jsonapi_compliable
|
17
20
|
@description = description || default_description
|
18
21
|
@tags = tags
|
22
|
+
@singular = singular
|
19
23
|
end
|
20
24
|
|
21
25
|
def util
|
@@ -41,7 +45,7 @@ module JsonapiSwaggerHelpers
|
|
41
45
|
def payload_tags
|
42
46
|
tags = [:"payload-#{strong_resource.name}_#{action_name}"]
|
43
47
|
|
44
|
-
strong_resource.relations.each_pair do |relation_name,
|
48
|
+
strong_resource.relations.each_pair do |relation_name, _relation_config|
|
45
49
|
tags << :"payload-#{strong_resource.name}_#{relation_name}_#{action_name}"
|
46
50
|
end
|
47
51
|
|
@@ -68,7 +72,7 @@ module JsonapiSwaggerHelpers
|
|
68
72
|
key :'$ref', :"#{_self.strong_resource.name}_#{_self.action_name}"
|
69
73
|
end
|
70
74
|
|
71
|
-
_self.each_strong_relation(_self.strong_resource) do |relation_name,
|
75
|
+
_self.each_strong_relation(_self.strong_resource) do |relation_name, _relation_config|
|
72
76
|
property relation_name do
|
73
77
|
key :'$ref', :"#{_self.strong_resource.name}_#{relation_name}_#{_self.action_name}"
|
74
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi_swagger_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: swagger-blocks
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: strong_resources
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.1'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: bundler
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +94,20 @@ dependencies:
|
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '1.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: rake
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
190
|
version: '0'
|
149
191
|
requirements: []
|
150
192
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.6.
|
193
|
+
rubygems_version: 2.6.12
|
152
194
|
signing_key:
|
153
195
|
specification_version: 4
|
154
196
|
summary: Swagger helpers for jsonapi.org-compatible APIs
|