mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-22 22:26:41 +00:00
Allows custom meta for response
This commit is contained in:
parent
d2f3c8f2c2
commit
e5229586af
@ -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
|
||||
|
||||
@ -3,14 +3,16 @@ module Schemable
|
||||
attr_accessor orm: Symbol
|
||||
attr_accessor float_as_string: bool
|
||||
attr_accessor decimal_as_string: bool
|
||||
attr_accessor pagination_enabled: bool
|
||||
attr_accessor disable_factory_bot: 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_suffix_for_simple_enum: String?
|
||||
attr_accessor custom_defined_enum_method: Symbol?
|
||||
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 custom_meta_response_schema: Hash[Symbol, any]?
|
||||
attr_accessor infer_attributes_from_jsonapi_serializable: bool
|
||||
|
||||
|
||||
def initialize: -> void
|
||||
|
||||
@ -3,6 +3,7 @@ module Schemable
|
||||
attr_reader model: Class
|
||||
attr_reader model_definition: Definition
|
||||
attr_reader schema_modifier: SchemaModifier
|
||||
attr_reader configuration: Configuration
|
||||
|
||||
def initialize: (Definition) -> void
|
||||
def meta: -> Hash[Symbol, any]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user