forked from loafle/openapi-generator-original
better model name for perl
This commit is contained in:
parent
ae54301ed7
commit
e0b16151f4
@ -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
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
17
samples/client/petstore/perl/t/InlineResponse200Test.t
Normal file
17
samples/client/petstore/perl/t/InlineResponse200Test.t
Normal file
@ -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');
|
||||
|
17
samples/client/petstore/perl/t/ObjectReturnTest.t
Normal file
17
samples/client/petstore/perl/t/ObjectReturnTest.t
Normal file
@ -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');
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
17
samples/client/petstore/perl/t/SpecialModelNameTest.t
Normal file
17
samples/client/petstore/perl/t/SpecialModelNameTest.t
Normal file
@ -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');
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user