Class: Intrinsic::ErrorSchemaError

Inherits:
Object
  • Object
show all
Defined in:
lib/intrinsic/types/error_schema_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, message:, code:, param: nil, additional_properties: nil) ⇒ ErrorSchemaError

Parameters:

  • type (ERROR_SCHEMA_ERROR_TYPE)
  • message (String)
  • code (ERROR_SCHEMA_ERROR_CODE)
  • param (String) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/intrinsic/types/error_schema_error.rb', line 17

def initialize(type:, message:, code:, param: nil, additional_properties: nil)
  # @type [ERROR_SCHEMA_ERROR_TYPE]
  @type = type
  # @type [String]
  @message = message
  # @type [ERROR_SCHEMA_ERROR_CODE]
  @code = code
  # @type [String]
  @param = param
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



9
10
11
# File 'lib/intrinsic/types/error_schema_error.rb', line 9

def additional_properties
  @additional_properties
end

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/intrinsic/types/error_schema_error.rb', line 9

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/intrinsic/types/error_schema_error.rb', line 9

def message
  @message
end

#paramObject (readonly)

Returns the value of attribute param.



9
10
11
# File 'lib/intrinsic/types/error_schema_error.rb', line 9

def param
  @param
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/intrinsic/types/error_schema_error.rb', line 9

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ ErrorSchemaError

Deserialize a JSON object to an instance of ErrorSchemaError

Parameters:

  • json_object (JSON)

Returns:



34
35
36
37
38
39
40
41
42
# File 'lib/intrinsic/types/error_schema_error.rb', line 34

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  type = ERROR_SCHEMA_ERROR_TYPE.key(parsed_json["type"]) || parsed_json["type"]
  message = struct.message
  code = ERROR_SCHEMA_ERROR_CODE.key(parsed_json["code"]) || parsed_json["code"]
  param = struct.param
  new(type: type, message: message, code: code, param: param, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


60
61
62
63
64
65
# File 'lib/intrinsic/types/error_schema_error.rb', line 60

def self.validate_raw(obj:)
  obj.type.is_a?(ERROR_SCHEMA_ERROR_TYPE) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.message.is_a?(String) != false || raise("Passed value for field obj.message is not the expected type, validation failed.")
  obj.code.is_a?(ERROR_SCHEMA_ERROR_CODE) != false || raise("Passed value for field obj.code is not the expected type, validation failed.")
  obj.param&.is_a?(String) != false || raise("Passed value for field obj.param is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ErrorSchemaError to a JSON object

Returns:

  • (JSON)


47
48
49
50
51
52
53
54
# File 'lib/intrinsic/types/error_schema_error.rb', line 47

def to_json(*_args)
  {
    "type": ERROR_SCHEMA_ERROR_TYPE[@type] || @type,
    "message": @message,
    "code": ERROR_SCHEMA_ERROR_CODE[@code] || @code,
    "param": @param
  }.to_json
end