mirror of
https://github.com/ditkrg/jsonapi-swagger.git
synced 2026-01-22 22:06:50 +00:00
add filter field
This commit is contained in:
parent
bd3db5e85e
commit
e807339d29
@ -50,6 +50,10 @@ module Jsonapi
|
|||||||
resource_klass._relationships
|
resource_klass._relationships
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filters
|
||||||
|
resource_klass.filters
|
||||||
|
end
|
||||||
|
|
||||||
def columns_with_comment
|
def columns_with_comment
|
||||||
@columns_with_comment ||= {}.tap do |clos|
|
@columns_with_comment ||= {}.tap do |clos|
|
||||||
model_klass.columns.each do |col|
|
model_klass.columns.each do |col|
|
||||||
@ -60,6 +64,7 @@ module Jsonapi
|
|||||||
|
|
||||||
def swagger_type(column)
|
def swagger_type(column)
|
||||||
return 'array' if column.array
|
return 'array' if column.array
|
||||||
|
|
||||||
case column.type
|
case column.type
|
||||||
when :bigint, :integer then 'integer'
|
when :bigint, :integer then 'integer'
|
||||||
when :boolean then 'boolean'
|
when :boolean then 'boolean'
|
||||||
|
|||||||
@ -12,6 +12,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|||||||
produces 'application/vnd.api+json'
|
produces 'application/vnd.api+json'
|
||||||
parameter name: :'page[number]', in: :query, type: :string, description: '<%= t(:page_num) %>', required: false
|
parameter name: :'page[number]', in: :query, type: :string, description: '<%= t(:page_num) %>', required: false
|
||||||
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
|
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
|
||||||
|
<% filters.each do |filter_attr, filter_config| -%>
|
||||||
|
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
|
||||||
|
<% end -%>
|
||||||
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
||||||
<% relationships.each_value do |relation| -%>
|
<% relationships.each_value do |relation| -%>
|
||||||
parameter name: :'fields[<%= relation.class_name.tableize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false
|
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
|
|||||||
type: :object,
|
type: :object,
|
||||||
properties: {
|
properties: {
|
||||||
<% attributes.each_key.each do |attr| -%>
|
<% attributes.each_key.each do |attr| -%>
|
||||||
<%= 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] %>'},
|
<%= 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] %>'},
|
||||||
<% end -%>
|
<% end -%>
|
||||||
},
|
},
|
||||||
description: '<%= t(:attributes) %>'
|
description: '<%= t(:attributes) %>'
|
||||||
@ -120,7 +123,7 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|||||||
type: :object,
|
type: :object,
|
||||||
properties: {
|
properties: {
|
||||||
<% attributes.each_key.each do |attr| -%>
|
<% attributes.each_key.each do |attr| -%>
|
||||||
<%= 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] %>'},
|
<%= 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] %>'},
|
||||||
<% end -%>
|
<% end -%>
|
||||||
},
|
},
|
||||||
description: '<%= t(:attributes) %>'
|
description: '<%= t(:attributes) %>'
|
||||||
|
|||||||
@ -3,6 +3,7 @@ en:
|
|||||||
page_num: 'Page Number'
|
page_num: 'Page Number'
|
||||||
include_related_data: 'Include Related Data'
|
include_related_data: 'Include Related Data'
|
||||||
display_field: 'Display Field'
|
display_field: 'Display Field'
|
||||||
|
filter_field: 'Filter Field'
|
||||||
list: 'List'
|
list: 'List'
|
||||||
get_list: 'Fetch List'
|
get_list: 'Fetch List'
|
||||||
detail_link: 'Detail Link'
|
detail_link: 'Detail Link'
|
||||||
|
|||||||
@ -3,6 +3,7 @@ zh-CN:
|
|||||||
page_num: '页码'
|
page_num: '页码'
|
||||||
include_related_data: '包含关联数据'
|
include_related_data: '包含关联数据'
|
||||||
display_field: '显示字段'
|
display_field: '显示字段'
|
||||||
|
filter_field: '过滤字段'
|
||||||
list: '列表'
|
list: '列表'
|
||||||
get_list: '获取列表'
|
get_list: '获取列表'
|
||||||
detail_link: '详情链接'
|
detail_link: '详情链接'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user