diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java index 8b677d07c4b..be2a47e6a0e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java @@ -218,6 +218,8 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toModelName(String name) { + name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + // model name cannot use reserved keyword if (isReservedWord(name)) { LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name)); @@ -225,7 +227,13 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { } // add prefix/suffic to model name - name = modelNamePrefix + name + modelNameSuffix; + if (!StringUtils.isEmpty(modelNamePrefix)) { + name = modelNamePrefix + "_" + name; + } + + if (!StringUtils.isEmpty(modelNameSuffix)) { + name = name + "_" + modelNameSuffix; + } // camelize the model name // phone_number => PhoneNumber diff --git a/samples/client/petstore/perl/README.md b/samples/client/petstore/perl/README.md index aec4a513ef5..06dc39ccad2 100644 --- a/samples/client/petstore/perl/README.md +++ b/samples/client/petstore/perl/README.md @@ -8,7 +8,7 @@ WWW::SwaggerClient::Role - a Moose role for the Swagger Petstore Automatically generated by the Perl Swagger Codegen project: -- Build date: 2016-03-03T20:09:18.907+08:00 +- Build date: 2016-03-04T14:39:09.479+08:00 - Build package: class io.swagger.codegen.languages.PerlClientCodegen - Codegen version: diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/InlineResponse200.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/InlineResponse200.pm new file mode 100644 index 00000000000..61ce10e3a2e --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/InlineResponse200.pm @@ -0,0 +1,145 @@ +package WWW::SwaggerClient::Object::InlineResponse200; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use JSON qw(decode_json); +use Data::Dumper; +use Module::Runtime qw(use_module); +use Log::Any qw($log); +use Date::Parse; +use DateTime; + +use base ("Class::Accessor", "Class::Data::Inheritable"); + + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +__PACKAGE__->mk_classdata('attribute_map' => {}); +__PACKAGE__->mk_classdata('swagger_types' => {}); +__PACKAGE__->mk_classdata('method_documentation' => {}); +__PACKAGE__->mk_classdata('class_documentation' => {}); + +# new object +sub new { + my ($class, %args) = @_; + + my $self = bless {}, $class; + + foreach my $attribute (keys %{$class->attribute_map}) { + my $args_key = $class->attribute_map->{$attribute}; + $self->$attribute( $args{ $args_key } ); + } + + return $self; +} + +# return perl hash +sub to_hash { + return decode_json(JSON->new->convert_blessed->encode( shift )); +} + +# used by JSON for serialization +sub TO_JSON { + my $self = shift; + my $_data = {}; + foreach my $_key (keys %{$self->attribute_map}) { + if (defined $self->{$_key}) { + $_data->{$self->attribute_map->{$_key}} = $self->{$_key}; + } + } + return $_data; +} + +# from Perl hashref +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} ) { + my $_json_attribute = $self->attribute_map->{$_key}; + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$_json_attribute}}) { + push @_array, $self->_deserialize($_subclass, $_element); + } + $self->{$_key} = \@_array; + } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime + $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute}); + } else { + $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute); + } + } + + 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$/, ('int', 'double', 'string', 'boolean'))) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; + return $_instance->from_hash($data); + } +} + + + +__PACKAGE__->class_documentation({description => '', + class => 'InlineResponse200', + required => [], # TODO +} ); + +__PACKAGE__->method_documentation({ + 'id' => { + datatype => 'int', + base_name => 'id', + description => '', + format => '', + read_only => '', + }, + 'category' => { + datatype => 'object', + base_name => 'category', + description => '', + format => '', + read_only => '', + }, + 'name' => { + datatype => 'string', + base_name => 'name', + description => '', + format => '', + read_only => '', + }, + +}); + +__PACKAGE__->swagger_types( { + 'id' => 'int', + 'category' => 'object', + 'name' => 'string' +} ); + +__PACKAGE__->attribute_map( { + 'id' => 'id', + 'category' => 'category', + 'name' => 'name' +} ); + +__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map}); + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/ObjectReturn.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/ObjectReturn.pm new file mode 100644 index 00000000000..6dec8a34c54 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/ObjectReturn.pm @@ -0,0 +1,127 @@ +package WWW::SwaggerClient::Object::ObjectReturn; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use JSON qw(decode_json); +use Data::Dumper; +use Module::Runtime qw(use_module); +use Log::Any qw($log); +use Date::Parse; +use DateTime; + +use base ("Class::Accessor", "Class::Data::Inheritable"); + + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +__PACKAGE__->mk_classdata('attribute_map' => {}); +__PACKAGE__->mk_classdata('swagger_types' => {}); +__PACKAGE__->mk_classdata('method_documentation' => {}); +__PACKAGE__->mk_classdata('class_documentation' => {}); + +# new object +sub new { + my ($class, %args) = @_; + + my $self = bless {}, $class; + + foreach my $attribute (keys %{$class->attribute_map}) { + my $args_key = $class->attribute_map->{$attribute}; + $self->$attribute( $args{ $args_key } ); + } + + return $self; +} + +# return perl hash +sub to_hash { + return decode_json(JSON->new->convert_blessed->encode( shift )); +} + +# used by JSON for serialization +sub TO_JSON { + my $self = shift; + my $_data = {}; + foreach my $_key (keys %{$self->attribute_map}) { + if (defined $self->{$_key}) { + $_data->{$self->attribute_map->{$_key}} = $self->{$_key}; + } + } + return $_data; +} + +# from Perl hashref +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} ) { + my $_json_attribute = $self->attribute_map->{$_key}; + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$_json_attribute}}) { + push @_array, $self->_deserialize($_subclass, $_element); + } + $self->{$_key} = \@_array; + } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime + $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute}); + } else { + $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute); + } + } + + 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$/, ('int', 'double', 'string', 'boolean'))) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; + return $_instance->from_hash($data); + } +} + + + +__PACKAGE__->class_documentation({description => '', + class => 'ObjectReturn', + required => [], # TODO +} ); + +__PACKAGE__->method_documentation({ + 'return' => { + datatype => 'int', + base_name => 'return', + description => '', + format => '', + read_only => '', + }, + +}); + +__PACKAGE__->swagger_types( { + 'return' => 'int' +} ); + +__PACKAGE__->attribute_map( { + 'return' => 'return' +} ); + +__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map}); + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/SpecialModelName.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/SpecialModelName.pm new file mode 100644 index 00000000000..b720c10b1a6 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/SpecialModelName.pm @@ -0,0 +1,127 @@ +package WWW::SwaggerClient::Object::SpecialModelName; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use JSON qw(decode_json); +use Data::Dumper; +use Module::Runtime qw(use_module); +use Log::Any qw($log); +use Date::Parse; +use DateTime; + +use base ("Class::Accessor", "Class::Data::Inheritable"); + + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +__PACKAGE__->mk_classdata('attribute_map' => {}); +__PACKAGE__->mk_classdata('swagger_types' => {}); +__PACKAGE__->mk_classdata('method_documentation' => {}); +__PACKAGE__->mk_classdata('class_documentation' => {}); + +# new object +sub new { + my ($class, %args) = @_; + + my $self = bless {}, $class; + + foreach my $attribute (keys %{$class->attribute_map}) { + my $args_key = $class->attribute_map->{$attribute}; + $self->$attribute( $args{ $args_key } ); + } + + return $self; +} + +# return perl hash +sub to_hash { + return decode_json(JSON->new->convert_blessed->encode( shift )); +} + +# used by JSON for serialization +sub TO_JSON { + my $self = shift; + my $_data = {}; + foreach my $_key (keys %{$self->attribute_map}) { + if (defined $self->{$_key}) { + $_data->{$self->attribute_map->{$_key}} = $self->{$_key}; + } + } + return $_data; +} + +# from Perl hashref +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} ) { + my $_json_attribute = $self->attribute_map->{$_key}; + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$_json_attribute}}) { + push @_array, $self->_deserialize($_subclass, $_element); + } + $self->{$_key} = \@_array; + } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime + $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute}); + } else { + $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute); + } + } + + 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$/, ('int', 'double', 'string', 'boolean'))) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; + return $_instance->from_hash($data); + } +} + + + +__PACKAGE__->class_documentation({description => '', + class => 'SpecialModelName', + required => [], # TODO +} ); + +__PACKAGE__->method_documentation({ + '__special[property/name]' => { + datatype => 'int', + base_name => '$special[property.name]', + description => '', + format => '', + read_only => '', + }, + +}); + +__PACKAGE__->swagger_types( { + '__special[property/name]' => 'int' +} ); + +__PACKAGE__->attribute_map( { + '__special[property/name]' => '$special[property.name]' +} ); + +__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map}); + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role.pm index 033ba9a0dc5..1334b695271 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role.pm @@ -37,7 +37,7 @@ has version_info => ( is => 'ro', default => sub { { app_name => 'Swagger Petstore', app_version => '1.0.0', - generated_date => '2016-03-03T20:09:18.907+08:00', + generated_date => '2016-03-04T14:39:09.479+08:00', generator_class => 'class io.swagger.codegen.languages.PerlClientCodegen', } }, documentation => 'Information about the application version and the codegen codebase version' @@ -103,7 +103,7 @@ Automatically generated by the Perl Swagger Codegen project: =over 4 -=item Build date: 2016-03-03T20:09:18.907+08:00 +=item Build date: 2016-03-04T14:39:09.479+08:00 =item Build package: class io.swagger.codegen.languages.PerlClientCodegen diff --git a/samples/client/petstore/perl/t/CategoryTest.t b/samples/client/petstore/perl/t/CategoryTest.t index 93534938102..495d4202ec5 100644 --- a/samples/client/petstore/perl/t/CategoryTest.t +++ b/samples/client/petstore/perl/t/CategoryTest.t @@ -1,3 +1,6 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + use Test::More tests => 2; use Test::Exception; diff --git a/samples/client/petstore/perl/t/InlineResponse200Test.t b/samples/client/petstore/perl/t/InlineResponse200Test.t new file mode 100644 index 00000000000..404dc64b7e3 --- /dev/null +++ b/samples/client/petstore/perl/t/InlineResponse200Test.t @@ -0,0 +1,17 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + +use Test::More tests => 2; +use Test::Exception; + +use lib 'lib'; +use strict; +use warnings; + + +use_ok('WWW::SwaggerClient::Object::InlineResponse200'); + +my $instance = WWW::SwaggerClient::Object::InlineResponse200->new(); + +isa_ok($instance, 'WWW::SwaggerClient::Object::InlineResponse200'); + diff --git a/samples/client/petstore/perl/t/ObjectReturnTest.t b/samples/client/petstore/perl/t/ObjectReturnTest.t new file mode 100644 index 00000000000..a703141bb4e --- /dev/null +++ b/samples/client/petstore/perl/t/ObjectReturnTest.t @@ -0,0 +1,17 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + +use Test::More tests => 2; +use Test::Exception; + +use lib 'lib'; +use strict; +use warnings; + + +use_ok('WWW::SwaggerClient::Object::ObjectReturn'); + +my $instance = WWW::SwaggerClient::Object::ObjectReturn->new(); + +isa_ok($instance, 'WWW::SwaggerClient::Object::ObjectReturn'); + diff --git a/samples/client/petstore/perl/t/OrderTest.t b/samples/client/petstore/perl/t/OrderTest.t index 5ec9b3d9802..36871c896c6 100644 --- a/samples/client/petstore/perl/t/OrderTest.t +++ b/samples/client/petstore/perl/t/OrderTest.t @@ -1,3 +1,6 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + use Test::More tests => 2; use Test::Exception; diff --git a/samples/client/petstore/perl/t/PetApiTest.t b/samples/client/petstore/perl/t/PetApiTest.t index 52211d2e95f..ec4723812a9 100644 --- a/samples/client/petstore/perl/t/PetApiTest.t +++ b/samples/client/petstore/perl/t/PetApiTest.t @@ -14,8 +14,8 @@ # limitations under the License. # # -# NOTE: This class is auto generated by the swagger code generator program. -# Do not edit the class manually. +# NOTE: This class is auto generated by Swagger Codegen +# Please update the test case below to test the API endpoints. # use Test::More tests => 1; #TODO update number of test cases use Test::Exception; diff --git a/samples/client/petstore/perl/t/PetTest.t b/samples/client/petstore/perl/t/PetTest.t index bae56462a36..54a2888dbe8 100644 --- a/samples/client/petstore/perl/t/PetTest.t +++ b/samples/client/petstore/perl/t/PetTest.t @@ -1,3 +1,6 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + use Test::More tests => 2; use Test::Exception; diff --git a/samples/client/petstore/perl/t/SpecialModelNameTest.t b/samples/client/petstore/perl/t/SpecialModelNameTest.t new file mode 100644 index 00000000000..230db33bab8 --- /dev/null +++ b/samples/client/petstore/perl/t/SpecialModelNameTest.t @@ -0,0 +1,17 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + +use Test::More tests => 2; +use Test::Exception; + +use lib 'lib'; +use strict; +use warnings; + + +use_ok('WWW::SwaggerClient::Object::SpecialModelName'); + +my $instance = WWW::SwaggerClient::Object::SpecialModelName->new(); + +isa_ok($instance, 'WWW::SwaggerClient::Object::SpecialModelName'); + diff --git a/samples/client/petstore/perl/t/StoreApiTest.t b/samples/client/petstore/perl/t/StoreApiTest.t index 49257eaf3cd..3772914c7aa 100644 --- a/samples/client/petstore/perl/t/StoreApiTest.t +++ b/samples/client/petstore/perl/t/StoreApiTest.t @@ -14,8 +14,8 @@ # limitations under the License. # # -# NOTE: This class is auto generated by the swagger code generator program. -# Do not edit the class manually. +# NOTE: This class is auto generated by Swagger Codegen +# Please update the test case below to test the API endpoints. # use Test::More tests => 1; #TODO update number of test cases use Test::Exception; diff --git a/samples/client/petstore/perl/t/TagTest.t b/samples/client/petstore/perl/t/TagTest.t index 49a44e4e843..bde9da8c69e 100644 --- a/samples/client/petstore/perl/t/TagTest.t +++ b/samples/client/petstore/perl/t/TagTest.t @@ -1,3 +1,6 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + use Test::More tests => 2; use Test::Exception; diff --git a/samples/client/petstore/perl/t/UserApiTest.t b/samples/client/petstore/perl/t/UserApiTest.t index 97294919612..e0bf708ca48 100644 --- a/samples/client/petstore/perl/t/UserApiTest.t +++ b/samples/client/petstore/perl/t/UserApiTest.t @@ -14,8 +14,8 @@ # limitations under the License. # # -# NOTE: This class is auto generated by the swagger code generator program. -# Do not edit the class manually. +# NOTE: This class is auto generated by Swagger Codegen +# Please update the test case below to test the API endpoints. # use Test::More tests => 1; #TODO update number of test cases use Test::Exception; diff --git a/samples/client/petstore/perl/t/UserTest.t b/samples/client/petstore/perl/t/UserTest.t index edf1d66777b..260595540be 100644 --- a/samples/client/petstore/perl/t/UserTest.t +++ b/samples/client/petstore/perl/t/UserTest.t @@ -1,3 +1,6 @@ +# NOTE: This class is auto generated by the Swagger Codegen +# Please update the test case below to test the model. + use Test::More tests => 2; use Test::Exception;