From 6908df347aac88d69068916457b79d5bb8ee923d Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Fri, 17 Nov 2023 16:11:20 +0300 Subject: [PATCH] Ensures type safety --- lib/schemable/definition.rb | 2 +- sig/schemable/definition.rbs | 2 +- sig/schemable/included_schema_generator.rbs | 4 +--- sig/schemable/relationship_schema_generator.rbs | 4 +--- sig/schemable/request_schema_generator.rbs | 4 ++-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/schemable/definition.rb b/lib/schemable/definition.rb index ad159ee..0768f9f 100644 --- a/lib/schemable/definition.rb +++ b/lib/schemable/definition.rb @@ -297,7 +297,7 @@ module Schemable # # @param hash [Hash] The hash with all the keys camelized. # - # @return [Hash] The hash with all the keys camelized. + # @return [Hash, Array] The hash with all the keys camelized. # # @example # { first_name: 'John', last_name: 'Doe' } => { firstName: 'John', lastName: 'Doe' } diff --git a/sig/schemable/definition.rbs b/sig/schemable/definition.rbs index a159d12..18db060 100644 --- a/sig/schemable/definition.rbs +++ b/sig/schemable/definition.rbs @@ -25,8 +25,8 @@ module Schemable def excluded_update_request_attributes: -> Array[Symbol] def optional_create_request_attributes: -> Array[Symbol] def optional_update_request_attributes: -> Array[Symbol] - def camelize_keys: (Hash[Symbol, any]) -> (Hash[Symbol, any]) def additional_create_request_attributes: -> Hash[Symbol, any] def additional_update_request_attributes: -> Hash[Symbol, any] + def camelize_keys: (Hash[Symbol, any]) -> (Array[Hash[Symbol, any]] | Hash[Symbol, any]) end end diff --git a/sig/schemable/included_schema_generator.rbs b/sig/schemable/included_schema_generator.rbs index 6677d99..616b146 100644 --- a/sig/schemable/included_schema_generator.rbs +++ b/sig/schemable/included_schema_generator.rbs @@ -5,9 +5,7 @@ module Schemable attr_reader relationships: Hash[Symbol, any] def initialize: (Definition) -> void - + def generate: (?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> (Hash[Symbol, any]) def prepare_schema_for_included: (Definition, ?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> Hash[Symbol, any] - - def generate: (?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> (Hash[Symbol, any] | Array[Hash[Symbol, any]]) end end diff --git a/sig/schemable/relationship_schema_generator.rbs b/sig/schemable/relationship_schema_generator.rbs index b82bcb1..8d21c70 100644 --- a/sig/schemable/relationship_schema_generator.rbs +++ b/sig/schemable/relationship_schema_generator.rbs @@ -5,9 +5,7 @@ module Schemable attr_reader relationships: Hash[Symbol, any] def initialize: (Definition) -> void - - def generate: (?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> (Hash[Symbol, any] | Array[Hash[Symbol, any]]) - def generate_schema: (String, ?collection: bool) -> Hash[Symbol, any] + def generate: (?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> (Hash[Symbol, any]) end end diff --git a/sig/schemable/request_schema_generator.rbs b/sig/schemable/request_schema_generator.rbs index c6a99b0..64b719b 100644 --- a/sig/schemable/request_schema_generator.rbs +++ b/sig/schemable/request_schema_generator.rbs @@ -4,7 +4,7 @@ module Schemable attr_reader schema_modifier: SchemaModifier def initialize: (Definition) -> void - def generate_for_create: () -> (Hash[Symbol, any] | Array[Hash[Symbol, any]]) - def generate_for_update: () -> (Hash[Symbol, any] | Array[Hash[Symbol, any]]) + def generate_for_create: () -> (Hash[Symbol, any]) + def generate_for_update: () -> (Hash[Symbol, any]) end end