From 5dfea141d20f1cebba6e22c1f22f9937f458386b Mon Sep 17 00:00:00 2001 From: Vishrut Shah Date: Thu, 16 Jun 2016 13:29:42 -0700 Subject: [PATCH] Ruby - Regenerating samples for ruby (#1179) --- .../models/check_name_availability_result.rb | 82 +++--- .../azure_storage/models/custom_domain.rb | 65 ++--- .../azure_storage/models/endpoints.rb | 91 +++--- .../azure_storage/models/storage_account.rb | 134 +++++---- ...ount_check_name_availability_parameters.rb | 68 ++--- .../storage_account_create_parameters.rb | 94 +++---- .../models/storage_account_keys.rb | 65 ++--- .../models/storage_account_list_result.rb | 93 +++---- .../models/storage_account_properties.rb | 229 +++++++-------- ...ge_account_properties_create_parameters.rb | 57 ++-- ...ge_account_properties_update_parameters.rb | 77 ++---- ...orage_account_regenerate_key_parameters.rb | 52 ++-- .../storage_account_update_parameters.rb | 80 +++--- .../Azure.Ruby/azure_storage/models/usage.rb | 109 +++----- .../azure_storage/models/usage_list_result.rb | 93 +++---- .../azure_storage/models/usage_name.rb | 65 ++--- .../azure_storage/storage_accounts.rb | 101 +++---- .../storage_management_client.rb | 5 +- .../azure_storage/usage_operations.rb | 6 +- .../petstore/Ruby/petstore/models/category.rb | 66 ++--- .../petstore/Ruby/petstore/models/order.rb | 122 ++++---- Samples/petstore/Ruby/petstore/models/pet.rb | 164 +++++------ Samples/petstore/Ruby/petstore/models/tag.rb | 66 ++--- Samples/petstore/Ruby/petstore/models/user.rb | 145 +++++----- .../Ruby/petstore/swagger_petstore.rb | 261 +++++++++++------- 25 files changed, 1060 insertions(+), 1330 deletions(-) diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/check_name_availability_result.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/check_name_availability_result.rb index 9b27165554aab..8770f93c77216 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/check_name_availability_result.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/check_name_availability_result.rb @@ -23,56 +23,44 @@ class CheckNameAvailabilityResult # more detail. attr_accessor :message - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for CheckNameAvailabilityResult class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.name_available - output_object['nameAvailable'] = serialized_property unless serialized_property.nil? - - serialized_property = object.reason - output_object['reason'] = serialized_property unless serialized_property.nil? - - serialized_property = object.message - output_object['message'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [CheckNameAvailabilityResult] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = CheckNameAvailabilityResult.new - - deserialized_property = object['nameAvailable'] - output_object.name_available = deserialized_property - - deserialized_property = object['reason'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = Reason.constants.any? { |e| Reason.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum Reason does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.reason = deserialized_property - - deserialized_property = object['message'] - output_object.message = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'CheckNameAvailabilityResult', + type: { + name: 'Composite', + class_name: 'CheckNameAvailabilityResult', + model_properties: { + name_available: { + required: false, + serialized_name: 'nameAvailable', + type: { + name: 'Boolean' + } + }, + reason: { + required: false, + serialized_name: 'reason', + type: { + name: 'Enum', + module: 'Reason' + } + }, + message: { + required: false, + serialized_name: 'message', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/custom_domain.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/custom_domain.rb index f58b3faad5d12..9965feb2f8919 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/custom_domain.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/custom_domain.rb @@ -18,47 +18,36 @@ class CustomDomain # enabled. Default value is false. This should only be set on updates attr_accessor :use_sub_domain - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property name is nil' if @name.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for CustomDomain class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.name - output_object['name'] = serialized_property unless serialized_property.nil? - - serialized_property = object.use_sub_domain - output_object['useSubDomain'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [CustomDomain] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = CustomDomain.new - - deserialized_property = object['name'] - output_object.name = deserialized_property - - deserialized_property = object['useSubDomain'] - output_object.use_sub_domain = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'CustomDomain', + type: { + name: 'Composite', + class_name: 'CustomDomain', + model_properties: { + name: { + required: true, + serialized_name: 'name', + type: { + name: 'String' + } + }, + use_sub_domain: { + required: false, + serialized_name: 'useSubDomain', + type: { + name: 'Boolean' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/endpoints.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/endpoints.rb index d936b4dae5047..f8670fba76e4d 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/endpoints.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/endpoints.rb @@ -22,59 +22,50 @@ class Endpoints # @return [String] Gets the file endpoint. attr_accessor :file - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - # Nothing to validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for Endpoints class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.blob - output_object['blob'] = serialized_property unless serialized_property.nil? - - serialized_property = object.queue - output_object['queue'] = serialized_property unless serialized_property.nil? - - serialized_property = object.table - output_object['table'] = serialized_property unless serialized_property.nil? - - serialized_property = object.file - output_object['file'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [Endpoints] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = Endpoints.new - - deserialized_property = object['blob'] - output_object.blob = deserialized_property - - deserialized_property = object['queue'] - output_object.queue = deserialized_property - - deserialized_property = object['table'] - output_object.table = deserialized_property - - deserialized_property = object['file'] - output_object.file = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'Endpoints', + type: { + name: 'Composite', + class_name: 'Endpoints', + model_properties: { + blob: { + required: false, + serialized_name: 'blob', + type: { + name: 'String' + } + }, + queue: { + required: false, + serialized_name: 'queue', + type: { + name: 'String' + } + }, + table: { + required: false, + serialized_name: 'table', + type: { + name: 'String' + } + }, + file: { + required: false, + serialized_name: 'file', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account.rb index f22d013ec87d7..f7877c5125526 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account.rb @@ -12,77 +12,75 @@ class StorageAccount < MsRestAzure::Resource # @return [StorageAccountProperties] attr_accessor :properties - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - @properties.validate unless @properties.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccount class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.id - output_object['id'] = serialized_property unless serialized_property.nil? - - serialized_property = object.name - output_object['name'] = serialized_property unless serialized_property.nil? - - serialized_property = object.type - output_object['type'] = serialized_property unless serialized_property.nil? - - serialized_property = object.location - output_object['location'] = serialized_property unless serialized_property.nil? - - serialized_property = object.tags - output_object['tags'] = serialized_property unless serialized_property.nil? - - serialized_property = object.properties - unless serialized_property.nil? - serialized_property = StorageAccountProperties.serialize_object(serialized_property) - end - output_object['properties'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccount] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccount.new - - deserialized_property = object['id'] - output_object.id = deserialized_property - - deserialized_property = object['name'] - output_object.name = deserialized_property - - deserialized_property = object['type'] - output_object.type = deserialized_property - - deserialized_property = object['location'] - output_object.location = deserialized_property - - deserialized_property = object['tags'] - output_object.tags = deserialized_property - - deserialized_property = object['properties'] - unless deserialized_property.nil? - deserialized_property = StorageAccountProperties.deserialize_object(deserialized_property) - end - output_object.properties = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccount', + type: { + name: 'Composite', + class_name: 'StorageAccount', + model_properties: { + id: { + required: false, + read_only: true, + serialized_name: 'id', + type: { + name: 'String' + } + }, + name: { + required: false, + read_only: true, + serialized_name: 'name', + type: { + name: 'String' + } + }, + type: { + required: false, + read_only: true, + serialized_name: 'type', + type: { + name: 'String' + } + }, + location: { + required: false, + serialized_name: 'location', + type: { + name: 'String' + } + }, + tags: { + required: false, + serialized_name: 'tags', + type: { + name: 'Dictionary', + value: { + required: false, + serialized_name: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + properties: { + required: false, + serialized_name: 'properties', + type: { + name: 'Composite', + class_name: 'StorageAccountProperties' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_check_name_availability_parameters.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_check_name_availability_parameters.rb index 8a2bdf9e61fb0..99d4c82433637 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_check_name_availability_parameters.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_check_name_availability_parameters.rb @@ -15,48 +15,38 @@ class StorageAccountCheckNameAvailabilityParameters # @return [String] Default value: 'Microsoft.Storage/storageAccounts' . attr_accessor :type - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property name is nil' if @name.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountCheckNameAvailabilityParameters class as Ruby + # Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.name - output_object['name'] = serialized_property unless serialized_property.nil? - - serialized_property = object.type - output_object['type'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountCheckNameAvailabilityParameters] Deserialized - # object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountCheckNameAvailabilityParameters.new - - deserialized_property = object['name'] - output_object.name = deserialized_property - - deserialized_property = object['type'] - output_object.type = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountCheckNameAvailabilityParameters', + type: { + name: 'Composite', + class_name: 'StorageAccountCheckNameAvailabilityParameters', + model_properties: { + name: { + required: true, + serialized_name: 'name', + type: { + name: 'String' + } + }, + type: { + required: false, + serialized_name: 'type', + default_value: 'Microsoft.Storage/storageAccounts', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_create_parameters.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_create_parameters.rb index 184376783ab6d..a05a8a891969e 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_create_parameters.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_create_parameters.rb @@ -18,61 +18,51 @@ class StorageAccountCreateParameters # @return [StorageAccountPropertiesCreateParameters] attr_accessor :properties - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property location is nil' if @location.nil? - @tags.each{ |e| e.validate if e.respond_to?(:validate) } unless @tags.nil? - @properties.validate unless @properties.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountCreateParameters class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.location - output_object['location'] = serialized_property unless serialized_property.nil? - - serialized_property = object.tags - output_object['tags'] = serialized_property unless serialized_property.nil? - - serialized_property = object.properties - unless serialized_property.nil? - serialized_property = StorageAccountPropertiesCreateParameters.serialize_object(serialized_property) - end - output_object['properties'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountCreateParameters] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountCreateParameters.new - - deserialized_property = object['location'] - output_object.location = deserialized_property - - deserialized_property = object['tags'] - output_object.tags = deserialized_property - - deserialized_property = object['properties'] - unless deserialized_property.nil? - deserialized_property = StorageAccountPropertiesCreateParameters.deserialize_object(deserialized_property) - end - output_object.properties = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountCreateParameters', + type: { + name: 'Composite', + class_name: 'StorageAccountCreateParameters', + model_properties: { + location: { + required: true, + serialized_name: 'location', + type: { + name: 'String' + } + }, + tags: { + required: false, + serialized_name: 'tags', + type: { + name: 'Dictionary', + value: { + required: false, + serialized_name: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + properties: { + required: false, + serialized_name: 'properties', + type: { + name: 'Composite', + class_name: 'StorageAccountPropertiesCreateParameters' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_keys.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_keys.rb index 7ac86fcf35ad5..731b30a8d420c 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_keys.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_keys.rb @@ -15,47 +15,36 @@ class StorageAccountKeys # @return [String] Gets the value of key 2. attr_accessor :key2 - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - # Nothing to validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountKeys class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.key1 - output_object['key1'] = serialized_property unless serialized_property.nil? - - serialized_property = object.key2 - output_object['key2'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountKeys] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountKeys.new - - deserialized_property = object['key1'] - output_object.key1 = deserialized_property - - deserialized_property = object['key2'] - output_object.key2 = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountKeys', + type: { + name: 'Composite', + class_name: 'StorageAccountKeys', + model_properties: { + key1: { + required: false, + serialized_name: 'key1', + type: { + name: 'String' + } + }, + key2: { + required: false, + serialized_name: 'key2', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_list_result.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_list_result.rb index 1b711341335b8..aa238721e7963 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_list_result.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_list_result.rb @@ -16,67 +16,44 @@ class StorageAccountListResult # @return [String] attr_accessor :next_link - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - @value.each{ |e| e.validate if e.respond_to?(:validate) } unless @value.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountListResult class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.value - unless serialized_property.nil? - serializedArray = [] - serialized_property.each do |element| - unless element.nil? - element = StorageAccount.serialize_object(element) - end - serializedArray.push(element) - end - serialized_property = serializedArray - end - output_object['value'] = serialized_property unless serialized_property.nil? - - serialized_property = object.next_link - output_object['nextLink'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountListResult] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountListResult.new - - deserialized_property = object['value'] - unless deserialized_property.nil? - deserialized_array = [] - deserialized_property.each do |element1| - unless element1.nil? - element1 = StorageAccount.deserialize_object(element1) - end - deserialized_array.push(element1) - end - deserialized_property = deserialized_array - end - output_object.value = deserialized_property - - deserialized_property = object['nextLink'] - output_object.next_link = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountListResult', + type: { + name: 'Composite', + class_name: 'StorageAccountListResult', + model_properties: { + value: { + required: false, + serialized_name: 'value', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'StorageAccountElementType', + type: { + name: 'Composite', + class_name: 'StorageAccount' + } + } + } + }, + next_link: { + required: false, + serialized_name: 'nextLink', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties.rb index 1004ba1b8e61c..4c2d957caf261 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties.rb @@ -65,141 +65,106 @@ class StorageAccountProperties # StandardRAGRS. attr_accessor :secondary_endpoints - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - @primary_endpoints.validate unless @primary_endpoints.nil? - @custom_domain.validate unless @custom_domain.nil? - @secondary_endpoints.validate unless @secondary_endpoints.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountProperties class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.provisioning_state - output_object['provisioningState'] = serialized_property unless serialized_property.nil? - - serialized_property = object.account_type - output_object['accountType'] = serialized_property unless serialized_property.nil? - - serialized_property = object.primary_endpoints - unless serialized_property.nil? - serialized_property = Endpoints.serialize_object(serialized_property) - end - output_object['primaryEndpoints'] = serialized_property unless serialized_property.nil? - - serialized_property = object.primary_location - output_object['primaryLocation'] = serialized_property unless serialized_property.nil? - - serialized_property = object.status_of_primary - output_object['statusOfPrimary'] = serialized_property unless serialized_property.nil? - - serialized_property = object.last_geo_failover_time - serialized_property = serialized_property.new_offset(0).strftime('%FT%TZ') - output_object['lastGeoFailoverTime'] = serialized_property unless serialized_property.nil? - - serialized_property = object.secondary_location - output_object['secondaryLocation'] = serialized_property unless serialized_property.nil? - - serialized_property = object.status_of_secondary - output_object['statusOfSecondary'] = serialized_property unless serialized_property.nil? - - serialized_property = object.creation_time - serialized_property = serialized_property.new_offset(0).strftime('%FT%TZ') - output_object['creationTime'] = serialized_property unless serialized_property.nil? - - serialized_property = object.custom_domain - unless serialized_property.nil? - serialized_property = CustomDomain.serialize_object(serialized_property) - end - output_object['customDomain'] = serialized_property unless serialized_property.nil? - - serialized_property = object.secondary_endpoints - unless serialized_property.nil? - serialized_property = Endpoints.serialize_object(serialized_property) - end - output_object['secondaryEndpoints'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountProperties] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountProperties.new - - deserialized_property = object['provisioningState'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = ProvisioningState.constants.any? { |e| ProvisioningState.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum ProvisioningState does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.provisioning_state = deserialized_property - - deserialized_property = object['accountType'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = AccountType.constants.any? { |e| AccountType.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum AccountType does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.account_type = deserialized_property - - deserialized_property = object['primaryEndpoints'] - unless deserialized_property.nil? - deserialized_property = Endpoints.deserialize_object(deserialized_property) - end - output_object.primary_endpoints = deserialized_property - - deserialized_property = object['primaryLocation'] - output_object.primary_location = deserialized_property - - deserialized_property = object['statusOfPrimary'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = AccountStatus.constants.any? { |e| AccountStatus.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum AccountStatus does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.status_of_primary = deserialized_property - - deserialized_property = object['lastGeoFailoverTime'] - deserialized_property = DateTime.parse(deserialized_property) unless deserialized_property.to_s.empty? - output_object.last_geo_failover_time = deserialized_property - - deserialized_property = object['secondaryLocation'] - output_object.secondary_location = deserialized_property - - deserialized_property = object['statusOfSecondary'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = AccountStatus.constants.any? { |e| AccountStatus.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum AccountStatus does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.status_of_secondary = deserialized_property - - deserialized_property = object['creationTime'] - deserialized_property = DateTime.parse(deserialized_property) unless deserialized_property.to_s.empty? - output_object.creation_time = deserialized_property - - deserialized_property = object['customDomain'] - unless deserialized_property.nil? - deserialized_property = CustomDomain.deserialize_object(deserialized_property) - end - output_object.custom_domain = deserialized_property - - deserialized_property = object['secondaryEndpoints'] - unless deserialized_property.nil? - deserialized_property = Endpoints.deserialize_object(deserialized_property) - end - output_object.secondary_endpoints = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountProperties', + type: { + name: 'Composite', + class_name: 'StorageAccountProperties', + model_properties: { + provisioning_state: { + required: false, + serialized_name: 'provisioningState', + type: { + name: 'Enum', + module: 'ProvisioningState' + } + }, + account_type: { + required: false, + serialized_name: 'accountType', + type: { + name: 'Enum', + module: 'AccountType' + } + }, + primary_endpoints: { + required: false, + serialized_name: 'primaryEndpoints', + type: { + name: 'Composite', + class_name: 'Endpoints' + } + }, + primary_location: { + required: false, + serialized_name: 'primaryLocation', + type: { + name: 'String' + } + }, + status_of_primary: { + required: false, + serialized_name: 'statusOfPrimary', + type: { + name: 'Enum', + module: 'AccountStatus' + } + }, + last_geo_failover_time: { + required: false, + serialized_name: 'lastGeoFailoverTime', + type: { + name: 'DateTime' + } + }, + secondary_location: { + required: false, + serialized_name: 'secondaryLocation', + type: { + name: 'String' + } + }, + status_of_secondary: { + required: false, + serialized_name: 'statusOfSecondary', + type: { + name: 'Enum', + module: 'AccountStatus' + } + }, + creation_time: { + required: false, + serialized_name: 'creationTime', + type: { + name: 'DateTime' + } + }, + custom_domain: { + required: false, + serialized_name: 'customDomain', + type: { + name: 'Composite', + class_name: 'CustomDomain' + } + }, + secondary_endpoints: { + required: false, + serialized_name: 'secondaryEndpoints', + type: { + name: 'Composite', + class_name: 'Endpoints' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_create_parameters.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_create_parameters.rb index c57e39d436bf8..fbb2b91b7032b 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_create_parameters.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_create_parameters.rb @@ -14,45 +14,30 @@ class StorageAccountPropertiesCreateParameters # 'Standard_RAGRS', 'Premium_LRS' attr_accessor :account_type - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property account_type is nil' if @account_type.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountPropertiesCreateParameters class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.account_type - output_object['accountType'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountPropertiesCreateParameters] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountPropertiesCreateParameters.new - - deserialized_property = object['accountType'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = AccountType.constants.any? { |e| AccountType.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum AccountType does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.account_type = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountPropertiesCreateParameters', + type: { + name: 'Composite', + class_name: 'StorageAccountPropertiesCreateParameters', + model_properties: { + account_type: { + required: true, + serialized_name: 'accountType', + type: { + name: 'Enum', + module: 'AccountType' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_update_parameters.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_update_parameters.rb index 6bde6df04940c..f286fae9885d0 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_update_parameters.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_properties_update_parameters.rb @@ -22,57 +22,38 @@ class StorageAccountPropertiesUpdateParameters # use an empty string for the custom domain name property. attr_accessor :custom_domain - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - @custom_domain.validate unless @custom_domain.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountPropertiesUpdateParameters class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.account_type - output_object['accountType'] = serialized_property unless serialized_property.nil? - - serialized_property = object.custom_domain - unless serialized_property.nil? - serialized_property = CustomDomain.serialize_object(serialized_property) - end - output_object['customDomain'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountPropertiesUpdateParameters] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountPropertiesUpdateParameters.new - - deserialized_property = object['accountType'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = AccountType.constants.any? { |e| AccountType.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum AccountType does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.account_type = deserialized_property - - deserialized_property = object['customDomain'] - unless deserialized_property.nil? - deserialized_property = CustomDomain.deserialize_object(deserialized_property) - end - output_object.custom_domain = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountPropertiesUpdateParameters', + type: { + name: 'Composite', + class_name: 'StorageAccountPropertiesUpdateParameters', + model_properties: { + account_type: { + required: false, + serialized_name: 'accountType', + type: { + name: 'Enum', + module: 'AccountType' + } + }, + custom_domain: { + required: false, + serialized_name: 'customDomain', + type: { + name: 'Composite', + class_name: 'CustomDomain' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_regenerate_key_parameters.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_regenerate_key_parameters.rb index f057068890e30..21238ce25fcf6 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_regenerate_key_parameters.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_regenerate_key_parameters.rb @@ -12,41 +12,29 @@ class StorageAccountRegenerateKeyParameters # @return [String] attr_accessor :key_name - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property key_name is nil' if @key_name.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountRegenerateKeyParameters class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.key_name - output_object['keyName'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountRegenerateKeyParameters] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountRegenerateKeyParameters.new - - deserialized_property = object['keyName'] - output_object.key_name = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountRegenerateKeyParameters', + type: { + name: 'Composite', + class_name: 'StorageAccountRegenerateKeyParameters', + model_properties: { + key_name: { + required: true, + serialized_name: 'keyName', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_update_parameters.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_update_parameters.rb index 593ba5b06da54..5a1b2e54ae077 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_update_parameters.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/storage_account_update_parameters.rb @@ -15,54 +15,44 @@ class StorageAccountUpdateParameters # @return [StorageAccountPropertiesUpdateParameters] attr_accessor :properties - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - @tags.each{ |e| e.validate if e.respond_to?(:validate) } unless @tags.nil? - @properties.validate unless @properties.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for StorageAccountUpdateParameters class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.tags - output_object['tags'] = serialized_property unless serialized_property.nil? - - serialized_property = object.properties - unless serialized_property.nil? - serialized_property = StorageAccountPropertiesUpdateParameters.serialize_object(serialized_property) - end - output_object['properties'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [StorageAccountUpdateParameters] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = StorageAccountUpdateParameters.new - - deserialized_property = object['tags'] - output_object.tags = deserialized_property - - deserialized_property = object['properties'] - unless deserialized_property.nil? - deserialized_property = StorageAccountPropertiesUpdateParameters.deserialize_object(deserialized_property) - end - output_object.properties = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'StorageAccountUpdateParameters', + type: { + name: 'Composite', + class_name: 'StorageAccountUpdateParameters', + model_properties: { + tags: { + required: false, + serialized_name: 'tags', + type: { + name: 'Dictionary', + value: { + required: false, + serialized_name: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + properties: { + required: false, + serialized_name: 'properties', + type: { + name: 'Composite', + class_name: 'StorageAccountPropertiesUpdateParameters' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage.rb index ced4efa1aca06..09a810b648c2f 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage.rb @@ -25,75 +25,52 @@ class Usage # @return [UsageName] Gets the name of the type of usage. attr_accessor :name - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property unit is nil' if @unit.nil? - fail MsRest::ValidationError, 'property current_value is nil' if @current_value.nil? - fail MsRest::ValidationError, 'property limit is nil' if @limit.nil? - fail MsRest::ValidationError, 'property name is nil' if @name.nil? - @name.validate unless @name.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for Usage class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.unit - output_object['unit'] = serialized_property unless serialized_property.nil? - - serialized_property = object.current_value - output_object['currentValue'] = serialized_property unless serialized_property.nil? - - serialized_property = object.limit - output_object['limit'] = serialized_property unless serialized_property.nil? - - serialized_property = object.name - unless serialized_property.nil? - serialized_property = UsageName.serialize_object(serialized_property) - end - output_object['name'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [Usage] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = Usage.new - - deserialized_property = object['unit'] - if (!deserialized_property.nil? && !deserialized_property.empty?) - enum_is_valid = UsageUnit.constants.any? { |e| UsageUnit.const_get(e).to_s.downcase == deserialized_property.downcase } - warn 'Enum UsageUnit does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid - end - output_object.unit = deserialized_property - - deserialized_property = object['currentValue'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.current_value = deserialized_property - - deserialized_property = object['limit'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.limit = deserialized_property - - deserialized_property = object['name'] - unless deserialized_property.nil? - deserialized_property = UsageName.deserialize_object(deserialized_property) - end - output_object.name = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'Usage', + type: { + name: 'Composite', + class_name: 'Usage', + model_properties: { + unit: { + required: true, + serialized_name: 'unit', + type: { + name: 'Enum', + module: 'UsageUnit' + } + }, + current_value: { + required: true, + serialized_name: 'currentValue', + type: { + name: 'Number' + } + }, + limit: { + required: true, + serialized_name: 'limit', + type: { + name: 'Number' + } + }, + name: { + required: true, + serialized_name: 'name', + type: { + name: 'Composite', + class_name: 'UsageName' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_list_result.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_list_result.rb index be59e10042364..638ff997317c7 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_list_result.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_list_result.rb @@ -15,67 +15,44 @@ class UsageListResult # @return [String] attr_accessor :next_link - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - @value.each{ |e| e.validate if e.respond_to?(:validate) } unless @value.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for UsageListResult class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.value - unless serialized_property.nil? - serializedArray = [] - serialized_property.each do |element| - unless element.nil? - element = Usage.serialize_object(element) - end - serializedArray.push(element) - end - serialized_property = serializedArray - end - output_object['value'] = serialized_property unless serialized_property.nil? - - serialized_property = object.next_link - output_object['nextLink'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [UsageListResult] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = UsageListResult.new - - deserialized_property = object['value'] - unless deserialized_property.nil? - deserialized_array = [] - deserialized_property.each do |element1| - unless element1.nil? - element1 = Usage.deserialize_object(element1) - end - deserialized_array.push(element1) - end - deserialized_property = deserialized_array - end - output_object.value = deserialized_property - - deserialized_property = object['nextLink'] - output_object.next_link = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'UsageListResult', + type: { + name: 'Composite', + class_name: 'UsageListResult', + model_properties: { + value: { + required: false, + serialized_name: 'value', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'UsageElementType', + type: { + name: 'Composite', + class_name: 'Usage' + } + } + } + }, + next_link: { + required: false, + serialized_name: 'nextLink', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_name.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_name.rb index 9b38c81277d27..7c6eb478e382e 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_name.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/models/usage_name.rb @@ -15,47 +15,36 @@ class UsageName # @return [String] Gets a localized string describing the resource name. attr_accessor :localized_value - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - # Nothing to validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for UsageName class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.value - output_object['value'] = serialized_property unless serialized_property.nil? - - serialized_property = object.localized_value - output_object['localizedValue'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [UsageName] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = UsageName.new - - deserialized_property = object['value'] - output_object.value = deserialized_property - - deserialized_property = object['localizedValue'] - output_object.localized_value = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'UsageName', + type: { + name: 'Composite', + class_name: 'UsageName', + model_properties: { + value: { + required: false, + serialized_name: 'value', + type: { + name: 'String' + } + }, + localized_value: { + required: false, + serialized_name: 'localizedValue', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/storage_accounts.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/storage_accounts.rb index 771307fb0945d..29649021111d5 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/storage_accounts.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/storage_accounts.rb @@ -66,7 +66,6 @@ def check_name_availability_with_http_info(account_name, custom_headers = nil) # def check_name_availability_async(account_name, custom_headers = nil) fail ArgumentError, 'account_name is nil' if account_name.nil? - account_name.validate unless account_name.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? request_headers = {} @@ -75,12 +74,13 @@ def check_name_availability_async(account_name, custom_headers = nil) request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil? - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless account_name.nil? - account_name = StorageAccountCheckNameAvailabilityParameters.serialize_object(account_name) - end - request_content = account_name != nil ? JSON.generate(account_name, quirks_mode: true) : nil + + # Serialize Request + request_mapper = StorageAccountCheckNameAvailabilityParameters.mapper() + request_content = @client.serialize(request_mapper, account_name, 'account_name') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -112,10 +112,8 @@ def check_name_availability_async(account_name, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = CheckNameAvailabilityResult.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = CheckNameAvailabilityResult.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -158,9 +156,8 @@ def create(resource_group_name, account_name, parameters, custom_headers = nil) promise = promise.then do |response| # Defining deserialization method. deserialize_method = lambda do |parsed_response| - unless parsed_response.nil? - parsed_response = StorageAccount.deserialize_object(parsed_response) - end + result_mapper = StorageAccount.mapper() + parsed_response = @client.deserialize(result_mapper, parsed_response, 'parsed_response') end # Waiting for response. @@ -240,7 +237,6 @@ def begin_create_async(resource_group_name, account_name, parameters, custom_hea fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil? fail ArgumentError, 'account_name is nil' if account_name.nil? fail ArgumentError, 'parameters is nil' if parameters.nil? - parameters.validate unless parameters.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? request_headers = {} @@ -249,12 +245,13 @@ def begin_create_async(resource_group_name, account_name, parameters, custom_hea request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil? - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless parameters.nil? - parameters = StorageAccountCreateParameters.serialize_object(parameters) - end - request_content = parameters != nil ? JSON.generate(parameters, quirks_mode: true) : nil + + # Serialize Request + request_mapper = StorageAccountCreateParameters.mapper() + request_content = @client.serialize(request_mapper, parameters, 'parameters') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -286,10 +283,8 @@ def begin_create_async(resource_group_name, account_name, parameters, custom_hea if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccount.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccount.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -485,10 +480,8 @@ def get_properties_async(resource_group_name, account_name, custom_headers = nil if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccount.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccount.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -594,7 +587,6 @@ def update_async(resource_group_name, account_name, parameters, custom_headers = fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil? fail ArgumentError, 'account_name is nil' if account_name.nil? fail ArgumentError, 'parameters is nil' if parameters.nil? - parameters.validate unless parameters.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? request_headers = {} @@ -603,12 +595,13 @@ def update_async(resource_group_name, account_name, parameters, custom_headers = request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil? - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless parameters.nil? - parameters = StorageAccountUpdateParameters.serialize_object(parameters) - end - request_content = parameters != nil ? JSON.generate(parameters, quirks_mode: true) : nil + + # Serialize Request + request_mapper = StorageAccountUpdateParameters.mapper() + request_content = @client.serialize(request_mapper, parameters, 'parameters') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -640,10 +633,8 @@ def update_async(resource_group_name, account_name, parameters, custom_headers = if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccount.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccount.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -734,10 +725,8 @@ def list_keys_async(resource_group_name, account_name, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccountKeys.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccountKeys.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -823,10 +812,8 @@ def list_async(custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccountListResult.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccountListResult.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -922,10 +909,8 @@ def list_by_resource_group_async(resource_group_name, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccountListResult.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccountListResult.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -995,7 +980,6 @@ def regenerate_key_async(resource_group_name, account_name, regenerate_key, cust fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil? fail ArgumentError, 'account_name is nil' if account_name.nil? fail ArgumentError, 'regenerate_key is nil' if regenerate_key.nil? - regenerate_key.validate unless regenerate_key.nil? fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil? fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil? request_headers = {} @@ -1004,12 +988,13 @@ def regenerate_key_async(resource_group_name, account_name, regenerate_key, cust request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil? - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless regenerate_key.nil? - regenerate_key = StorageAccountRegenerateKeyParameters.serialize_object(regenerate_key) - end - request_content = regenerate_key != nil ? JSON.generate(regenerate_key, quirks_mode: true) : nil + + # Serialize Request + request_mapper = StorageAccountRegenerateKeyParameters.mapper() + request_content = @client.serialize(request_mapper, regenerate_key, 'regenerate_key') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/regenerateKey' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -1041,10 +1026,8 @@ def regenerate_key_async(resource_group_name, account_name, regenerate_key, cust if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = StorageAccountKeys.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = StorageAccountKeys.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/storage_management_client.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/storage_management_client.rb index 94846f3d7b7c1..c7fdefd945f0c 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/storage_management_client.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/storage_management_client.rb @@ -6,6 +6,7 @@ module Petstore # class StorageManagementClient < MsRestAzure::AzureServiceClient include Petstore::Models + include MsRest::Serialization include MsRestAzure # @return [String] the base URI of the service. @@ -37,10 +38,10 @@ class StorageManagementClient < MsRestAzure::AzureServiceClient # subscription. attr_accessor :credentials - # @return storage_accounts + # @return [StorageAccounts] storage_accounts attr_reader :storage_accounts - # @return usage_operations + # @return [UsageOperations] usage_operations attr_reader :usage_operations # diff --git a/Samples/azure-storage/Azure.Ruby/azure_storage/usage_operations.rb b/Samples/azure-storage/Azure.Ruby/azure_storage/usage_operations.rb index 7ac968267e69c..c69460b704e42 100644 --- a/Samples/azure-storage/Azure.Ruby/azure_storage/usage_operations.rb +++ b/Samples/azure-storage/Azure.Ruby/azure_storage/usage_operations.rb @@ -93,10 +93,8 @@ def list_async(custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = UsageListResult.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = UsageListResult.mapper() + result.body = @client.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end diff --git a/Samples/petstore/Ruby/petstore/models/category.rb b/Samples/petstore/Ruby/petstore/models/category.rb index 679f051575436..621554b24d0c7 100644 --- a/Samples/petstore/Ruby/petstore/models/category.rb +++ b/Samples/petstore/Ruby/petstore/models/category.rb @@ -12,48 +12,36 @@ class Category # @return [String] attr_accessor :name - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - # Nothing to validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for Category class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.id - output_object['id'] = serialized_property unless serialized_property.nil? - - serialized_property = object.name - output_object['name'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [Category] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = Category.new - - deserialized_property = object['id'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.id = deserialized_property - - deserialized_property = object['name'] - output_object.name = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'Category', + type: { + name: 'Composite', + class_name: 'Category', + model_properties: { + id: { + required: false, + serialized_name: 'id', + type: { + name: 'Number' + } + }, + name: { + required: false, + serialized_name: 'name', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/petstore/Ruby/petstore/models/order.rb b/Samples/petstore/Ruby/petstore/models/order.rb index 0b424d22cbcab..7cfaf334d8410 100644 --- a/Samples/petstore/Ruby/petstore/models/order.rb +++ b/Samples/petstore/Ruby/petstore/models/order.rb @@ -25,75 +25,65 @@ class Order # @return [Boolean] attr_accessor :complete - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for Order class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.id - output_object['id'] = serialized_property unless serialized_property.nil? - - serialized_property = object.pet_id - output_object['petId'] = serialized_property unless serialized_property.nil? - - serialized_property = object.quantity - output_object['quantity'] = serialized_property unless serialized_property.nil? - - serialized_property = object.ship_date - serialized_property = serialized_property.new_offset(0).strftime('%FT%TZ') - output_object['shipDate'] = serialized_property unless serialized_property.nil? - - serialized_property = object.status - output_object['status'] = serialized_property unless serialized_property.nil? - - serialized_property = object.complete - output_object['complete'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [Order] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = Order.new - - deserialized_property = object['id'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.id = deserialized_property - - deserialized_property = object['petId'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.pet_id = deserialized_property - - deserialized_property = object['quantity'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.quantity = deserialized_property - - deserialized_property = object['shipDate'] - deserialized_property = DateTime.parse(deserialized_property) unless deserialized_property.to_s.empty? - output_object.ship_date = deserialized_property - - deserialized_property = object['status'] - output_object.status = deserialized_property - - deserialized_property = object['complete'] - output_object.complete = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'Order', + type: { + name: 'Composite', + class_name: 'Order', + model_properties: { + id: { + required: false, + read_only: true, + serialized_name: 'id', + type: { + name: 'Number' + } + }, + pet_id: { + required: false, + serialized_name: 'petId', + type: { + name: 'Number' + } + }, + quantity: { + required: false, + serialized_name: 'quantity', + type: { + name: 'Number' + } + }, + ship_date: { + required: false, + serialized_name: 'shipDate', + type: { + name: 'DateTime' + } + }, + status: { + required: false, + serialized_name: 'status', + type: { + name: 'String' + } + }, + complete: { + required: false, + serialized_name: 'complete', + type: { + name: 'Boolean' + } + } + } + } + } end end end diff --git a/Samples/petstore/Ruby/petstore/models/pet.rb b/Samples/petstore/Ruby/petstore/models/pet.rb index 2cf467e34a540..c7c0493957547 100644 --- a/Samples/petstore/Ruby/petstore/models/pet.rb +++ b/Samples/petstore/Ruby/petstore/models/pet.rb @@ -28,102 +28,80 @@ class Pet # 'pending', 'sold' attr_accessor :status - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - fail MsRest::ValidationError, 'property name is nil' if @name.nil? - fail MsRest::ValidationError, 'property photo_urls is nil' if @photo_urls.nil? - @category.validate unless @category.nil? - @photo_urls.each{ |e| e.validate if e.respond_to?(:validate) } unless @photo_urls.nil? - @tags.each{ |e| e.validate if e.respond_to?(:validate) } unless @tags.nil? - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for Pet class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.name - output_object['name'] = serialized_property unless serialized_property.nil? - - serialized_property = object.photo_urls - output_object['photoUrls'] = serialized_property unless serialized_property.nil? - - serialized_property = object.id - output_object['id'] = serialized_property unless serialized_property.nil? - - serialized_property = object.category - unless serialized_property.nil? - serialized_property = Category.serialize_object(serialized_property) - end - output_object['category'] = serialized_property unless serialized_property.nil? - - serialized_property = object.tags - unless serialized_property.nil? - serializedArray = [] - serialized_property.each do |element1| - unless element1.nil? - element1 = Tag.serialize_object(element1) - end - serializedArray.push(element1) - end - serialized_property = serializedArray - end - output_object['tags'] = serialized_property unless serialized_property.nil? - - serialized_property = object.status - output_object['status'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [Pet] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = Pet.new - - deserialized_property = object['name'] - output_object.name = deserialized_property - - deserialized_property = object['photoUrls'] - output_object.photo_urls = deserialized_property - - deserialized_property = object['id'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.id = deserialized_property - - deserialized_property = object['category'] - unless deserialized_property.nil? - deserialized_property = Category.deserialize_object(deserialized_property) - end - output_object.category = deserialized_property - - deserialized_property = object['tags'] - unless deserialized_property.nil? - deserialized_array = [] - deserialized_property.each do |element3| - unless element3.nil? - element3 = Tag.deserialize_object(element3) - end - deserialized_array.push(element3) - end - deserialized_property = deserialized_array - end - output_object.tags = deserialized_property - - deserialized_property = object['status'] - output_object.status = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'Pet', + type: { + name: 'Composite', + class_name: 'Pet', + model_properties: { + id: { + required: false, + serialized_name: 'id', + type: { + name: 'Number' + } + }, + category: { + required: false, + serialized_name: 'category', + type: { + name: 'Composite', + class_name: 'Category' + } + }, + name: { + required: true, + serialized_name: 'name', + type: { + name: 'String' + } + }, + photo_urls: { + required: true, + serialized_name: 'photoUrls', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + tags: { + required: false, + serialized_name: 'tags', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'TagElementType', + type: { + name: 'Composite', + class_name: 'Tag' + } + } + } + }, + status: { + required: false, + serialized_name: 'status', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/petstore/Ruby/petstore/models/tag.rb b/Samples/petstore/Ruby/petstore/models/tag.rb index 8c9ecd51bd6c4..e3214a4f3866c 100644 --- a/Samples/petstore/Ruby/petstore/models/tag.rb +++ b/Samples/petstore/Ruby/petstore/models/tag.rb @@ -12,48 +12,36 @@ class Tag # @return [String] attr_accessor :name - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - # Nothing to validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for Tag class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.id - output_object['id'] = serialized_property unless serialized_property.nil? - - serialized_property = object.name - output_object['name'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [Tag] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = Tag.new - - deserialized_property = object['id'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.id = deserialized_property - - deserialized_property = object['name'] - output_object.name = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'Tag', + type: { + name: 'Composite', + class_name: 'Tag', + model_properties: { + id: { + required: false, + serialized_name: 'id', + type: { + name: 'Number' + } + }, + name: { + required: false, + serialized_name: 'name', + type: { + name: 'String' + } + } + } + } + } end end end diff --git a/Samples/petstore/Ruby/petstore/models/user.rb b/Samples/petstore/Ruby/petstore/models/user.rb index 6fd38b53f7750..a7b71de5767be 100644 --- a/Samples/petstore/Ruby/petstore/models/user.rb +++ b/Samples/petstore/Ruby/petstore/models/user.rb @@ -30,85 +30,78 @@ class User # @return [Integer] User Status attr_accessor :user_status - # - # Validate the object. Throws ValidationError if validation fails. - # - def validate - # Nothing to validate - end # - # Serializes given Model object into Ruby Hash. - # @param object Model object to serialize. - # @return [Hash] Serialized object in form of Ruby Hash. + # Mapper for User class as Ruby Hash. + # This will be used for serialization/deserialization. # - def self.serialize_object(object) - object.validate - output_object = {} - - serialized_property = object.id - output_object['id'] = serialized_property unless serialized_property.nil? - - serialized_property = object.username - output_object['username'] = serialized_property unless serialized_property.nil? - - serialized_property = object.first_name - output_object['firstName'] = serialized_property unless serialized_property.nil? - - serialized_property = object.last_name - output_object['lastName'] = serialized_property unless serialized_property.nil? - - serialized_property = object.email - output_object['email'] = serialized_property unless serialized_property.nil? - - serialized_property = object.password - output_object['password'] = serialized_property unless serialized_property.nil? - - serialized_property = object.phone - output_object['phone'] = serialized_property unless serialized_property.nil? - - serialized_property = object.user_status - output_object['userStatus'] = serialized_property unless serialized_property.nil? - - output_object - end - - # - # Deserializes given Ruby Hash into Model object. - # @param object [Hash] Ruby Hash object to deserialize. - # @return [User] Deserialized object. - # - def self.deserialize_object(object) - return if object.nil? - output_object = User.new - - deserialized_property = object['id'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.id = deserialized_property - - deserialized_property = object['username'] - output_object.username = deserialized_property - - deserialized_property = object['firstName'] - output_object.first_name = deserialized_property - - deserialized_property = object['lastName'] - output_object.last_name = deserialized_property - - deserialized_property = object['email'] - output_object.email = deserialized_property - - deserialized_property = object['password'] - output_object.password = deserialized_property - - deserialized_property = object['phone'] - output_object.phone = deserialized_property - - deserialized_property = object['userStatus'] - deserialized_property = Integer(deserialized_property) unless deserialized_property.to_s.empty? - output_object.user_status = deserialized_property - - output_object + def self.mapper() + { + required: false, + serialized_name: 'User', + type: { + name: 'Composite', + class_name: 'User', + model_properties: { + id: { + required: false, + serialized_name: 'id', + type: { + name: 'Number' + } + }, + username: { + required: false, + serialized_name: 'username', + type: { + name: 'String' + } + }, + first_name: { + required: false, + serialized_name: 'firstName', + type: { + name: 'String' + } + }, + last_name: { + required: false, + serialized_name: 'lastName', + type: { + name: 'String' + } + }, + email: { + required: false, + serialized_name: 'email', + type: { + name: 'String' + } + }, + password: { + required: false, + serialized_name: 'password', + type: { + name: 'String' + } + }, + phone: { + required: false, + serialized_name: 'phone', + type: { + name: 'String' + } + }, + user_status: { + required: false, + serialized_name: 'userStatus', + type: { + name: 'Number' + } + } + } + } + } end end end diff --git a/Samples/petstore/Ruby/petstore/swagger_petstore.rb b/Samples/petstore/Ruby/petstore/swagger_petstore.rb index d78adfdce6333..1aad859034fd5 100644 --- a/Samples/petstore/Ruby/petstore/swagger_petstore.rb +++ b/Samples/petstore/Ruby/petstore/swagger_petstore.rb @@ -5,6 +5,7 @@ module Petstore # A service client - single point of access to the REST API. # class SwaggerPetstore < MsRest::ServiceClient + include MsRest::Serialization # @return [String] the base URI of the service. attr_accessor :base_url @@ -66,9 +67,19 @@ def add_pet_using_byte_array_with_http_info(body = nil, custom_headers = nil) def add_pet_using_byte_array_async(body = nil, custom_headers = nil) request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = { + required: false, + serialized_name: 'body', + type: { + name: 'String' + } + } + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/pet' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -145,15 +156,15 @@ def add_pet_with_http_info(body = nil, custom_headers = nil) # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def add_pet_async(body = nil, custom_headers = nil) - body.validate unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - body = Pet.serialize_object(body) - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = Pet.mapper() + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/pet' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -221,15 +232,15 @@ def update_pet_with_http_info(body = nil, custom_headers = nil) # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def update_pet_async(body = nil, custom_headers = nil) - body.validate unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - body = Pet.serialize_object(body) - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = Pet.mapper() + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/pet' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -307,7 +318,6 @@ def find_pets_by_status_with_http_info(status = nil, custom_headers = nil) # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def find_pets_by_status_async(status = nil, custom_headers = nil) - status.each{ |e| e.validate if e.respond_to?(:validate) } unless status.nil? request_headers = {} path_template = '/pet/findByStatus' options = { @@ -337,17 +347,22 @@ def find_pets_by_status_async(status = nil, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - deserialized_array = [] - parsed_response.each do |element| - unless element.nil? - element = Pet.deserialize_object(element) - end - deserialized_array.push(element) - end - parsed_response = deserialized_array - end - result.body = parsed_response + result_mapper = { + required: false, + serialized_name: 'parsed_response', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'PetElementType', + type: { + name: 'Composite', + class_name: 'Pet' + } + } + } + } + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -405,7 +420,6 @@ def find_pets_by_tags_with_http_info(tags = nil, custom_headers = nil) # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def find_pets_by_tags_async(tags = nil, custom_headers = nil) - tags.each{ |e| e.validate if e.respond_to?(:validate) } unless tags.nil? request_headers = {} path_template = '/pet/findByTags' options = { @@ -435,17 +449,22 @@ def find_pets_by_tags_async(tags = nil, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - deserialized_array = [] - parsed_response.each do |element| - unless element.nil? - element = Pet.deserialize_object(element) - end - deserialized_array.push(element) - end - parsed_response = deserialized_array - end - result.body = parsed_response + result_mapper = { + required: false, + serialized_name: 'parsed_response', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'PetElementType', + type: { + name: 'Composite', + class_name: 'Pet' + } + } + } + } + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -533,7 +552,14 @@ def find_pets_with_byte_array_async(pet_id, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - result.body = parsed_response + result_mapper = { + required: false, + serialized_name: 'parsed_response', + type: { + name: 'String' + } + } + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -621,10 +647,8 @@ def get_pet_by_id_async(pet_id, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = Pet.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = Pet.mapper() + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -929,13 +953,21 @@ def get_inventory_async(custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response.each do |key, valueElement| - valueElement = Integer(valueElement) unless valueElement.to_s.empty? - parsed_response[key] = valueElement - end - end - result.body = parsed_response + result_mapper = { + required: false, + serialized_name: 'parsed_response', + type: { + name: 'Dictionary', + value: { + required: false, + serialized_name: 'NumberElementType', + type: { + name: 'Number' + } + } + } + } + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -984,15 +1016,15 @@ def place_order_with_http_info(body = nil, custom_headers = nil) # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def place_order_async(body = nil, custom_headers = nil) - body.validate unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - body = Order.serialize_object(body) - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = Order.mapper() + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/store/order' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -1021,10 +1053,8 @@ def place_order_async(body = nil, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = Order.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = Order.mapper() + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -1112,10 +1142,8 @@ def get_order_by_id_async(order_id, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = Order.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = Order.mapper() + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -1247,15 +1275,15 @@ def create_user_with_http_info(body = nil, custom_headers = nil) # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def create_user_async(body = nil, custom_headers = nil) - body.validate unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - body = User.serialize_object(body) - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = User.mapper() + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/user' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -1323,22 +1351,29 @@ def create_users_with_array_input_with_http_info(body = nil, custom_headers = ni # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def create_users_with_array_input_async(body = nil, custom_headers = nil) - body.each{ |e| e.validate if e.respond_to?(:validate) } unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - serializedArray = [] - body.each do |element| - unless element.nil? - element = User.serialize_object(element) - end - serializedArray.push(element) - end - body = serializedArray - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = { + required: false, + serialized_name: 'body', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'UserElementType', + type: { + name: 'Composite', + class_name: 'User' + } + } + } + } + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/user/createWithArray' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -1406,22 +1441,29 @@ def create_users_with_list_input_with_http_info(body = nil, custom_headers = nil # @return [Concurrent::Promise] Promise object which holds the HTTP response. # def create_users_with_list_input_async(body = nil, custom_headers = nil) - body.each{ |e| e.validate if e.respond_to?(:validate) } unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - serializedArray = [] - body.each do |element| - unless element.nil? - element = User.serialize_object(element) - end - serializedArray.push(element) - end - body = serializedArray - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = { + required: false, + serialized_name: 'body', + type: { + name: 'Sequence', + element: { + required: false, + serialized_name: 'UserElementType', + type: { + name: 'Composite', + class_name: 'User' + } + } + } + } + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/user/createWithList' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], @@ -1522,7 +1564,14 @@ def login_user_async(username = nil, password = nil, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - result.body = parsed_response + result_mapper = { + required: false, + serialized_name: 'parsed_response', + type: { + name: 'String' + } + } + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -1668,10 +1717,8 @@ def get_user_by_name_async(username, custom_headers = nil) if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) - unless parsed_response.nil? - parsed_response = User.deserialize_object(parsed_response) - end - result.body = parsed_response + result_mapper = User.mapper() + result.body = self.deserialize(result_mapper, parsed_response, 'result.body') rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result) end @@ -1729,15 +1776,15 @@ def update_user_with_http_info(username, body = nil, custom_headers = nil) # def update_user_async(username, body = nil, custom_headers = nil) fail ArgumentError, 'username is nil' if username.nil? - body.validate unless body.nil? request_headers = {} - # Serialize Request request_headers['Content-Type'] = 'application/json; charset=utf-8' - unless body.nil? - body = User.serialize_object(body) - end - request_content = body != nil ? JSON.generate(body, quirks_mode: true) : nil + + # Serialize Request + request_mapper = User.mapper() + request_content = self.serialize(request_mapper, body, 'body') + request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil + path_template = '/user/{username}' options = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],