mirror of
https://github.com/ditkrg/jsonapi-swagger.git
synced 2026-01-22 13:56:54 +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("::")
|
||||
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
|
||||
|
||||
@ -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 -%>
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -2,6 +2,7 @@ zh-CN:
|
||||
jsonapi_swagger:
|
||||
page_num: '页码'
|
||||
include_related_data: '包含关联数据'
|
||||
sortable_fields: '排序字段'
|
||||
display_field: '显示字段'
|
||||
filter_field: '过滤字段'
|
||||
list: '列表'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user