mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-25 07:36:40 +00:00
Allows custom meta for response
This commit is contained in:
@@ -9,12 +9,14 @@ module Schemable
|
||||
:orm,
|
||||
:float_as_string,
|
||||
:decimal_as_string,
|
||||
:pagination_enabled,
|
||||
:custom_type_mappers,
|
||||
:disable_factory_bot,
|
||||
:use_serialized_instance,
|
||||
:custom_defined_enum_method,
|
||||
:enum_prefix_for_simple_enum,
|
||||
:enum_suffix_for_simple_enum,
|
||||
:custom_meta_response_schema,
|
||||
:infer_attributes_from_custom_method,
|
||||
:infer_attributes_from_jsonapi_serializable
|
||||
)
|
||||
@@ -24,10 +26,12 @@ module Schemable
|
||||
@orm = :active_record # orm options are :active_record, :mongoid
|
||||
@float_as_string = false
|
||||
@custom_type_mappers = {}
|
||||
@pagination_enabled = true
|
||||
@decimal_as_string = false
|
||||
@disable_factory_bot = true
|
||||
@use_serialized_instance = false
|
||||
@custom_defined_enum_method = nil
|
||||
@custom_meta_response_schema = nil
|
||||
@enum_prefix_for_simple_enum = nil
|
||||
@enum_suffix_for_simple_enum = nil
|
||||
@infer_attributes_from_custom_method = nil
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
module Schemable
|
||||
class ResponseSchemaGenerator
|
||||
attr_reader :model_definition, :model, :schema_modifier
|
||||
attr_reader :model_definition, :model, :schema_modifier, :configuration
|
||||
|
||||
def initialize(model_definition)
|
||||
@model_definition = model_definition
|
||||
@model = model_definition.model
|
||||
@schema_modifier = SchemaModifier.new
|
||||
@configuration = Schemable.configuration
|
||||
end
|
||||
|
||||
def generate(expand: false, relationships_to_exclude_from_expansion: [], collection: false)
|
||||
@@ -38,32 +39,38 @@ module Schemable
|
||||
end
|
||||
|
||||
def meta
|
||||
{
|
||||
type: :object,
|
||||
properties: {
|
||||
page: {
|
||||
type: :object,
|
||||
properties: {
|
||||
totalPages: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
},
|
||||
count: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
},
|
||||
rowsPerPage: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
},
|
||||
currentPage: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
return @configuration.custom_meta_response_schema if @configuration.custom_meta_response_schema.present?
|
||||
|
||||
if @configuration.pagination_enabled
|
||||
{
|
||||
type: :object,
|
||||
properties: {
|
||||
page: {
|
||||
type: :object,
|
||||
properties: {
|
||||
totalPages: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
},
|
||||
count: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
},
|
||||
rowsPerPage: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
},
|
||||
currentPage: {
|
||||
type: :integer,
|
||||
default: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def jsonapi
|
||||
|
||||
Reference in New Issue
Block a user