swagger_api 0.1.47 → 0.1.48
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/Gemfile.lock +6 -6
- data/lib/swagger_api/component_schema.rb +14 -6
- data/lib/swagger_api/components.rb +15 -1
- data/lib/swagger_api/concerns/columns.rb +1 -1
- data/lib/swagger_api/concerns/sti_schema.rb +30 -0
- data/lib/swagger_api/operations/base.rb +8 -3
- data/lib/swagger_api/operations/create.rb +0 -6
- data/lib/swagger_api/operations/update.rb +0 -6
- data/lib/swagger_api/request_bodies.rb +4 -4
- data/lib/swagger_api/version.rb +1 -1
- data/lib/swagger_api.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb4dd2a0633d5191515c8699a0c6b03c8441e91
|
4
|
+
data.tar.gz: f9cb561189108adfd5c7fb599ef4af095de44a6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e716f77b6772363c94b31d97a8c74ee748cccd18fae8bdb9266ef390ab9255bba31cc09910609cd9a77524e122a4f0e4efb81a88145d683ab437b855b529b23e
|
7
|
+
data.tar.gz: 6026a289c5edc66bd67e9d4ab8ececa879aeac81883b08df47055c57f8297b096b8e1fbb863d8f0be2af917670ad1b731b6005a2ace5c384fcf41e2bc618d872
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
swagger_api (0.1.
|
4
|
+
swagger_api (0.1.47)
|
5
5
|
active_attr
|
6
6
|
rails (>= 5.0)
|
7
7
|
rspec-rails
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
erubi (~> 1.4)
|
33
33
|
rails-dom-testing (~> 2.0)
|
34
34
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
35
|
-
active_attr (0.
|
35
|
+
active_attr (0.11.0)
|
36
36
|
activemodel (>= 3.0.2, < 6.0)
|
37
37
|
activesupport (>= 3.0.2, < 6.0)
|
38
38
|
activejob (5.2.0)
|
@@ -61,7 +61,7 @@ GEM
|
|
61
61
|
erubi (1.7.1)
|
62
62
|
globalid (0.4.1)
|
63
63
|
activesupport (>= 4.2.0)
|
64
|
-
i18n (1.0.
|
64
|
+
i18n (1.0.1)
|
65
65
|
concurrent-ruby (~> 1.0)
|
66
66
|
loofah (2.2.2)
|
67
67
|
crass (~> 1.0.2)
|
@@ -75,10 +75,10 @@ GEM
|
|
75
75
|
mini_mime (1.0.0)
|
76
76
|
mini_portile2 (2.3.0)
|
77
77
|
minitest (5.11.3)
|
78
|
-
nio4r (2.3.
|
79
|
-
nokogiri (1.8.
|
78
|
+
nio4r (2.3.1)
|
79
|
+
nokogiri (1.8.3)
|
80
80
|
mini_portile2 (~> 2.3.0)
|
81
|
-
rack (2.0.
|
81
|
+
rack (2.0.5)
|
82
82
|
rack-test (1.0.0)
|
83
83
|
rack (>= 1.0, < 3)
|
84
84
|
rails (5.2.0)
|
@@ -16,7 +16,7 @@ module SwaggerApi
|
|
16
16
|
|
17
17
|
def required
|
18
18
|
controller.try(:columns).try(:required) ||
|
19
|
-
|
19
|
+
columns.map(&:name).map { |name| name.gsub(/^encrypted_/, '') } & clean_required_attributes
|
20
20
|
end
|
21
21
|
|
22
22
|
def clean_required_attributes
|
@@ -35,14 +35,22 @@ module SwaggerApi
|
|
35
35
|
end.compact.flatten.uniq.map(&:to_s)
|
36
36
|
end
|
37
37
|
|
38
|
+
def absence_attributes
|
39
|
+
@absence_attributes ||= model.validators.map do |validator|
|
40
|
+
validator.attributes if validator.is_a?(ActiveRecord::Validations::AbsenceValidator)
|
41
|
+
end.compact.flatten.uniq.map(&:to_s)
|
42
|
+
end
|
43
|
+
|
38
44
|
def properties
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
columns.map do |column|
|
46
|
+
next if column.name.end_with? '_iv'
|
47
|
+
next if absence_attributes.include? column.name
|
48
|
+
attribute_name = column.name.gsub(/^encrypted_/, '')
|
49
|
+
[attribute_name, ColumnSchema.new(column: column).create]
|
50
|
+
end.compact.to_h
|
44
51
|
end
|
45
52
|
|
53
|
+
|
46
54
|
def model
|
47
55
|
controller.model.constantize
|
48
56
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module SwaggerApi
|
2
2
|
class Components
|
3
3
|
include ActiveAttr::Model
|
4
|
+
include Concerns::StiSchema
|
5
|
+
|
4
6
|
attr_accessor :controllers
|
5
7
|
|
6
8
|
def create
|
@@ -8,7 +10,7 @@ module SwaggerApi
|
|
8
10
|
@components = {}
|
9
11
|
controllers.each do |controller|
|
10
12
|
if controller.custom_model_file.nil?
|
11
|
-
@components
|
13
|
+
@components.merge!(create_model_components_from_controller(controller))
|
12
14
|
else
|
13
15
|
@components.merge!(custom_json(controller.custom_model_file))
|
14
16
|
end
|
@@ -20,5 +22,17 @@ module SwaggerApi
|
|
20
22
|
file = File.read(custom_model_file)
|
21
23
|
JSON.parse(file)
|
22
24
|
end
|
25
|
+
|
26
|
+
def create_model_components_from_controller(controller)
|
27
|
+
if is_sti?(controller.model)
|
28
|
+
controller.model.constantize.descendants.map do |klass|
|
29
|
+
[klass.name, ComponentSchema.new(controller: OpenStruct.new(model: klass.name)).create]
|
30
|
+
end.to_h
|
31
|
+
else
|
32
|
+
{
|
33
|
+
controller.model => ComponentSchema.new(controller: controller).create
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SwaggerApi
|
2
|
+
module Concerns
|
3
|
+
module StiSchema
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def is_sti?(model)
|
8
|
+
model_klass = model&.safe_constantize || model
|
9
|
+
return false if model_klass.is_a? String
|
10
|
+
Rails.application.eager_load!
|
11
|
+
model_klass.descendants.count != 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def schema(model)
|
15
|
+
if is_sti?(model)
|
16
|
+
{
|
17
|
+
oneOf: model.descendants.map do |klass|
|
18
|
+
{ '$ref' => "#/components/schemas/#{klass.name}" }
|
19
|
+
end
|
20
|
+
}
|
21
|
+
else
|
22
|
+
{
|
23
|
+
'$ref' => "#/components/schemas/#{model.try(:name) || model}"
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -3,6 +3,7 @@ module SwaggerApi
|
|
3
3
|
class Base
|
4
4
|
include ActiveAttr::Model
|
5
5
|
include SwaggerApi::Concerns::Columns
|
6
|
+
include SwaggerApi::Concerns::StiSchema
|
6
7
|
|
7
8
|
attr_accessor :controller, :action
|
8
9
|
|
@@ -32,6 +33,12 @@ module SwaggerApi
|
|
32
33
|
]
|
33
34
|
end
|
34
35
|
|
36
|
+
def request_body
|
37
|
+
{
|
38
|
+
'$ref' => "#/components/requestBodies/#{model_name}"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
35
42
|
def responses
|
36
43
|
return @responses unless @responses.nil?
|
37
44
|
@responses = success_response
|
@@ -47,9 +54,7 @@ module SwaggerApi
|
|
47
54
|
description: "#{readable_action} #{model_name.downcase}'s information",
|
48
55
|
content: {
|
49
56
|
'application/json; charset=utf-8' => {
|
50
|
-
schema:
|
51
|
-
'$ref' => "#/components/schemas/#{model_name}"
|
52
|
-
}
|
57
|
+
schema: schema(model)
|
53
58
|
}
|
54
59
|
}
|
55
60
|
}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module SwaggerApi
|
2
2
|
class RequestBodies
|
3
3
|
include ActiveAttr::Model
|
4
|
+
include SwaggerApi::Concerns::StiSchema
|
5
|
+
|
4
6
|
attr_accessor :controllers
|
5
7
|
|
6
8
|
def create
|
@@ -15,12 +17,10 @@ module SwaggerApi
|
|
15
17
|
{
|
16
18
|
content: {
|
17
19
|
'application/json' => {
|
18
|
-
schema:
|
19
|
-
'$ref' => "#/components/schemas/#{controller.model}"
|
20
|
-
}
|
20
|
+
schema: schema(controller.model.safe_constantize || controller.model)
|
21
21
|
}
|
22
22
|
},
|
23
|
-
description: "
|
23
|
+
description: "#{controller.model} attribute",
|
24
24
|
required: true
|
25
25
|
}
|
26
26
|
end
|
data/lib/swagger_api/version.rb
CHANGED
data/lib/swagger_api.rb
CHANGED
@@ -110,6 +110,7 @@ require 'swagger_api/railtie'
|
|
110
110
|
|
111
111
|
require 'swagger_api/actions'
|
112
112
|
require 'swagger_api/concerns/columns'
|
113
|
+
require 'swagger_api/concerns/sti_schema'
|
113
114
|
require 'swagger_api/column_schema'
|
114
115
|
require 'swagger_api/component_schema'
|
115
116
|
require 'swagger_api/components'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.48
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Full Measure Education
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/swagger_api/component_schema.rb
|
122
122
|
- lib/swagger_api/components.rb
|
123
123
|
- lib/swagger_api/concerns/columns.rb
|
124
|
+
- lib/swagger_api/concerns/sti_schema.rb
|
124
125
|
- lib/swagger_api/operations/base.rb
|
125
126
|
- lib/swagger_api/operations/create.rb
|
126
127
|
- lib/swagger_api/operations/delete.rb
|