jsonapi-swagger 0.2.0 → 0.3.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/USAGE +8 -0
- data/lib/generators/jsonapi/swagger/swagger_generator.rb +9 -2
- data/lib/generators/jsonapi/swagger/templates/swagger.rb.erb +36 -36
- data/lib/i18n/en.yml +24 -0
- data/lib/i18n/zh-CN.yml +24 -0
- data/lib/jsonapi/swagger.rb +1 -1
- data/lib/jsonapi/swagger/railtie.rb +16 -0
- data/lib/jsonapi/swagger/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2451e820082b9b97f3ec0d6ba3fbf9d7f8bb17276a8b99ddd1901f60ccc7d214
|
4
|
+
data.tar.gz: aacdea086604b346aa42d022478b8e088bd38f97d91c5b861be7593469eb8f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dc72e490d688a7e84e87aed24f3c3071e0aea054eb3a4a5171532841f2f95cf715a278814767bf2ebe25be529a9cc2cff0c07ea38999215404badd750e44bfc
|
7
|
+
data.tar.gz: 512a1a4ec818091f046e22a4cf3d95a14c5d6081940d8be1dc12e148ff515da8ba6a5af08e34beb0c3b1946497aee3268e26ed80bbfea722860b9cb34b6640b4
|
@@ -67,8 +67,15 @@ module Jsonapi
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
71
|
-
|
70
|
+
def t(key, options={})
|
71
|
+
options[:scope] = :jsonapi_swagger
|
72
|
+
options[:default] = key.to_s.humanize
|
73
|
+
content = I18n.t(key, options)
|
74
|
+
safe_encode(content)
|
75
|
+
end
|
76
|
+
|
77
|
+
def safe_encode(content)
|
78
|
+
content&.force_encoding('ASCII-8BIT')
|
72
79
|
end
|
73
80
|
end
|
74
81
|
end
|
@@ -7,16 +7,16 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
path '/<%= route_resouces %>' do
|
10
|
-
get '<%= route_resouces %>' do
|
10
|
+
get '<%= route_resouces %> <%= t(:list) %>' do
|
11
11
|
tags '<%= route_resouces %>'
|
12
12
|
produces 'application/vnd.api+json'
|
13
|
-
parameter name: :'page[number]', in: :query, type: :string, description: '
|
14
|
-
parameter name: :include, in: :query, type: :string, description: '
|
15
|
-
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '
|
13
|
+
parameter name: :'page[number]', in: :query, type: :string, description: '<%= t(:page_num) %>', required: false
|
14
|
+
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
|
15
|
+
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
16
16
|
<% relationships.each_key do |relation| -%>
|
17
|
-
parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '
|
17
|
+
parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
18
18
|
<% end -%>
|
19
|
-
response '200', '
|
19
|
+
response '200', '<%= t(:get_list) %>' do
|
20
20
|
schema type: :object,
|
21
21
|
properties: {
|
22
22
|
data: {
|
@@ -28,9 +28,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
28
28
|
links: {
|
29
29
|
type: :object,
|
30
30
|
properties: {
|
31
|
-
self: { type: :string, description: '
|
31
|
+
self: { type: :string, description: '<%= t(:detail_link) %>'},
|
32
32
|
},
|
33
|
-
description: '
|
33
|
+
description: '<%= t(:detail_link) %>'
|
34
34
|
},
|
35
35
|
attributes: {
|
36
36
|
type: :object,
|
@@ -39,7 +39,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
39
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] %>'},
|
40
40
|
<% end -%>
|
41
41
|
},
|
42
|
-
description: '
|
42
|
+
description: '<%= t(:attributes) %>'
|
43
43
|
},
|
44
44
|
relationships: {
|
45
45
|
type: :object,
|
@@ -52,38 +52,38 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
52
52
|
links: {
|
53
53
|
type: :object,
|
54
54
|
properties: {
|
55
|
-
self: { type: :string, description: '
|
56
|
-
related: { type: :string, description: '
|
55
|
+
self: { type: :string, description: '<%= t(:associate_list_link, model: relation_name_camelize) %>' },
|
56
|
+
related: { type: :string, description: '<%= t(:related_link, model: relation_name_camelize) %>' },
|
57
57
|
},
|
58
|
-
description: '
|
58
|
+
description: '<%= t(:related_link, model: relation_name_camelize)%>'
|
59
59
|
},
|
60
60
|
},
|
61
|
-
description: '
|
61
|
+
description: '<%= t(:related_model, model: relation_name_camelize)%>'
|
62
62
|
},
|
63
63
|
<% end -%>
|
64
64
|
},
|
65
|
-
description: '
|
65
|
+
description: '<%= t(:associate_data) %>'
|
66
66
|
}
|
67
67
|
},
|
68
68
|
},
|
69
|
-
description: '
|
69
|
+
description: '<%= t(:data) %>'
|
70
70
|
},
|
71
71
|
meta: {
|
72
72
|
type: :object,
|
73
73
|
properties: {
|
74
|
-
record_count: { type: :integer, description: '
|
75
|
-
page_count: { type: :integer, description: '
|
74
|
+
record_count: { type: :integer, description: '<%= t(:record_count) %>'},
|
75
|
+
page_count: { type: :integer, description: '<%= t(:page_count) %>'},
|
76
76
|
},
|
77
|
-
description: '
|
77
|
+
description: '<%= t(:meta) %>'
|
78
78
|
},
|
79
79
|
links: {
|
80
80
|
type: :object,
|
81
81
|
properties: {
|
82
|
-
first: { type: :string, description: '
|
83
|
-
next: { type: :string, description: '
|
84
|
-
last: { type: :string, description: '
|
82
|
+
first: { type: :string, description: '<%= t(:first_page_link) %>'},
|
83
|
+
next: { type: :string, description: '<%= t(:next_page_link) %>'},
|
84
|
+
last: { type: :string, description: '<%= t(:last_page_link) %>'},
|
85
85
|
},
|
86
|
-
description: '
|
86
|
+
description: '<%= t(:page_links) %>' },
|
87
87
|
},
|
88
88
|
required: [:data]
|
89
89
|
run_test!
|
@@ -92,16 +92,16 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
path '/<%= route_resouces %>/{id}' do
|
95
|
-
get '<%= route_resouces
|
95
|
+
get '<%= route_resouces %> <%= t(:detail) %>' do
|
96
96
|
tags '<%= route_resouces %>'
|
97
97
|
produces 'application/vnd.api+json'
|
98
98
|
parameter name: :id, in: :path, type: :integer, description: 'ID', required: true
|
99
|
-
parameter name: :include, in: :query, type: :string, description: '
|
100
|
-
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '
|
99
|
+
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
|
100
|
+
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
101
101
|
<% relationships.each_key do |relation| -%>
|
102
|
-
parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '
|
102
|
+
parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
103
103
|
<% end -%>
|
104
|
-
response '200', '
|
104
|
+
response '200', '<%= t(:get_detail) %>' do
|
105
105
|
schema type: :object,
|
106
106
|
properties: {
|
107
107
|
data: {
|
@@ -112,9 +112,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
112
112
|
links: {
|
113
113
|
type: :object,
|
114
114
|
properties: {
|
115
|
-
self: { type: :string, description: '
|
115
|
+
self: { type: :string, description: '<%= t(:detail_link) %>'},
|
116
116
|
},
|
117
|
-
description: '
|
117
|
+
description: '<%= t(:detail_link) %>'
|
118
118
|
},
|
119
119
|
attributes: {
|
120
120
|
type: :object,
|
@@ -123,7 +123,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
123
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] %>'},
|
124
124
|
<% end -%>
|
125
125
|
},
|
126
|
-
description: '
|
126
|
+
description: '<%= t(:attributes) %>'
|
127
127
|
},
|
128
128
|
relationships: {
|
129
129
|
type: :object,
|
@@ -136,20 +136,20 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|
136
136
|
links: {
|
137
137
|
type: :object,
|
138
138
|
properties: {
|
139
|
-
self: { type: :string, description: '
|
140
|
-
related: { type: :string, description: '
|
139
|
+
self: { type: :string, description: '<%= t(:associate_list_link, model: relation_name_camelize) %>' },
|
140
|
+
related: { type: :string, description: '<%= t(:related_link, model: relation_name_camelize )%>' },
|
141
141
|
},
|
142
|
-
description: '
|
142
|
+
description: '<%= t(:related_link, model: relation_name_camelize) %>'
|
143
143
|
},
|
144
144
|
},
|
145
|
-
description: '
|
145
|
+
description: '<%= t(:related_link, model: relation_name_camelize) %>'
|
146
146
|
},
|
147
147
|
<% end -%>
|
148
148
|
},
|
149
|
-
description: '
|
149
|
+
description: '<%= t(:associate_data) %>'
|
150
150
|
}
|
151
151
|
},
|
152
|
-
description: '
|
152
|
+
description: '<%= t(:data) %>'
|
153
153
|
},
|
154
154
|
},
|
155
155
|
required: [:data]
|
data/lib/i18n/en.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
en:
|
2
|
+
jsonapi_swagger:
|
3
|
+
page_num: 'Page Number'
|
4
|
+
include_related_data: 'Include Related Data'
|
5
|
+
display_field: 'Display Field'
|
6
|
+
list: 'List'
|
7
|
+
get_list: 'Fetch List'
|
8
|
+
detail_link: 'Detail Link'
|
9
|
+
attributes: 'Attributes'
|
10
|
+
associate_list_link: 'Associate to %{model} Link'
|
11
|
+
related_link: 'Related %{model} Link'
|
12
|
+
related_model: 'Related %{model}'
|
13
|
+
associate_data: 'Associate to Date'
|
14
|
+
data: 'Data'
|
15
|
+
record_count: 'Total Record Count'
|
16
|
+
page_count: 'Page Count'
|
17
|
+
meta: 'Meta'
|
18
|
+
first_page_link: 'First Page'
|
19
|
+
next_page_link: 'Next Page'
|
20
|
+
last_page_link: 'Last Page'
|
21
|
+
page_links: 'Page Link'
|
22
|
+
detail: 'Detail'
|
23
|
+
get_dtail: 'Fetch Detail'
|
24
|
+
detail_link: 'Detail Link'
|
data/lib/i18n/zh-CN.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
zh-CN:
|
2
|
+
jsonapi_swagger:
|
3
|
+
page_num: '页码'
|
4
|
+
include_related_data: '包含关联数据'
|
5
|
+
display_field: '显示字段'
|
6
|
+
list: '列表'
|
7
|
+
get_list: '获取列表'
|
8
|
+
detail_link: '详情链接'
|
9
|
+
attributes: '属性'
|
10
|
+
associate_list_link: '关联%{model}链接'
|
11
|
+
related_link: '相关%{model}链接'
|
12
|
+
related_model: '相关%{model}'
|
13
|
+
associate_data: '关联数据'
|
14
|
+
data: '数据'
|
15
|
+
record_count: '总记录数'
|
16
|
+
page_count: '页数'
|
17
|
+
meta: '元数据'
|
18
|
+
first_page_link: '第一页链接'
|
19
|
+
next_page_link: '下一页链接'
|
20
|
+
last_page_link: '最后一页链接'
|
21
|
+
page_links: '分页链接'
|
22
|
+
detail: '详情'
|
23
|
+
get_dtail: '获取详情'
|
24
|
+
detail_link: '详情链接'
|
data/lib/jsonapi/swagger.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsonapi
|
4
|
+
module Swagger
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer 'jsonapi-swagger-i18n' do |app|
|
7
|
+
locates = app.config.i18n.available_locales
|
8
|
+
locates_dir = File.expand_path('../../i18n', __dir__)
|
9
|
+
locates.each do |loc|
|
10
|
+
locate_file = File.join(locates_dir, "#{loc}.yml")
|
11
|
+
I18n.load_path.push(locate_file) if File.exist?(locate_file) && !I18n.load_path.include?(locate_file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.3.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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,7 +77,10 @@ files:
|
|
77
77
|
- lib/generators/jsonapi/swagger/USAGE
|
78
78
|
- lib/generators/jsonapi/swagger/swagger_generator.rb
|
79
79
|
- lib/generators/jsonapi/swagger/templates/swagger.rb.erb
|
80
|
+
- lib/i18n/en.yml
|
81
|
+
- lib/i18n/zh-CN.yml
|
80
82
|
- lib/jsonapi/swagger.rb
|
83
|
+
- lib/jsonapi/swagger/railtie.rb
|
81
84
|
- lib/jsonapi/swagger/version.rb
|
82
85
|
homepage: https://github.com/superiorlu/jsonapi-swagger
|
83
86
|
licenses:
|