mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-22 22:26:41 +00:00
Updates method names and generate_attributes_schema's logic
This commit is contained in:
parent
213fecefd2
commit
15fae701b5
@ -11,21 +11,27 @@ module Schemable
|
||||
end
|
||||
|
||||
# Generate the JSON schema for attributes
|
||||
def generate_attribute_schema
|
||||
def generate_attributes_schema
|
||||
schema = {
|
||||
type: :object,
|
||||
properties: {}
|
||||
properties: attributes.index_with do |attr|
|
||||
generate_attribute_schema(attr)
|
||||
end
|
||||
}
|
||||
|
||||
@model.attribute_names.each do |attribute|
|
||||
schema[:properties][attribute.to_sym] = generate_property_schema(attribute)
|
||||
# modify the schema to include additional response relations
|
||||
schema = @schema_modifier.add_properties(schema, @model_definition.additional_response_attributes, 'properties')
|
||||
|
||||
# modify the schema to exclude response relations
|
||||
@model_definition.excluded_response_attributes.each do |key|
|
||||
schema = @schema_modifier.delete_properties(schema, "properties.#{key}")
|
||||
end
|
||||
|
||||
schema
|
||||
end
|
||||
|
||||
# Generate the JSON schema for a specific attribute
|
||||
def generate_property_schema(attribute)
|
||||
def generate_attribute_schema(attribute)
|
||||
if @configuration.orm == :mongoid
|
||||
# Get the column hash for the attribute
|
||||
attribute_hash = @model.fields[attribute.to_s]
|
||||
|
||||
@ -7,8 +7,8 @@ module Schemable
|
||||
attr_accessor schema_modifier: SchemaModifier
|
||||
|
||||
def initialize: (Definition, Configuration) -> void
|
||||
def generate_attribute_schema: -> Hash[Symbol, any]
|
||||
def generate_attributes_schema: -> (Hash[Symbol, any] | Array[any])
|
||||
|
||||
def generate_property_schema: (Symbol) -> Hash[Symbol, any]
|
||||
def generate_attribute_schema: (Symbol) -> Hash[Symbol, any]
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user