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