diff --git a/docs/generators/perl.md b/docs/generators/perl.md
index 34b9e1354a..090ccadf14 100644
--- a/docs/generators/perl.md
+++ b/docs/generators/perl.md
@@ -41,7 +41,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
- ARRAY
-- DateTime
+- DATE
+- DATE_TIME
- HASH
- boolean
- double
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java
index 2f48cbc9b9..0986c187e6 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java
@@ -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");
diff --git a/modules/openapi-generator/src/main/resources/perl/ApiClient.mustache b/modules/openapi-generator/src/main/resources/perl/ApiClient.mustache
index 30cad76b42..023891413b 100644
--- a/modules/openapi-generator/src/main/resources/perl/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/perl/ApiClient.mustache
@@ -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") {
diff --git a/modules/openapi-generator/src/main/resources/perl/BaseObject.mustache b/modules/openapi-generator/src/main/resources/perl/BaseObject.mustache
index 91c0f10ac8..62c00930ba 100644
--- a/modules/openapi-generator/src/main/resources/perl/BaseObject.mustache
+++ b/modules/openapi-generator/src/main/resources/perl/BaseObject.mustache
@@ -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);
diff --git a/samples/client/petstore/perl/docs/FakeApi.md b/samples/client/petstore/perl/docs/FakeApi.md
index fbd1c1d042..e028d69b6c 100644
--- a/samples/client/petstore/perl/docs/FakeApi.md
+++ b/samples/client/petstore/perl/docs/FakeApi.md
@@ -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]
diff --git a/samples/client/petstore/perl/docs/FormatTest.md b/samples/client/petstore/perl/docs/FormatTest.md
index 886a93b4fe..a55b89f6ce 100644
--- a/samples/client/petstore/perl/docs/FormatTest.md
+++ b/samples/client/petstore/perl/docs/FormatTest.md
@@ -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]
diff --git a/samples/client/petstore/perl/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/perl/docs/MixedPropertiesAndAdditionalPropertiesClass.md
index f2720cf57b..9fe5279da0 100644
--- a/samples/client/petstore/perl/docs/MixedPropertiesAndAdditionalPropertiesClass.md
+++ b/samples/client/petstore/perl/docs/MixedPropertiesAndAdditionalPropertiesClass.md
@@ -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)
diff --git a/samples/client/petstore/perl/docs/NullableClass.md b/samples/client/petstore/perl/docs/NullableClass.md
index 326c42317c..200aaa3d78 100644
--- a/samples/client/petstore/perl/docs/NullableClass.md
+++ b/samples/client/petstore/perl/docs/NullableClass.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]
diff --git a/samples/client/petstore/perl/docs/Order.md b/samples/client/petstore/perl/docs/Order.md
index 356ad67f45..2b33f1d4d7 100644
--- a/samples/client/petstore/perl/docs/Order.md
+++ b/samples/client/petstore/perl/docs/Order.md
@@ -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]
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/ApiClient.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/ApiClient.pm
index ca783c1c96..3319a2c92a 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/ApiClient.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/ApiClient.pm
@@ -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") {
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/FakeApi.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/FakeApi.pm
index 9c702e1c1d..2712407215 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/FakeApi.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/FakeApi.pm
@@ -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',
},
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AdditionalPropertiesClass.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AdditionalPropertiesClass.pm
index 80616971f5..5bfd2561c1 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AdditionalPropertiesClass.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AdditionalPropertiesClass.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AllOfWithSingleRef.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AllOfWithSingleRef.pm
index f946b72b81..e0b67ee995 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AllOfWithSingleRef.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/AllOfWithSingleRef.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Animal.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Animal.pm
index c84ba835dc..19935a5a67 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Animal.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Animal.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ApiResponse.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ApiResponse.pm
index be51069730..82724eea0e 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ApiResponse.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ApiResponse.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfArrayOfNumberOnly.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfArrayOfNumberOnly.pm
index 710a8c450a..ef86dfd227 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfArrayOfNumberOnly.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfArrayOfNumberOnly.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfNumberOnly.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfNumberOnly.pm
index 02cbce5acf..d94cc4fa33 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfNumberOnly.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayOfNumberOnly.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayTest.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayTest.pm
index c264d79a98..bc9709867d 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayTest.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ArrayTest.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Capitalization.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Capitalization.pm
index 3ccae2f45c..f325e1957e 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Capitalization.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Capitalization.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Cat.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Cat.pm
index bc5543d187..c54a69e987 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Cat.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Cat.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/CatAllOf.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/CatAllOf.pm
index 756a3277fd..406e840c19 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/CatAllOf.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/CatAllOf.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Category.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Category.pm
index ba7781f968..e3afa3ab93 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Category.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Category.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ClassModel.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ClassModel.pm
index 43466b5250..f30461a570 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ClassModel.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ClassModel.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Client.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Client.pm
index a60ed0bbbf..41884d9766 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Client.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Client.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DeprecatedObject.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DeprecatedObject.pm
index cd1e7e6bde..f1cea97088 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DeprecatedObject.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DeprecatedObject.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Dog.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Dog.pm
index 5a09bf92a9..75c1ec4b12 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Dog.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Dog.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DogAllOf.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DogAllOf.pm
index b9b60b22ad..91a7955661 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DogAllOf.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/DogAllOf.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumArrays.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumArrays.pm
index fc3051a33f..d643ec1c31 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumArrays.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumArrays.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumClass.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumClass.pm
index 98917574d1..de44e861e1 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumClass.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumClass.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumTest.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumTest.pm
index 4d12ae2544..44309f3b79 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumTest.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/EnumTest.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/File.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/File.pm
index ba5693d738..b1f2fabb43 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/File.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/File.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FileSchemaTestClass.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FileSchemaTestClass.pm
index 420be77669..6db1af4d32 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FileSchemaTestClass.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FileSchemaTestClass.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Foo.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Foo.pm
index e400a15003..0f46ea56d7 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Foo.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Foo.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FooGetDefaultResponse.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FooGetDefaultResponse.pm
index 55ef2490ba..58b6840640 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FooGetDefaultResponse.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FooGetDefaultResponse.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FormatTest.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FormatTest.pm
index 9091a6b344..8650282129 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FormatTest.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/FormatTest.pm
@@ -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',
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HasOnlyReadOnly.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HasOnlyReadOnly.pm
index 356ca35907..b4d3279295 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HasOnlyReadOnly.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HasOnlyReadOnly.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HealthCheckResult.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HealthCheckResult.pm
index 7665da0f57..3597ad7910 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HealthCheckResult.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/HealthCheckResult.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/List.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/List.pm
index f88f37aa6e..4079df60b5 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/List.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/List.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MapTest.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MapTest.pm
index 6fb048ca8e..6e1eef560a 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MapTest.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MapTest.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MixedPropertiesAndAdditionalPropertiesClass.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MixedPropertiesAndAdditionalPropertiesClass.pm
index 49bc4d8008..14b36c0b9d 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MixedPropertiesAndAdditionalPropertiesClass.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/MixedPropertiesAndAdditionalPropertiesClass.pm
@@ -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]'
} );
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Model200Response.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Model200Response.pm
index b6ba3d4fea..bf5e8982fd 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Model200Response.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Model200Response.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ModelReturn.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ModelReturn.pm
index a2b9dd03e9..830cd139e2 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ModelReturn.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ModelReturn.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Name.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Name.pm
index 905fc94c75..98bc8cb8e5 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Name.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Name.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NullableClass.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NullableClass.pm
index eb35f4c6b3..ecff001261 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NullableClass.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NullableClass.pm
@@ -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]',
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NumberOnly.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NumberOnly.pm
index 990cf69ef8..e68bf9c257 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NumberOnly.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/NumberOnly.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ObjectWithDeprecatedFields.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ObjectWithDeprecatedFields.pm
index 3980ecf0a2..b1645a4c9d 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ObjectWithDeprecatedFields.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ObjectWithDeprecatedFields.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Order.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Order.pm
index e4a9f74599..6420432525 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Order.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Order.pm
@@ -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'
} );
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterComposite.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterComposite.pm
index f0643e54ad..c41a1bf716 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterComposite.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterComposite.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnum.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnum.pm
index a07684584a..b891f0e7c4 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnum.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnum.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumDefaultValue.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumDefaultValue.pm
index 9b14db60a3..28aa622afe 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumDefaultValue.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumDefaultValue.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumInteger.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumInteger.pm
index 14ff2ff095..7c50183625 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumInteger.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumInteger.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumIntegerDefaultValue.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumIntegerDefaultValue.pm
index 3c10bfe39f..c2e3b5bff3 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumIntegerDefaultValue.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterEnumIntegerDefaultValue.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterObjectWithEnumProperty.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterObjectWithEnumProperty.pm
index 12e1846b53..54e2310624 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterObjectWithEnumProperty.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/OuterObjectWithEnumProperty.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Pet.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Pet.pm
index 43f2672c95..c94165e283 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Pet.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Pet.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ReadOnlyFirst.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ReadOnlyFirst.pm
index 1563ebce86..23f5d6e686 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ReadOnlyFirst.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/ReadOnlyFirst.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SingleRefType.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SingleRefType.pm
index 3211fd33ea..a2d098a691 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SingleRefType.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SingleRefType.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SpecialModelName.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SpecialModelName.pm
index fa9de2f527..5814b31aae 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SpecialModelName.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/SpecialModelName.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Tag.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Tag.pm
index 998d3179a3..2e220492dc 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Tag.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/Tag.pm
@@ -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);
diff --git a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/User.pm b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/User.pm
index e301902cc0..f46fab05d5 100644
--- a/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/User.pm
+++ b/samples/client/petstore/perl/lib/WWW/OpenAPIClient/Object/User.pm
@@ -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);
diff --git a/samples/client/petstore/perl/tests/02_store_api.t b/samples/client/petstore/perl/tests/02_store_api.t
index ee721210cd..36e54ed12f 100644
--- a/samples/client/petstore/perl/tests/02_store_api.t
+++ b/samples/client/petstore/perl/tests/02_store_api.t
@@ -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 = <deserialize("HASH[string,Pet]", $pet_json)->{pet}->{photo_urls}-
my $array_json = <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';
\ No newline at end of file