Adds Camelize Keys Method to Definitions

This commit is contained in:
Muhammad Nawzad 2023-11-12 14:48:46 +03:00
parent 92d9f33d20
commit e25dfff4ec
No known key found for this signature in database
GPG Key ID: B954B6AAE33940B2
2 changed files with 14 additions and 0 deletions

View File

@ -95,5 +95,9 @@ module Schemable
def model_name
self.class.name.gsub('Swagger::Definitions::', '').pluralize.underscore.downcase
end
def camelize_keys(hash)
hash.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym }
end
end
end

View File

@ -247,5 +247,15 @@ module Schemable
# 'users' for the User model
# 'citizen_applications' for the CitizenApplication model
def model_name: -> String
# Given a hash, it returns a new hash with all the keys camelized.
#
# @param hash [Array | Hash] The hash with all the keys camelized.
#
# @return [Array | Hash] The hash with all the keys camelized.
#
# @example
# { first_name: 'John', last_name: 'Doe' } => { firstName: 'John', lastName: 'Doe' }
def camelize_keys: (Hash[Symbol, any]) -> (Hash[Symbol, any] | Array[Hash[Symbol, any]])
end
end