forked from loafle/openapi-generator-original
add methods for static variable
This commit is contained in:
@@ -28,9 +28,9 @@ sub to_hash {
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $self->{attribute_map}) {
|
||||
if (defined $self->{$self->{attribute_map}->{$_key}}) {
|
||||
$_data->{$self->{attribute_map}->{$_key}} = $self->{$_key};
|
||||
foreach my $_key (keys $self->get_attribute_map) {
|
||||
if (defined $self->{$self->get_attribute_map->{$_key}}) {
|
||||
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
@@ -40,11 +40,11 @@ sub TO_JSON {
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $self->{swagger_types}) {
|
||||
while ( my ($_key, $_type) = each $self->get_swagger_types ) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$self->{attribute_map}->{$_key}}}) {
|
||||
foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
|
||||
@@ -43,61 +43,16 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# return json string
|
||||
sub to_hash {
|
||||
return decode_json(JSON->new->convert_blessed->encode( shift ));
|
||||
# get swagger type of the attribute
|
||||
sub get_swagger_types {
|
||||
return $swagger_types;
|
||||
}
|
||||
|
||||
# used by JSON for serialization
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $attribute_map) {
|
||||
if (defined $self->{$attribute_map->{$_key}}) {
|
||||
$_data->{$attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
# get attribute mappping
|
||||
sub get_attribute_map {
|
||||
return $attribute_map;
|
||||
}
|
||||
|
||||
# from json string
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $swagger_types) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
} elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
|
||||
$self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
|
||||
} else {
|
||||
$log->debugf("warning: %s not defined\n", $_key);
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# deserialize non-array data
|
||||
sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) {
|
||||
return $data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
}
|
||||
}
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
1;
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -28,9 +28,9 @@ sub to_hash {
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $self->{attribute_map}) {
|
||||
if (defined $self->{$self->{attribute_map}->{$_key}}) {
|
||||
$_data->{$self->{attribute_map}->{$_key}} = $self->{$_key};
|
||||
foreach my $_key (keys $self->get_attribute_map) {
|
||||
if (defined $self->{$self->get_attribute_map->{$_key}}) {
|
||||
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
@@ -40,11 +40,11 @@ sub TO_JSON {
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $self->{swagger_types}) {
|
||||
while ( my ($_key, $_type) = each $self->get_swagger_types ) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$self->{attribute_map}->{$_key}}}) {
|
||||
foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
|
||||
@@ -42,59 +42,14 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# return json string
|
||||
sub to_hash {
|
||||
return decode_json(JSON->new->convert_blessed->encode( shift ));
|
||||
# get swagger type of the attribute
|
||||
sub get_swagger_types {
|
||||
return $swagger_types;
|
||||
}
|
||||
|
||||
# used by JSON for serialization
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $attribute_map) {
|
||||
if (defined $self->{$attribute_map->{$_key}}) {
|
||||
$_data->{$attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
# get attribute mappping
|
||||
sub get_attribute_map {
|
||||
return $attribute_map;
|
||||
}
|
||||
|
||||
# from json string
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $swagger_types) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
} elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
|
||||
$self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
|
||||
} else {
|
||||
$log->debugf("warning: %s not defined\n", $_key);
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# deserialize non-array data
|
||||
sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) {
|
||||
return $data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::SwaggerClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
@@ -58,59 +58,14 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# return json string
|
||||
sub to_hash {
|
||||
return decode_json(JSON->new->convert_blessed->encode( shift ));
|
||||
# get swagger type of the attribute
|
||||
sub get_swagger_types {
|
||||
return $swagger_types;
|
||||
}
|
||||
|
||||
# used by JSON for serialization
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $attribute_map) {
|
||||
if (defined $self->{$attribute_map->{$_key}}) {
|
||||
$_data->{$attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
# get attribute mappping
|
||||
sub get_attribute_map {
|
||||
return $attribute_map;
|
||||
}
|
||||
|
||||
# from json string
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $swagger_types) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
} elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
|
||||
$self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
|
||||
} else {
|
||||
$log->debugf("warning: %s not defined\n", $_key);
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# deserialize non-array data
|
||||
sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) {
|
||||
return $data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::SwaggerClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
@@ -58,59 +58,14 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# return json string
|
||||
sub to_hash {
|
||||
return decode_json(JSON->new->convert_blessed->encode( shift ));
|
||||
# get swagger type of the attribute
|
||||
sub get_swagger_types {
|
||||
return $swagger_types;
|
||||
}
|
||||
|
||||
# used by JSON for serialization
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $attribute_map) {
|
||||
if (defined $self->{$attribute_map->{$_key}}) {
|
||||
$_data->{$attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
# get attribute mappping
|
||||
sub get_attribute_map {
|
||||
return $attribute_map;
|
||||
}
|
||||
|
||||
# from json string
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $swagger_types) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
} elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
|
||||
$self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
|
||||
} else {
|
||||
$log->debugf("warning: %s not defined\n", $_key);
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# deserialize non-array data
|
||||
sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) {
|
||||
return $data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::SwaggerClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
@@ -42,59 +42,14 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# return json string
|
||||
sub to_hash {
|
||||
return decode_json(JSON->new->convert_blessed->encode( shift ));
|
||||
# get swagger type of the attribute
|
||||
sub get_swagger_types {
|
||||
return $swagger_types;
|
||||
}
|
||||
|
||||
# used by JSON for serialization
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $attribute_map) {
|
||||
if (defined $self->{$attribute_map->{$_key}}) {
|
||||
$_data->{$attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
# get attribute mappping
|
||||
sub get_attribute_map {
|
||||
return $attribute_map;
|
||||
}
|
||||
|
||||
# from json string
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $swagger_types) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
} elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
|
||||
$self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
|
||||
} else {
|
||||
$log->debugf("warning: %s not defined\n", $_key);
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# deserialize non-array data
|
||||
sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) {
|
||||
return $data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::SwaggerClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
@@ -66,59 +66,14 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
# return json string
|
||||
sub to_hash {
|
||||
return decode_json(JSON->new->convert_blessed->encode( shift ));
|
||||
# get swagger type of the attribute
|
||||
sub get_swagger_types {
|
||||
return $swagger_types;
|
||||
}
|
||||
|
||||
# used by JSON for serialization
|
||||
sub TO_JSON {
|
||||
my $self = shift;
|
||||
my $_data = {};
|
||||
foreach my $_key (keys $attribute_map) {
|
||||
if (defined $self->{$attribute_map->{$_key}}) {
|
||||
$_data->{$attribute_map->{$_key}} = $self->{$_key};
|
||||
}
|
||||
}
|
||||
return $_data;
|
||||
# get attribute mappping
|
||||
sub get_attribute_map {
|
||||
return $attribute_map;
|
||||
}
|
||||
|
||||
# from json string
|
||||
sub from_hash {
|
||||
my ($self, $hash) = @_;
|
||||
# loop through attributes and use swagger_types to deserialize the data
|
||||
while ( my ($_key, $_type) = each $swagger_types) {
|
||||
if ($_type =~ /^array\[/i) { # array
|
||||
my $_subclass = substr($_type, 6, -1);
|
||||
my @_array = ();
|
||||
foreach my $_element (@{$hash->{$attribute_map->{$_key}}}) {
|
||||
push @_array, $self->_deserialize($_subclass, $_element);
|
||||
}
|
||||
$self->{$_key} = \@_array;
|
||||
} elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
|
||||
$self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
|
||||
} else {
|
||||
$log->debugf("warning: %s not defined\n", $_key);
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# deserialize non-array data
|
||||
sub _deserialize {
|
||||
my ($self, $type, $data) = @_;
|
||||
$log->debugf("deserializing %s with %s",Dumper($data), $type);
|
||||
|
||||
if ($type eq 'DateTime') {
|
||||
return DateTime->from_epoch(epoch => str2time($data));
|
||||
} elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) {
|
||||
return $data;
|
||||
} else { # hash(model)
|
||||
my $_instance = eval "WWW::SwaggerClient::Object::$type->new()";
|
||||
return $_instance->from_hash($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
@@ -11,20 +11,35 @@ use WWW::SwaggerClient::Object::Tag;
|
||||
use WWW::SwaggerClient::Object::Category;
|
||||
use JSON;
|
||||
use Data::Dumper;
|
||||
use DateTime;
|
||||
|
||||
my $api = WWW::SwaggerClient::PetApi->new();
|
||||
|
||||
#print WWW::SwaggerClient::APIClient::to_form_value('testing 123');
|
||||
|
||||
my $pet_id = 5;
|
||||
my $dt = DateTime->new(
|
||||
year => 1972,
|
||||
month => 12,
|
||||
day => 31,
|
||||
hour => 23,
|
||||
minute => 59,
|
||||
second => 30,
|
||||
time_zone => 'UTC'
|
||||
);
|
||||
|
||||
print "dt = $dt\n";
|
||||
print "dt = ".$dt->datetime()."\n";
|
||||
|
||||
|
||||
my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => 'tag1', 'name' => 'just kidding',
|
||||
"photoUrls" => ['123', 'oop']});
|
||||
my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => 5, 'name' => 'haha',
|
||||
"photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => '2003-04-05 02:58:00'});
|
||||
"photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => $dt});
|
||||
|
||||
##print Dumper $pet;
|
||||
|
||||
print "pet ref=".ref($pet)."\n";
|
||||
print "tag ref=".ref($tag)."\n";
|
||||
my $json = JSON->new->convert_blessed;
|
||||
|
||||
#print $json->convert_blessed->encode($pet);
|
||||
@@ -34,7 +49,8 @@ print Dumper($pet->to_hash);
|
||||
my $pet2 = WWW::SwaggerClient::Object::Pet->new();
|
||||
$pet2 = $pet2->from_hash($pet->to_hash);
|
||||
#$pet2->from_json($pet->to_hash);
|
||||
##print Dumper($pet2->to_hash);
|
||||
print Dumper($pet2->to_hash);
|
||||
#exit;
|
||||
print "============================\n";
|
||||
print Dumper $api->get_pet_by_id({pet_id => $pet_id});
|
||||
print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'});
|
||||
|
||||
Reference in New Issue
Block a user