jsonapi-swagger 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cfab1114fff50d85a5e1a794431587a8f6275e2dbcd2343b4ae4a527ae379e1
|
4
|
+
data.tar.gz: 535abfa4b0960bcaa7f752d30d64f7ba255306bd5652cb522088137754146f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1846b3909f1fe9948e5e213818df33f763c9c75be9d055ba96149d6bb1f346a4cc1566b5e5b5270d9bb6a1934c03f4411470d48ecf662f5314b8306b77666af
|
7
|
+
data.tar.gz: 204262395c367fab8a0eb6febed30c4420a7bc8191aa872977c087418bd4b0c3bed08739325681a275fa2ddf664eedfa4f51f3520035b0ab53bfc26a82f67181
|
@@ -18,12 +18,16 @@ module Jsonapi
|
|
18
18
|
"#{file_name.downcase.pluralize}_spec.rb"
|
19
19
|
end
|
20
20
|
|
21
|
+
def model_name
|
22
|
+
file_name.downcase.singularize
|
23
|
+
end
|
24
|
+
|
21
25
|
def resouces_name
|
22
26
|
model_class_name.pluralize
|
23
27
|
end
|
24
28
|
|
25
29
|
def route_resouces
|
26
|
-
resouces_name.
|
30
|
+
resouces_name.tableize
|
27
31
|
end
|
28
32
|
|
29
33
|
def model_class_name
|
@@ -49,14 +53,16 @@ module Jsonapi
|
|
49
53
|
def columns_with_comment
|
50
54
|
@columns_with_comment ||= {}.tap do |clos|
|
51
55
|
model_klass.columns.each do |col|
|
52
|
-
clos[col.name.to_sym] = { type: swagger_type(col.type
|
56
|
+
clos[col.name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: col.array, nullable: col.null, comment: safe_encode(col.comment) }
|
53
57
|
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
|
-
def swagger_type(
|
58
|
-
|
61
|
+
def swagger_type(column)
|
62
|
+
return 'array' if column.array
|
63
|
+
case column.type
|
59
64
|
when :bigint, :integer then 'integer'
|
65
|
+
when :boolean then 'boolean'
|
60
66
|
else 'string'
|
61
67
|
end
|
62
68
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
require 'swagger_helper'
|
2
2
|
RSpec.describe '<%= resouces_name %>', type: :request do
|
3
|
-
|
3
|
+
let(:include) {''} #see https://github.com/domaindrivendev/rswag/issues/188
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@<%= model_name %> = create :<%= model_name %>
|
7
|
+
end
|
8
|
+
|
4
9
|
path '/<%= route_resouces %>' do
|
5
10
|
get '<%= route_resouces %>' do
|
6
11
|
tags '<%= route_resouces %>'
|
7
12
|
produces 'application/vnd.api+json'
|
8
13
|
parameter name: :'page[number]', in: :query, type: :string, description: '页码', required: false
|
9
14
|
parameter name: :include, in: :query, type: :string, description: '包含关联数据', required: false
|
10
|
-
|
11
|
-
|
15
|
+
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '包含字段', required: false
|
16
|
+
<% relationships.each_key do |relation| -%>
|
17
|
+
parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '包含字段', required: false
|
12
18
|
<% end -%>
|
13
19
|
response '200', '获取列表' do
|
14
20
|
schema type: :object,
|
@@ -18,7 +24,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
18
24
|
items: {
|
19
25
|
type: :object,
|
20
26
|
properties: {
|
21
|
-
id: { type: :
|
27
|
+
id: { type: :string, description: 'ID'},
|
22
28
|
links: {
|
23
29
|
type: :object,
|
24
30
|
properties: {
|
@@ -29,8 +35,8 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
29
35
|
attributes: {
|
30
36
|
type: :object,
|
31
37
|
properties: {
|
32
|
-
<% attributes.
|
33
|
-
<%= attr %>: { type: :<%= columns_with_comment[attr][:type] %>, description: '<%= columns_with_comment[attr][:comment] %>'},
|
38
|
+
<% attributes.each_key.each do |attr| -%>
|
39
|
+
<%= attr %>: { type: :<%= columns_with_comment[attr][:type] %>, <%if columns_with_comment[attr][:is_array] -%> items: { type: :<%= columns_with_comment[attr][:items_type] %>},<% end -%> 'x-nullable': <%= columns_with_comment[attr][:nullable] %>, description: '<%= columns_with_comment[attr][:comment] %>'},
|
34
40
|
<% end -%>
|
35
41
|
},
|
36
42
|
description: '属性'
|
@@ -70,7 +76,14 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
70
76
|
},
|
71
77
|
description: '分页记录数'
|
72
78
|
},
|
73
|
-
links: {
|
79
|
+
links: {
|
80
|
+
type: :object,
|
81
|
+
properties: {
|
82
|
+
first: { type: :string, description: '第一页'},
|
83
|
+
next: { type: :string, description: '下一页'},
|
84
|
+
last: { type: :string, description: '最后一页'},
|
85
|
+
},
|
86
|
+
description: '分页链接' },
|
74
87
|
},
|
75
88
|
required: [:data]
|
76
89
|
run_test!
|
@@ -83,16 +96,19 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
83
96
|
tags '<%= route_resouces %>'
|
84
97
|
produces 'application/vnd.api+json'
|
85
98
|
parameter name: :id, in: :path, type: :integer, description: 'ID', required: true
|
86
|
-
|
99
|
+
parameter name: :include, in: :query, type: :string, description: '包含关联数据', required: false
|
100
|
+
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '包含字段', required: false
|
101
|
+
<% relationships.each_key do |relation| -%>
|
102
|
+
parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '包含字段', required: false
|
103
|
+
<% end -%>
|
87
104
|
response '200', '获取详情' do
|
88
105
|
schema type: :object,
|
89
106
|
properties: {
|
90
107
|
data: {
|
91
|
-
type: :array,
|
92
|
-
items: {
|
93
108
|
type: :object,
|
94
109
|
properties: {
|
95
|
-
id: { type: :
|
110
|
+
id: { type: :string, description: 'ID'},
|
111
|
+
type: { type: :string, description: 'Type'},
|
96
112
|
links: {
|
97
113
|
type: :object,
|
98
114
|
properties: {
|
@@ -103,8 +119,8 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
103
119
|
attributes: {
|
104
120
|
type: :object,
|
105
121
|
properties: {
|
106
|
-
<% attributes.
|
107
|
-
<%= attr %>: { type: :<%= columns_with_comment[attr][:type] %>, description: '<%= columns_with_comment[attr][:comment] %>'},
|
122
|
+
<% attributes.each_key.each do |attr| -%>
|
123
|
+
<%= attr %>: { type: :<%= columns_with_comment[attr][:type] %>, <%if columns_with_comment[attr][:is_array] -%> items: { type: :<%= columns_with_comment[attr][:items_type] %>},<% end -%> 'x-nullable': <%= columns_with_comment[attr][:nullable] %>, description: '<%= columns_with_comment[attr][:comment] %>'},
|
108
124
|
<% end -%>
|
109
125
|
},
|
110
126
|
description: '属性'
|
@@ -129,22 +145,19 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
129
145
|
description: '相关<%= relation_name_camelize %>'
|
130
146
|
},
|
131
147
|
<% end -%>
|
132
|
-
|
133
|
-
|
134
|
-
|
135
148
|
},
|
136
149
|
description: '关联数据'
|
137
150
|
}
|
138
|
-
},
|
139
151
|
},
|
140
152
|
description: '数据'
|
141
153
|
},
|
142
154
|
},
|
143
155
|
required: [:data]
|
156
|
+
let(:id) { @<%= model_name %>.id }
|
144
157
|
run_test!
|
145
158
|
end
|
146
159
|
end
|
147
160
|
end
|
148
|
-
<%
|
161
|
+
<% unless resource_klass.immutable -%>
|
149
162
|
<% end -%>
|
150
163
|
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.2.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: 2019-04-
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|