jsonapi-swagger 0.2.0 → 0.3.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: 8cfab1114fff50d85a5e1a794431587a8f6275e2dbcd2343b4ae4a527ae379e1
4
- data.tar.gz: 535abfa4b0960bcaa7f752d30d64f7ba255306bd5652cb522088137754146f65
3
+ metadata.gz: 2451e820082b9b97f3ec0d6ba3fbf9d7f8bb17276a8b99ddd1901f60ccc7d214
4
+ data.tar.gz: aacdea086604b346aa42d022478b8e088bd38f97d91c5b861be7593469eb8f10
5
5
  SHA512:
6
- metadata.gz: f1846b3909f1fe9948e5e213818df33f763c9c75be9d055ba96149d6bb1f346a4cc1566b5e5b5270d9bb6a1934c03f4411470d48ecf662f5314b8306b77666af
7
- data.tar.gz: 204262395c367fab8a0eb6febed30c4420a7bc8191aa872977c087418bd4b0c3bed08739325681a275fa2ddf664eedfa4f51f3520035b0ab53bfc26a82f67181
6
+ metadata.gz: 9dc72e490d688a7e84e87aed24f3c3071e0aea054eb3a4a5171532841f2f95cf715a278814767bf2ebe25be529a9cc2cff0c07ea38999215404badd750e44bfc
7
+ data.tar.gz: 512a1a4ec818091f046e22a4cf3d95a14c5d6081940d8be1dc12e148ff515da8ba6a5af08e34beb0c3b1946497aee3268e26ed80bbfea722860b9cb34b6640b4
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Create a JSONAPI Swagger
3
+
4
+ Example:
5
+ rails generate jsonapi:swagger User
6
+
7
+ This will create:
8
+ spec/requests/users_spec.rb
@@ -67,8 +67,15 @@ module Jsonapi
67
67
  end
68
68
  end
69
69
 
70
- def safe_encode(comment)
71
- comment&.force_encoding('ASCII-8BIT')
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: '页码', required: false
14
- parameter name: :include, in: :query, type: :string, description: '包含关联数据', required: false
15
- parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '包含字段', required: false
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: '包含字段', required: false
17
+ parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
18
18
  <% end -%>
19
- response '200', '获取列表' do
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: '关联<%= relation_name_camelize %>列表链接' },
56
- related: { type: :string, description: '相关<%= relation_name_camelize %>链接' },
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: '相关的<%= relation_name_camelize %>链接'
58
+ description: '<%= t(:related_link, model: relation_name_camelize)%>'
59
59
  },
60
60
  },
61
- description: '相关<%= relation_name_camelize %>'
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 %>详情' do
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: '包含关联数据', required: false
100
- parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '包含字段', required: false
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: '包含字段', required: false
102
+ parameter name: :'fields[<%= relation.to_s.pluralize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
103
103
  <% end -%>
104
- response '200', '获取详情' do
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: '关联<%= relation_name_camelize %>列表链接' },
140
- related: { type: :string, description: '相关<%= relation_name_camelize %>链接' },
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: '相关的<%= relation_name_camelize %>链接'
142
+ description: '<%= t(:related_link, model: relation_name_camelize) %>'
143
143
  },
144
144
  },
145
- description: '相关<%= relation_name_camelize %>'
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'
@@ -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: '详情链接'
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jsonapi/swagger/version'
4
+ require 'jsonapi/swagger/railtie' if defined?(Rails)
4
5
 
5
6
  module Jsonapi
6
7
  module Swagger
7
8
  class Error < StandardError; end
8
- # Your code goes here...
9
9
  end
10
10
  end
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jsonapi
4
4
  module Swagger
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  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.2.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-22 00:00:00.000000000 Z
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: