jsonapi-swagger 0.7.1 → 0.8.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.
- checksums.yaml +4 -4
- data/lib/generators/jsonapi/swagger/swagger_generator.rb +19 -2
- data/lib/generators/jsonapi/swagger/templates/swagger.json.erb +2 -2
- data/lib/generators/jsonapi/swagger/templates/swagger.rb.erb +2 -2
- data/lib/jsonapi/swagger.rb +4 -0
- data/lib/jsonapi/swagger/resource.rb +7 -0
- data/lib/jsonapi/swagger/resources/fast_jsonapi_resource.rb +39 -0
- data/lib/jsonapi/swagger/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bea152bc481a95fae26643e1df3fc5829a3f69eedfc5e6e8f95a3cb32703a688
|
4
|
+
data.tar.gz: e876e91b593c57aeaed8439710ea422d53070cf1affbdacfbe5a7fdd2f1a7d7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 306aebe1555ffe774a5cc72a0a8a18d435a6e165f781e373993982b4afdb5a88d2d15154ef9514913581ac94a209b4d66c372ddd101b21fb330e9f50554e76f5
|
7
|
+
data.tar.gz: 7af0d1c5f258616f3468a1420605f769e129b9ba5f0327e0e2c5dfec4b2e484ff88dbb07bc83b5e9839fd787f0a893a8f586bd11f7b5150e34d0df5458f3aa58
|
@@ -117,11 +117,23 @@ module Jsonapi
|
|
117
117
|
resource_klass.mutable?
|
118
118
|
end
|
119
119
|
|
120
|
+
def attribute_default
|
121
|
+
Jsonapi::Swagger.attribute_default
|
122
|
+
end
|
123
|
+
|
124
|
+
def transform_method
|
125
|
+
@transform_method ||= resource_klass.transform_method if resource_klass.respond_to?(:transform_method)
|
126
|
+
end
|
127
|
+
|
120
128
|
def columns_with_comment(need_encoding: true)
|
121
129
|
@columns_with_comment ||= {}.tap do |clos|
|
130
|
+
clos.default_proc = proc do |h, k|
|
131
|
+
h[k] = attribute_default
|
132
|
+
end
|
122
133
|
model_klass.columns.each do |col|
|
123
|
-
|
124
|
-
clos[
|
134
|
+
col_name = transform_method ? col.name.send(transform_method) : col.name
|
135
|
+
clos[col_name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: col.array, nullable: col.null, comment: col.comment }
|
136
|
+
clos[col_name.to_sym][:comment] = safe_encode(col.comment) if need_encoding
|
125
137
|
end
|
126
138
|
end
|
127
139
|
end
|
@@ -136,6 +148,11 @@ module Jsonapi
|
|
136
148
|
end
|
137
149
|
end
|
138
150
|
|
151
|
+
def relation_table_name(relation)
|
152
|
+
return relation.class_name.tableize if relation.respond_to?(:class_name)
|
153
|
+
return relation.name if relation.respond_to?(:name)
|
154
|
+
end
|
155
|
+
|
139
156
|
def t(key, options={})
|
140
157
|
content = tt(key, options)
|
141
158
|
safe_encode(content)
|
@@ -18,7 +18,7 @@
|
|
18
18
|
end
|
19
19
|
parameters << { name: :"fields[#{route_resouces}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
20
20
|
relationships.each_value do |relation|
|
21
|
-
parameters << { name: :"fields[#{relation
|
21
|
+
parameters << { name: :"fields[#{relation_table_name(relation)}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -31,7 +31,7 @@
|
|
31
31
|
end
|
32
32
|
parameters << { name: :"fields[#{route_resouces}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
33
33
|
relationships.each_value do |relation|
|
34
|
-
parameters << { name: :"fields[#{relation
|
34
|
+
parameters << { name: :"fields[#{relation_table_name(relation)}]", in: :query, type: :string, description: tt(:display_field), required: false }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -26,7 +26,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
26
26
|
<% end -%>
|
27
27
|
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
28
28
|
<% relationships.each_value do |relation| -%>
|
29
|
-
parameter name: :'fields[<%= relation
|
29
|
+
parameter name: :'fields[<%= relation_table_name(relation) %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
30
30
|
<% end -%>
|
31
31
|
response '200', '<%= t(:get_list) %>' do
|
32
32
|
schema type: :object,
|
@@ -113,7 +113,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
113
113
|
<% end -%>
|
114
114
|
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
115
115
|
<% relationships.each_value do |relation| -%>
|
116
|
-
parameter name: :'fields[<%= relation
|
116
|
+
parameter name: :'fields[<%= relation_table_name(relation) %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
117
117
|
<% end -%>
|
118
118
|
response '200', '<%= t(:get_detail) %>' do
|
119
119
|
schema type: :object,
|
data/lib/jsonapi/swagger.rb
CHANGED
@@ -17,6 +17,13 @@ module Jsonapi
|
|
17
17
|
end
|
18
18
|
require 'jsonapi/swagger/resources/serializable_resource'
|
19
19
|
return Jsonapi::Swagger::SerializableResource.new(@resource_class)
|
20
|
+
elsif Object.const_defined?("#{model_class_name}Serializer")
|
21
|
+
@resource_class = "#{model_class_name}Serializer".safe_constantize
|
22
|
+
unless @resource_class < FastJsonapi::ObjectSerializer
|
23
|
+
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of FastJsonapi::ObjectSerializer!"
|
24
|
+
end
|
25
|
+
require 'jsonapi/swagger/resources/fast_jsonapi_resource'
|
26
|
+
return Jsonapi::Swagger::FastJsonapiResource.new(@resource_class)
|
20
27
|
else
|
21
28
|
raise Jsonapi::Swagger::Error, "#{model_class_name} not support!"
|
22
29
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
module Jsonapi
|
3
|
+
module Swagger
|
4
|
+
class FastJsonapiResource
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :@fr, :attributes_to_serialize, :relationships_to_serialize, :sortable_fields,
|
8
|
+
:creatable_fields, :updatable_fields, :filters, :mutable?, :transform_method
|
9
|
+
|
10
|
+
def initialize(fr)
|
11
|
+
@fr = fr
|
12
|
+
end
|
13
|
+
|
14
|
+
alias attributes attributes_to_serialize
|
15
|
+
alias relationships relationships_to_serialize
|
16
|
+
|
17
|
+
# TODO: fast_jsonapi resource
|
18
|
+
def sortable_fields
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
def creatable_fields
|
23
|
+
[]
|
24
|
+
end
|
25
|
+
|
26
|
+
def updatable_fields
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
|
30
|
+
def filters
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
|
34
|
+
def mutable?
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YingRui Lu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/jsonapi/swagger/json.rb
|
85
85
|
- lib/jsonapi/swagger/railtie.rb
|
86
86
|
- lib/jsonapi/swagger/resource.rb
|
87
|
+
- lib/jsonapi/swagger/resources/fast_jsonapi_resource.rb
|
87
88
|
- lib/jsonapi/swagger/resources/jsonapi_resource.rb
|
88
89
|
- lib/jsonapi/swagger/resources/serializable_resource.rb
|
89
90
|
- lib/jsonapi/swagger/version.rb
|
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
- !ruby/object:Gem::Version
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
|
-
rubygems_version: 3.0.
|
110
|
+
rubygems_version: 3.0.3
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: JSON API Swagger Doc Generator
|