support sortable fields

This commit is contained in:
YingRui Lu 2019-05-08 14:01:34 +08:00
parent 17a263a9d1
commit 4ca14d7cdf
4 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,10 @@ module Jsonapi
(class_path + [file_name]).map!(&:camelize).join("::")
end
def sortable_feilds_desc
t(:sortable_fields) + ': [-]' + sortable_fields.join(',')
end
def model_klass
model_class_name.safe_constantize
end
@ -50,6 +54,10 @@ module Jsonapi
resource_klass._relationships
end
def sortable_fields
resource_klass.sortable_fields
end
def filters
resource_klass.filters
end

View File

@ -11,6 +11,9 @@ RSpec.describe '<%= resouces_name %>', type: :request do
tags '<%= route_resouces %>'
produces 'application/vnd.api+json'
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? -%>
parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false
<% end -%>

View File

@ -2,6 +2,7 @@ en:
jsonapi_swagger:
page_num: 'Page Number'
include_related_data: 'Include Related Data'
sortable_fields: 'Sortable Fields'
display_field: 'Display Field'
filter_field: 'Filter Field'
list: 'List'

View File

@ -2,6 +2,7 @@ zh-CN:
jsonapi_swagger:
page_num: '页码'
include_related_data: '包含关联数据'
sortable_fields: '排序字段'
display_field: '显示字段'
filter_field: '过滤字段'
list: '列表'