Skip to content

Commit e807339

Browse files
author
YingRui Lu
committed
add filter field
1 parent bd3db5e commit e807339

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/generators/jsonapi/swagger/swagger_generator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def relationships
5050
resource_klass._relationships
5151
end
5252

53+
def filters
54+
resource_klass.filters
55+
end
56+
5357
def columns_with_comment
5458
@columns_with_comment ||= {}.tap do |clos|
5559
model_klass.columns.each do |col|
@@ -60,6 +64,7 @@ def columns_with_comment
6064

6165
def swagger_type(column)
6266
return 'array' if column.array
67+
6368
case column.type
6469
when :bigint, :integer then 'integer'
6570
when :boolean then 'boolean'

lib/generators/jsonapi/swagger/templates/swagger.rb.erb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
1212
produces 'application/vnd.api+json'
1313
parameter name: :'page[number]', in: :query, type: :string, description: '<%= t(:page_num) %>', required: false
1414
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
15+
<% filters.each do |filter_attr, filter_config| -%>
16+
parameter name: :'filter[<%= filter_attr %>]', in: :query, type: :string, description: '<%= t(:filter_field) %>', <% if filter_config[:default] -%>default: '<%= safe_encode(filter_config[:default]) %>',<% end %>required: false
17+
<% end -%>
1518
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
1619
<% relationships.each_value do |relation| -%>
1720
parameter name: :'fields[<%= relation.class_name.tableize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
@@ -36,7 +39,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
3639
type: :object,
3740
properties: {
3841
<% 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] %>'},
42+
<%= 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] %>'},
4043
<% end -%>
4144
},
4245
description: '<%= t(:attributes) %>'
@@ -120,7 +123,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
120123
type: :object,
121124
properties: {
122125
<% 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] %>'},
126+
<%= 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] %>'},
124127
<% end -%>
125128
},
126129
description: '<%= t(:attributes) %>'

lib/i18n/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ en:
33
page_num: 'Page Number'
44
include_related_data: 'Include Related Data'
55
display_field: 'Display Field'
6+
filter_field: 'Filter Field'
67
list: 'List'
78
get_list: 'Fetch List'
89
detail_link: 'Detail Link'

lib/i18n/zh-CN.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ zh-CN:
33
page_num: '页码'
44
include_related_data: '包含关联数据'
55
display_field: '显示字段'
6+
filter_field: '过滤字段'
67
list: '列表'
78
get_list: '获取列表'
89
detail_link: '详情链接'

0 commit comments

Comments
 (0)