mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Perl: Type coercion for the JSON conversion part of Perl (#12891)
* Perl: separate date and DateTime - Since the json values to be returned are different for date and DateTime, they are managed separately * Per: Enforcing Perl types to openAPI types Perl JSON values return different types depending on the context, so look at openapi's type and modify the type. * generate samples * generate docs * add perl test (json types)
This commit is contained in:
@@ -41,7 +41,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>ARRAY</li>
|
||||
<li>DateTime</li>
|
||||
<li>DATE</li>
|
||||
<li>DATE_TIME</li>
|
||||
<li>HASH</li>
|
||||
<li>boolean</li>
|
||||
<li>double</li>
|
||||
|
||||
@@ -115,7 +115,8 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
languageSpecificPrimitives.add("double");
|
||||
languageSpecificPrimitives.add("string");
|
||||
languageSpecificPrimitives.add("boolean");
|
||||
languageSpecificPrimitives.add("DateTime");
|
||||
languageSpecificPrimitives.add("DATE");
|
||||
languageSpecificPrimitives.add("DATE_TIME");
|
||||
languageSpecificPrimitives.add("ARRAY");
|
||||
languageSpecificPrimitives.add("HASH");
|
||||
languageSpecificPrimitives.add("object");
|
||||
@@ -128,8 +129,8 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("boolean", "boolean");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("date", "DateTime");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
typeMapping.put("date", "DATE");
|
||||
typeMapping.put("DateTime", "DATE_TIME");
|
||||
typeMapping.put("password", "string");
|
||||
typeMapping.put("array", "ARRAY");
|
||||
typeMapping.put("set", "ARRAY");
|
||||
|
||||
@@ -112,7 +112,7 @@ sub call_api {
|
||||
$_request = GET($_url, %$header_params);
|
||||
}
|
||||
elsif ($method eq 'HEAD') {
|
||||
$_request = HEAD($_url,%$header_params);
|
||||
$_request = HEAD($_url,%$header_params);
|
||||
}
|
||||
elsif ($method eq 'DELETE') { #TODO support form data
|
||||
$_request = DELETE($_url, %$header_params);
|
||||
@@ -240,10 +240,16 @@ sub deserialize
|
||||
}
|
||||
}
|
||||
return \@_values;
|
||||
} elsif ($class eq 'DateTime') {
|
||||
} elsif (grep /^$class$/, ('DATE_TIME', 'DATE')) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) {
|
||||
} elsif ($class eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($class eq 'object') {
|
||||
return $data;
|
||||
} elsif (grep /^$class$/, ('int', 'float', 'double')) {
|
||||
return $data + 0;
|
||||
} elsif ($class eq 'bool') {
|
||||
return !!$data;
|
||||
} else { # model
|
||||
my $_instance = use_module("{{moduleName}}::Object::$class")->new;
|
||||
if (ref $data eq "HASH") {
|
||||
|
||||
@@ -55,7 +55,24 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{#allParents}}
|
||||
@@ -67,6 +84,36 @@ sub TO_JSON {
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -108,10 +155,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "{{moduleName}}::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -558,8 +558,8 @@ my $int64 = 789; # int | None
|
||||
my $float = 3.4; # double | None
|
||||
my $string = "string_example"; # string | None
|
||||
my $binary = "/path/to/file"; # string | None
|
||||
my $date = DateTime->from_epoch(epoch => str2time('null')); # DateTime | None
|
||||
my $date_time = DateTime->from_epoch(epoch => str2time('null')); # DateTime | None
|
||||
my $date = DateTime->from_epoch(epoch => str2time('null')); # DATE | None
|
||||
my $date_time = DateTime->from_epoch(epoch => str2time('null')); # DATE_TIME | None
|
||||
my $password = "password_example"; # string | None
|
||||
my $callback = "callback_example"; # string | None
|
||||
|
||||
@@ -585,8 +585,8 @@ Name | Type | Description | Notes
|
||||
**float** | **double**| None | [optional]
|
||||
**string** | **string**| None | [optional]
|
||||
**binary** | **string****string**| None | [optional]
|
||||
**date** | **DateTime**| None | [optional]
|
||||
**date_time** | **DateTime**| None | [optional]
|
||||
**date** | **DATE**| None | [optional]
|
||||
**date_time** | **DATE_TIME**| None | [optional]
|
||||
**password** | **string**| None | [optional]
|
||||
**callback** | **string**| None | [optional]
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ Name | Type | Description | Notes
|
||||
**string** | **string** | | [optional]
|
||||
**byte** | **string** | |
|
||||
**binary** | **string** | | [optional]
|
||||
**date** | **DateTime** | |
|
||||
**date_time** | **DateTime** | | [optional]
|
||||
**date** | **DATE** | |
|
||||
**date_time** | **DATE_TIME** | | [optional]
|
||||
**uuid** | **string** | | [optional]
|
||||
**password** | **string** | |
|
||||
**pattern_with_digits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional]
|
||||
|
||||
@@ -9,7 +9,7 @@ use WWW::OpenAPIClient::Object::MixedPropertiesAndAdditionalPropertiesClass;
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | **string** | | [optional]
|
||||
**date_time** | **DateTime** | | [optional]
|
||||
**date_time** | **DATE_TIME** | | [optional]
|
||||
**map** | [**HASH[string,Animal]**](Animal.md) | | [optional]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
@@ -12,8 +12,8 @@ Name | Type | Description | Notes
|
||||
**number_prop** | **double** | | [optional]
|
||||
**boolean_prop** | **boolean** | | [optional]
|
||||
**string_prop** | **string** | | [optional]
|
||||
**date_prop** | **DateTime** | | [optional]
|
||||
**datetime_prop** | **DateTime** | | [optional]
|
||||
**date_prop** | **DATE** | | [optional]
|
||||
**datetime_prop** | **DATE_TIME** | | [optional]
|
||||
**array_nullable_prop** | **ARRAY[object]** | | [optional]
|
||||
**array_and_items_nullable_prop** | **ARRAY[object]** | | [optional]
|
||||
**array_items_nullable** | **ARRAY[object]** | | [optional]
|
||||
|
||||
@@ -11,7 +11,7 @@ Name | Type | Description | Notes
|
||||
**id** | **int** | | [optional]
|
||||
**pet_id** | **int** | | [optional]
|
||||
**quantity** | **int** | | [optional]
|
||||
**ship_date** | **DateTime** | | [optional]
|
||||
**ship_date** | **DATE_TIME** | | [optional]
|
||||
**status** | **string** | Order Status | [optional]
|
||||
**complete** | **boolean** | | [optional] [default to false]
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ sub call_api {
|
||||
$_request = GET($_url, %$header_params);
|
||||
}
|
||||
elsif ($method eq 'HEAD') {
|
||||
$_request = HEAD($_url,%$header_params);
|
||||
$_request = HEAD($_url,%$header_params);
|
||||
}
|
||||
elsif ($method eq 'DELETE') { #TODO support form data
|
||||
$_request = DELETE($_url, %$header_params);
|
||||
@@ -253,10 +253,16 @@ sub deserialize
|
||||
}
|
||||
}
|
||||
return \@_values;
|
||||
} elsif ($class eq 'DateTime') {
|
||||
} elsif (grep /^$class$/, ('DATE_TIME', 'DATE')) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) {
|
||||
} elsif ($class eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($class eq 'object') {
|
||||
return $data;
|
||||
} elsif (grep /^$class$/, ('int', 'float', 'double')) {
|
||||
return $data + 0;
|
||||
} elsif ($class eq 'bool') {
|
||||
return !!$data;
|
||||
} else { # model
|
||||
my $_instance = use_module("WWW::OpenAPIClient::Object::$class")->new;
|
||||
if (ref $data eq "HASH") {
|
||||
|
||||
@@ -759,8 +759,8 @@ sub test_client_model {
|
||||
# @param double $float None (optional)
|
||||
# @param string $string None (optional)
|
||||
# @param string $binary None (optional)
|
||||
# @param DateTime $date None (optional)
|
||||
# @param DateTime $date_time None (optional)
|
||||
# @param DATE $date None (optional)
|
||||
# @param DATE_TIME $date_time None (optional)
|
||||
# @param string $password None (optional)
|
||||
# @param string $callback None (optional)
|
||||
{
|
||||
@@ -816,12 +816,12 @@ sub test_client_model {
|
||||
required => '0',
|
||||
},
|
||||
'date' => {
|
||||
data_type => 'DateTime',
|
||||
data_type => 'DATE',
|
||||
description => 'None',
|
||||
required => '0',
|
||||
},
|
||||
'date_time' => {
|
||||
data_type => 'DateTime',
|
||||
data_type => 'DATE_TIME',
|
||||
description => 'None',
|
||||
required => '0',
|
||||
},
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -107,7 +107,24 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +134,36 @@ sub TO_JSON {
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -156,10 +203,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -107,7 +107,24 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +134,36 @@ sub TO_JSON {
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -156,10 +203,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -104,13 +104,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -147,10 +194,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
@@ -232,14 +283,14 @@ __PACKAGE__->method_documentation({
|
||||
read_only => '',
|
||||
},
|
||||
'date' => {
|
||||
datatype => 'DateTime',
|
||||
datatype => 'DATE',
|
||||
base_name => 'date',
|
||||
description => '',
|
||||
format => '',
|
||||
read_only => '',
|
||||
},
|
||||
'date_time' => {
|
||||
datatype => 'DateTime',
|
||||
datatype => 'DATE_TIME',
|
||||
base_name => 'dateTime',
|
||||
description => '',
|
||||
format => '',
|
||||
@@ -286,8 +337,8 @@ __PACKAGE__->openapi_types( {
|
||||
'string' => 'string',
|
||||
'byte' => 'string',
|
||||
'binary' => 'string',
|
||||
'date' => 'DateTime',
|
||||
'date_time' => 'DateTime',
|
||||
'date' => 'DATE',
|
||||
'date_time' => 'DATE_TIME',
|
||||
'uuid' => 'string',
|
||||
'password' => 'string',
|
||||
'pattern_with_digits' => 'string',
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
@@ -169,7 +220,7 @@ __PACKAGE__->method_documentation({
|
||||
read_only => '',
|
||||
},
|
||||
'date_time' => {
|
||||
datatype => 'DateTime',
|
||||
datatype => 'DATE_TIME',
|
||||
base_name => 'dateTime',
|
||||
description => '',
|
||||
format => '',
|
||||
@@ -186,7 +237,7 @@ __PACKAGE__->method_documentation({
|
||||
|
||||
__PACKAGE__->openapi_types( {
|
||||
'uuid' => 'string',
|
||||
'date_time' => 'DateTime',
|
||||
'date_time' => 'DATE_TIME',
|
||||
'map' => 'HASH[string,Animal]'
|
||||
} );
|
||||
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
@@ -189,14 +240,14 @@ __PACKAGE__->method_documentation({
|
||||
read_only => '',
|
||||
},
|
||||
'date_prop' => {
|
||||
datatype => 'DateTime',
|
||||
datatype => 'DATE',
|
||||
base_name => 'date_prop',
|
||||
description => '',
|
||||
format => '',
|
||||
read_only => '',
|
||||
},
|
||||
'datetime_prop' => {
|
||||
datatype => 'DateTime',
|
||||
datatype => 'DATE_TIME',
|
||||
base_name => 'datetime_prop',
|
||||
description => '',
|
||||
format => '',
|
||||
@@ -251,8 +302,8 @@ __PACKAGE__->openapi_types( {
|
||||
'number_prop' => 'double',
|
||||
'boolean_prop' => 'boolean',
|
||||
'string_prop' => 'string',
|
||||
'date_prop' => 'DateTime',
|
||||
'datetime_prop' => 'DateTime',
|
||||
'date_prop' => 'DATE',
|
||||
'datetime_prop' => 'DATE_TIME',
|
||||
'array_nullable_prop' => 'ARRAY[object]',
|
||||
'array_and_items_nullable_prop' => 'ARRAY[object]',
|
||||
'array_items_nullable' => 'ARRAY[object]',
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
@@ -182,7 +233,7 @@ __PACKAGE__->method_documentation({
|
||||
read_only => '',
|
||||
},
|
||||
'ship_date' => {
|
||||
datatype => 'DateTime',
|
||||
datatype => 'DATE_TIME',
|
||||
base_name => 'shipDate',
|
||||
description => '',
|
||||
format => '',
|
||||
@@ -208,7 +259,7 @@ __PACKAGE__->openapi_types( {
|
||||
'id' => 'int',
|
||||
'pet_id' => 'int',
|
||||
'quantity' => 'int',
|
||||
'ship_date' => 'DateTime',
|
||||
'ship_date' => 'DATE_TIME',
|
||||
'status' => 'string',
|
||||
'complete' => 'boolean'
|
||||
} );
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -101,13 +101,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -144,10 +191,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -102,13 +102,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -145,10 +192,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -100,13 +100,60 @@ sub TO_JSON {
|
||||
my $_data = {};
|
||||
foreach my $_key (keys %{$self->attribute_map}) {
|
||||
if (defined $self->{$_key}) {
|
||||
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
|
||||
my $_json_attribute = $self->attribute_map->{$_key};
|
||||
my $_type = $self->openapi_types->{$_key};
|
||||
my $_value = $self->{$_key};
|
||||
if ($_type =~ /^array\[(.+)\]$/i) { # array
|
||||
my $_subclass = $1;
|
||||
$_data->{$_json_attribute} = [ map { $self->_to_json_primitives($_subclass, $_) } @$_value ];
|
||||
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
|
||||
my $_subclass = $1;
|
||||
my %_hash = ();
|
||||
while (my($_key, $_element) = each %{$_value}) {
|
||||
$_hash{$_key} = $self->_to_json_primitives($_subclass, $_element);
|
||||
}
|
||||
$_data->{$_json_attribute} = \%_hash;
|
||||
} elsif ( grep( /^$_type$/, ('int', 'double', 'string', 'boolean', 'DATE', 'DATE_TIME'))) {
|
||||
$_data->{$_json_attribute} = $self->_to_json_primitives($_type, $_value);
|
||||
} else {
|
||||
$_data->{$_json_attribute} = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_data;
|
||||
}
|
||||
|
||||
# to_json non-array data
|
||||
sub _to_json_primitives {
|
||||
my ($self, $type, $data) = @_;
|
||||
if ( grep( /^$type$/, ('int', 'double'))) {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# numify it, ensuring it will be dumped as a number
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
# https://metacpan.org/pod/JSON#simple-scalars
|
||||
# stringified
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
# https://metacpan.org/pod/JSON#JSON::true,-JSON::false,-JSON::null
|
||||
return $data ? \1 : \0;
|
||||
} elsif ($type eq 'DATE') {
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Eymd($optional_separator),-$dt-%3Emdy(...),-$dt-%3Edmy(...)
|
||||
return $data->ymd;
|
||||
}
|
||||
return $data .q();
|
||||
} elsif ($type eq 'DATE_TIME') {
|
||||
# the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z
|
||||
if (ref($data) eq 'DateTime') {
|
||||
# https://metacpan.org/pod/DateTime#$dt-%3Erfc3339
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
}
|
||||
}
|
||||
|
||||
# from Perl hashref
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
@@ -143,10 +190,14 @@ sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
if (grep( /^$type$/ , ('DATE_TIME', 'DATE'))) {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||
return $data;
|
||||
} elsif ( grep( /^$type$/, ('int', 'double'))) {
|
||||
return $data + 0;
|
||||
} elsif ($type eq 'string') {
|
||||
return $data . q();
|
||||
} elsif ($type eq 'boolean') {
|
||||
return !!$data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use Test::More tests => 41;
|
||||
use Test::More tests => 52;
|
||||
use Test::Exception;
|
||||
|
||||
use lib 'lib';
|
||||
@@ -13,6 +13,7 @@ use_ok('WWW::OpenAPIClient::Object::Pet');
|
||||
use_ok('WWW::OpenAPIClient::Object::Tag');
|
||||
use_ok('WWW::OpenAPIClient::Object::Category');
|
||||
use_ok('WWW::OpenAPIClient::Object::User');
|
||||
use_ok('WWW::OpenAPIClient::Object::Order');
|
||||
|
||||
|
||||
my $api_client = WWW::OpenAPIClient::ApiClient->new();
|
||||
@@ -28,7 +29,7 @@ like ($get_inventory_response->{sold}, qr/^\d+$/, "sold is numeric");
|
||||
|
||||
my $pet_json = <<JSON;
|
||||
{
|
||||
"pet": {
|
||||
"pet": {
|
||||
"id": 0,
|
||||
"category": {
|
||||
"id": 0,
|
||||
@@ -60,7 +61,7 @@ is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{photo_urls}-
|
||||
|
||||
my $array_json = <<JSON;
|
||||
[
|
||||
{
|
||||
{
|
||||
"id": 0,
|
||||
"category": {
|
||||
"id": 0,
|
||||
@@ -120,9 +121,8 @@ is ref $api_client->deserialize("Pet", $pet_json_nopet)->{tags}->[0], "WWW::Open
|
||||
is $api_client->deserialize("Pet", $pet_json_nopet)->{tags}->[0]->{name}, "tag string", "get the tag name the Pet object";
|
||||
is $api_client->deserialize("Pet", $pet_json_nopet)->{photo_urls}->[0], "string", "get the photoUrl from the Pet object";
|
||||
|
||||
|
||||
my %userdata = (
|
||||
id => 4000,
|
||||
id => "4000",
|
||||
username => "tony",
|
||||
firstName => "Tony",
|
||||
lastName => "Tiger",
|
||||
@@ -131,7 +131,7 @@ my %userdata = (
|
||||
phone => "408-867-5309",
|
||||
userStatus => 1,
|
||||
);
|
||||
|
||||
|
||||
my $user = WWW::OpenAPIClient::Object::User->new->from_hash(\%userdata);
|
||||
is ref $user, 'WWW::OpenAPIClient::Object::User', "built a User object via from_hash()";
|
||||
is $user->{id}, $userdata{id}, "got the id of the User object";
|
||||
@@ -143,4 +143,31 @@ is $user->{password}, $userdata{password}, "got the password of the User object"
|
||||
is $user->{phone}, $userdata{phone}, "got the phone of the User object";
|
||||
is $user->{user_status}, $userdata{userStatus}, "got the userStatus of the User object";
|
||||
|
||||
my $user_to_json = JSON->new->convert_blessed->encode($user);
|
||||
like $user_to_json, qr/4000/, '$userdata{id} is string. But, json id is a number';
|
||||
unlike $user_to_json, qr/"4000"/, '$userdata{id} is string. But, json id is a number';
|
||||
|
||||
|
||||
my %order_data = (
|
||||
id => '123',
|
||||
petId => '456',
|
||||
quantity => 789,
|
||||
shipDate => '2020-11-06T09:20:48Z',
|
||||
status => 101112, # status type is string, but this data is number
|
||||
complete => 0, # status type is boolean, but this data is number
|
||||
);
|
||||
my $order = WWW::OpenAPIClient::Object::Order->new->from_hash(\%order_data);
|
||||
is ref($order->ship_date), 'DateTime';
|
||||
|
||||
my $order_to_json = JSON->new->convert_blessed->encode($order);
|
||||
like $order_to_json, qr/123/, '$order{id} is string. But, json type is number';
|
||||
unlike $order_to_json, qr/"123"/, '$order{id} is string. But, json type is number';
|
||||
|
||||
like $order_to_json, qr/789/, '$order{quantity} is number';
|
||||
unlike $order_to_json, qr/"789"/, '$order{quantity} is number';
|
||||
|
||||
like $order_to_json, qr/2020-11-06T09:20:48Z/, '$order{shipDate} to date-time format';
|
||||
|
||||
like $order_to_json, qr/"101112"/, '$order{status} is number. But json type is string';
|
||||
|
||||
like $order_to_json, qr/false/, '$order{complete} is number. But json type is boolean';
|
||||
Reference in New Issue
Block a user