mirror of
https://github.com/ditkrg/jsonapi-swagger.git
synced 2026-01-22 22:06:50 +00:00
support sortable fields
This commit is contained in:
parent
17a263a9d1
commit
4ca14d7cdf
@ -34,6 +34,10 @@ module Jsonapi
|
|||||||
(class_path + [file_name]).map!(&:camelize).join("::")
|
(class_path + [file_name]).map!(&:camelize).join("::")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sortable_feilds_desc
|
||||||
|
t(:sortable_fields) + ': [-]' + sortable_fields.join(',')
|
||||||
|
end
|
||||||
|
|
||||||
def model_klass
|
def model_klass
|
||||||
model_class_name.safe_constantize
|
model_class_name.safe_constantize
|
||||||
end
|
end
|
||||||
@ -50,6 +54,10 @@ module Jsonapi
|
|||||||
resource_klass._relationships
|
resource_klass._relationships
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sortable_fields
|
||||||
|
resource_klass.sortable_fields
|
||||||
|
end
|
||||||
|
|
||||||
def filters
|
def filters
|
||||||
resource_klass.filters
|
resource_klass.filters
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,6 +11,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
|
|||||||
tags '<%= route_resouces %>'
|
tags '<%= route_resouces %>'
|
||||||
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
|
||||||
|
<% if sortable_fields.present? -%>
|
||||||
|
parameter name: :'sort', in: :query, type: :string, description: '<%= sortable_feilds_desc %>', required: false
|
||||||
|
<% end -%>
|
||||||
<% if relationships.present? -%>
|
<% if relationships.present? -%>
|
||||||
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
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|||||||
@ -2,6 +2,7 @@ en:
|
|||||||
jsonapi_swagger:
|
jsonapi_swagger:
|
||||||
page_num: 'Page Number'
|
page_num: 'Page Number'
|
||||||
include_related_data: 'Include Related Data'
|
include_related_data: 'Include Related Data'
|
||||||
|
sortable_fields: 'Sortable Fields'
|
||||||
display_field: 'Display Field'
|
display_field: 'Display Field'
|
||||||
filter_field: 'Filter Field'
|
filter_field: 'Filter Field'
|
||||||
list: 'List'
|
list: 'List'
|
||||||
|
|||||||
@ -2,6 +2,7 @@ zh-CN:
|
|||||||
jsonapi_swagger:
|
jsonapi_swagger:
|
||||||
page_num: '页码'
|
page_num: '页码'
|
||||||
include_related_data: '包含关联数据'
|
include_related_data: '包含关联数据'
|
||||||
|
sortable_fields: '排序字段'
|
||||||
display_field: '显示字段'
|
display_field: '显示字段'
|
||||||
filter_field: '过滤字段'
|
filter_field: '过滤字段'
|
||||||
list: '列表'
|
list: '列表'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user