lib/docspring/models/update_template_response.rb in docspring-1.4.1 vs lib/docspring/models/update_template_response.rb in docspring-2.0.0

- old
+ new

@@ -1,25 +1,26 @@ =begin #API v1 #DocSpring is a service that helps you fill out and sign PDF templates. -OpenAPI spec version: v1 +The version of the OpenAPI document: v1 Generated by: https://openapi-generator.tech -OpenAPI Generator version: 3.3.0 +Generator version: 7.11.0 =end require 'date' +require 'time' module DocSpring class UpdateTemplateResponse - attr_accessor :errors - attr_accessor :status + attr_accessor :errors + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values def initialize(datatype, allowable_values) @@ -41,125 +42,155 @@ end # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :'errors' => :'errors', - :'status' => :'status' + :'status' => :'status', + :'errors' => :'errors' } end + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + # Attribute type mapping. def self.openapi_types { - :'errors' => :'Array<String>', - :'status' => :'String' + :'status' => :'String', + :'errors' => :'Array<String>' } end + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) - return unless attributes.is_a?(Hash) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `DocSpring::UpdateTemplateResponse` initialize method" + end - # convert string to symbol for hash key - attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `DocSpring::UpdateTemplateResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } - if attributes.has_key?(:'errors') + if attributes.key?(:'status') + self.status = attributes[:'status'] + else + self.status = nil + end + + if attributes.key?(:'errors') if (value = attributes[:'errors']).is_a?(Array) self.errors = value end end - - if attributes.has_key?(:'status') - self.status = attributes[:'status'] - end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if @status.nil? + invalid_properties.push('invalid value for "status", status cannot be nil.') + end + invalid_properties end # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? - status_validator = EnumAttributeValidator.new('String', ['success', 'error']) + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @status.nil? + status_validator = EnumAttributeValidator.new('String', ["success", "error"]) return false unless status_validator.valid?(@status) true end # Custom attribute writer method checking allowed values (enum). # @param [Object] status Object to be assigned def status=(status) - validator = EnumAttributeValidator.new('String', ['success', 'error']) + validator = EnumAttributeValidator.new('String', ["success", "error"]) unless validator.valid?(status) - fail ArgumentError, 'invalid value for "status", must be one of #{validator.allowable_values}.' + fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}." end @status = status end # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && - errors == o.errors && - status == o.status + status == o.status && + errors == o.errors end # @see the `==` method # @param [Object] Object to be compared def eql?(o) self == o end # Calculates hash code according to all attributes. - # @return [Fixnum] Hash code + # @return [Integer] Hash code def hash - [errors, status].hash + [status, errors].hash end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself - def build_from_hash(attributes) + def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - self.class.openapi_types.each_pair do |key, type| - if type =~ /\AArray<(.*)>/i - # check to ensure the input is an array given that the the attribute + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[self.class.attribute_map[key]].is_a?(Array) - self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[self.class.attribute_map[key]].nil? - self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) - end # or else data not found in attributes(hash), not an issue as the data can be optional + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end end - - self + new(transformed_hash) end # Deserializes the data based on type # @param string type Data type # @param string value Value to be deserialized # @return [Object] Deserialized data - def _deserialize(type, value) + def self._deserialize(type, value) case type.to_sym - when :DateTime - DateTime.parse(value) + when :Time + Time.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f - when :BOOLEAN + when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end @@ -176,12 +207,13 @@ value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model - temp_model = DocSpring.const_get(type).new - temp_model.build_from_hash(value) + # models (e.g. Pet) or oneOf + klass = DocSpring.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) end end # Returns the string representation of the object # @return [String] String presentation of the object @@ -199,11 +231,15 @@ # @return [Hash] Returns the object in the form of hash def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) - next if value.nil? + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + hash[param] = _to_hash(value) end hash end @@ -222,7 +258,9 @@ value.to_hash else value end end + end + end