diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java index b25e4490e85..8f8ff21bc58 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java @@ -77,6 +77,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("map", "HASH"); supportingFiles.add(new SupportingFile("APIClient.mustache", "lib/WWW/" + invokerPackage, "APIClient.pm")); + supportingFiles.add(new SupportingFile("Configuration.mustache", "lib/WWW/" + invokerPackage, "Configuration.pm")); supportingFiles.add(new SupportingFile("BaseObject.mustache", "lib/WWW/" + invokerPackage, "Object/BaseObject.pm")); } diff --git a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache index 19079a07922..5d5dc0cdb96 100644 --- a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache @@ -15,20 +15,16 @@ use URI::Escape; use Scalar::Util; use Log::Any qw($log); use Carp; -use Switch; use Module::Runtime qw(use_module); -# class variables -my $ua = LWP::UserAgent->new; -my $http_user_agent = 'Perl-Swagger'; # HTTP user-agent -my $http_timeout; #timeout -my $base_url = "{{basePath}}"; - - sub new { my $class = shift; - my %args = @_; + my (%args) = ( + 'ua' => LWP::UserAgent->new, + 'base_url' => '{{basePath}}', + @_ + ); return bless \%args, $class; } @@ -38,8 +34,8 @@ sub new # @param string $user_agent The user agent of the API client # sub set_user_agent { - my $user_agent = shift; - $http_user_agent= $user_agent; + my ($self, $user_agent) = @_; + $self->{http_user_agent}= $user_agent; } # Set timeout @@ -47,11 +43,11 @@ sub set_user_agent { # @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] # sub set_timeout { - my $seconds = shift; + my ($self, $seconds) = @_; if (!looks_like_number($seconds)) { croak('Timeout variable must be numeric.'); } - $http_timeout = $seconds; + $self->{http_timeout} = $seconds; } # make the HTTP request @@ -67,7 +63,7 @@ sub call_api { my $headers = HTTP::Headers->new(%$header_params); - my $_url = $base_url . $resource_path; + my $_url = $self->{base_url} . $resource_path; # build query if (%$query_params) { @@ -80,43 +76,42 @@ sub call_api { # Make the HTTP request my $_request; - switch ($method) { - case 'POST' { + if ($method eq 'POST') { # multipart my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ? 'form-data' : $header_params->{'Content-Type'}; $_request = POST($_url, Accept => $header_params->{Accept}, Content_Type => $_content_type, Content => $_body_data); - } - case 'PUT' { + } + elsif ($method eq 'PUT') { # multipart my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ? 'form-data' : $header_params->{'Content-Type'}; $_request = PUT($_url, Accept => $header_params->{Accept}, Content_Type => $_content_type, Content => $_body_data); - } - case 'GET' { + } + elsif ($method eq 'GET') { $_request = GET($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}); - } - case 'HEAD' { + } + elsif ($method eq 'HEAD') { $_request = HEAD($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}); - } - case 'DELETE' { #TODO support form data + } + elsif ($method eq 'DELETE') { #TODO support form data $_request = DELETE($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}, Content => $_body_data); - } - case 'PATCH' { #TODO - } - + } + elsif ($method eq 'PATCH') { #TODO + } + else { } - $ua->timeout($http_timeout); - $ua->agent($http_user_agent); + $self->{ua}->timeout($self->{http_timeout} || $WWW::{{invokerPackage}}::Configuration::http_timeout); + $self->{ua}->agent($self->{http_user_agent} || $WWW::{{invokerPackage}}::Configuration::http_user_agent); - my $_response = $ua->request($_request); + my $_response = $self->{ua}->request($_request); unless ($_response->is_success) { croak("API Exception(".$_response->code."): ".$_response->message); @@ -126,41 +121,13 @@ sub call_api { } - -# Build a JSON POST object -sub sanitize_for_serialization -{ -# my $data = shift; -# if (is_scalar($data) || null === $data) { -# $sanitized = $data; -# } else if ($data instanceof \DateTime) { -# $sanitized = $data->format(\DateTime::ISO8601); -# } else if (is_array($data)) { -# foreach ($data as $property => $value) { -# $data[$property] = $this->sanitizeForSerialization($value); -# } -# $sanitized = $data; -# } else if (is_object($data)) { -# $values = array(); -# foreach (array_keys($data::$swaggerTypes) as $property) { -# $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property); -# } -# $sanitized = $values; -# } else { -# $sanitized = (string)$data; -# } -# -# return $sanitized; -} - - # Take value and turn it into a string suitable for inclusion in # the path, by url-encoding. # @param string $value a string which will be part of the path # @return string the serialized object sub to_path_value { - my $value = shift; - return uri_escape(to_string($value)); + my ($self, $value) = @_; + return uri_escape($self->to_string($value)); } @@ -171,11 +138,11 @@ sub to_path_value { # @param object $object an object to be serialized to a string # @return string the serialized object sub to_query_value { - my $object = shift; + my ($self, $object) = @_; if (is_array($object)) { return implode(',', $object); } else { - return toString($object); + return $self->to_string($object); } } @@ -186,8 +153,8 @@ sub to_query_value { # @param string $value a string which will be part of the header # @return string the header string sub to_header_value { - my $value = shift; - return to_string($value); + my ($self, $value) = @_; + return $self->to_string($value); } # Take value and turn it into a string suitable for inclusion in @@ -196,8 +163,8 @@ sub to_header_value { # @param string $value the value of the form parameter # @return string the form string sub to_form_value { - my $value = shift; - return to_string($value); + my ($self, $value) = @_; + return $self->to_string($value); } # Take value and turn it into a string suitable for inclusion in @@ -206,7 +173,7 @@ sub to_form_value { # @param string $value the value of the parameter # @return string the header string sub to_string { - my $value = shift; + my ($self, $value) = @_; if (ref($value) eq "DateTime") { # datetime in ISO8601 format return $value->datetime(); } diff --git a/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache b/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache new file mode 100644 index 00000000000..0967dc136c3 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache @@ -0,0 +1,16 @@ +package WWW::{{invokerPackage}}::Configuration; + +use strict; +use warnings; +use utf8; + +use Log::Any qw($log); +use Carp; + +# class/static variables +my $api_client = WWW::SwaggerClient::APIClient->new; +my $http_timeout = 180; +my $http_user_agent = 'Perl-Swagger'; + + +1; diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache index 131eb3a3934..4996534c35e 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -28,9 +28,6 @@ use Carp qw( croak ); use Log::Any qw($log); -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - {{#operations}} use WWW::{{invokerPackage}}::APIClient; @@ -92,37 +89,34 @@ sub new { } $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type({{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}); - {{#queryParams}} # query params + {{#queryParams}}# query params if ( exists $args{'{{paramName}}'}) { - $query_params->{'{{baseName}}'} = WWW::{{invokerPacakge}}::APIClient::to_query_value($args{'{{paramName}}'}); + $query_params->{'{{baseName}}'} = $self->{api_client}->to_query_value($args{'{{paramName}}'}); }{{/queryParams}} - {{#headerParams}} # header params + {{#headerParams}}# header params if ( exists $args{'{{paramName}}'}) { - $header_params->{'{{baseName}}'} = WWW::{{invokerPackage}}::APIClient::to_header_value($args{'{{paramName}}'}); + $header_params->{'{{baseName}}'} = $self->{api_client}->to_header_value($args{'{{paramName}}'}); }{{/headerParams}} - {{#pathParams}} # path params + {{#pathParams}}# path params if ( exists $args{'{{paramName}}'}) { my $_base_variable = "{" . "{{baseName}}" . "}"; - my $_base_value = WWW::{{invokerPackage}}::APIClient::to_path_value($args{'{{paramName}}'}); + my $_base_value = $self->{api_client}->to_path_value($args{'{{paramName}}'}); $_resource_path =~ s/$_base_variable/$_base_value/g; }{{/pathParams}} - {{#formParams}} # form params + {{#formParams}}# form params if ( exists $args{'{{paramName}}'} ) { {{#isFile}}$form_params->{'{{baseName}}'} = [] unless defined $form_params->{'{{baseName}}'}; push $form_params->{'{{baseName}}'}, $args{'{{paramName}}'}; {{/isFile}} - {{^isFile}}$form_params->{'{{baseName}}'} = WWW::{{invokerPackage}}::APIClient::to_form_value($args{'{{paramName}}'}); + {{^isFile}}$form_params->{'{{baseName}}'} = $self->{api_client}->to_form_value($args{'{{paramName}}'}); {{/isFile}} }{{/formParams}} my $_body_data; - {{#bodyParams}} # body params + {{#bodyParams}}# body params if ( exists $args{'{{paramName}}'}) { $_body_data = $args{'{{paramName}}'}; }{{/bodyParams}} - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call {{#returnType}}my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm index 0f0fea793e3..cf4ec0db4f3 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -15,20 +15,16 @@ use URI::Escape; use Scalar::Util; use Log::Any qw($log); use Carp; -use Switch; use Module::Runtime qw(use_module); -# class variables -my $ua = LWP::UserAgent->new; -my $http_user_agent = 'Perl-Swagger'; # HTTP user-agent -my $http_timeout; #timeout -my $base_url = "http://petstore.swagger.io/v2"; - - sub new { my $class = shift; - my %args = @_; + my (%args) = ( + 'ua' => LWP::UserAgent->new, + 'base_url' => 'http://petstore.swagger.io/v2', + @_ + ); return bless \%args, $class; } @@ -38,8 +34,8 @@ sub new # @param string $user_agent The user agent of the API client # sub set_user_agent { - my $user_agent = shift; - $http_user_agent= $user_agent; + my ($self, $user_agent) = @_; + $self->{http_user_agent}= $user_agent; } # Set timeout @@ -47,11 +43,11 @@ sub set_user_agent { # @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] # sub set_timeout { - my $seconds = shift; + my ($self, $seconds) = @_; if (!looks_like_number($seconds)) { croak('Timeout variable must be numeric.'); } - $http_timeout = $seconds; + $self->{http_timeout} = $seconds; } # make the HTTP request @@ -67,7 +63,7 @@ sub call_api { my $headers = HTTP::Headers->new(%$header_params); - my $_url = $base_url . $resource_path; + my $_url = $self->{base_url} . $resource_path; # build query if (%$query_params) { @@ -80,43 +76,42 @@ sub call_api { # Make the HTTP request my $_request; - switch ($method) { - case 'POST' { + if ($method eq 'POST') { # multipart my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ? 'form-data' : $header_params->{'Content-Type'}; $_request = POST($_url, Accept => $header_params->{Accept}, Content_Type => $_content_type, Content => $_body_data); - } - case 'PUT' { + } + elsif ($method eq 'PUT') { # multipart my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ? 'form-data' : $header_params->{'Content-Type'}; $_request = PUT($_url, Accept => $header_params->{Accept}, Content_Type => $_content_type, Content => $_body_data); - } - case 'GET' { + } + elsif ($method eq 'GET') { $_request = GET($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}); - } - case 'HEAD' { + } + elsif ($method eq 'HEAD') { $_request = HEAD($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}); - } - case 'DELETE' { #TODO support form data + } + elsif ($method eq 'DELETE') { #TODO support form data $_request = DELETE($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}, Content => $_body_data); - } - case 'PATCH' { #TODO - } - + } + elsif ($method eq 'PATCH') { #TODO + } + else { } - $ua->timeout($http_timeout); - $ua->agent($http_user_agent); + $self->{ua}->timeout($self->{http_timeout} || $WWW::SwaggerClient::Configuration::http_timeout); + $self->{ua}->agent($self->{http_user_agent} || $WWW::SwaggerClient::Configuration::http_user_agent); - my $_response = $ua->request($_request); + my $_response = $self->{ua}->request($_request); unless ($_response->is_success) { croak("API Exception(".$_response->code."): ".$_response->message); @@ -126,41 +121,13 @@ sub call_api { } - -# Build a JSON POST object -sub sanitize_for_serialization -{ -# my $data = shift; -# if (is_scalar($data) || null === $data) { -# $sanitized = $data; -# } else if ($data instanceof \DateTime) { -# $sanitized = $data->format(\DateTime::ISO8601); -# } else if (is_array($data)) { -# foreach ($data as $property => $value) { -# $data[$property] = $this->sanitizeForSerialization($value); -# } -# $sanitized = $data; -# } else if (is_object($data)) { -# $values = array(); -# foreach (array_keys($data::$swaggerTypes) as $property) { -# $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property); -# } -# $sanitized = $values; -# } else { -# $sanitized = (string)$data; -# } -# -# return $sanitized; -} - - # Take value and turn it into a string suitable for inclusion in # the path, by url-encoding. # @param string $value a string which will be part of the path # @return string the serialized object sub to_path_value { - my $value = shift; - return uri_escape(to_string($value)); + my ($self, $value) = @_; + return uri_escape($self->to_string($value)); } @@ -171,11 +138,11 @@ sub to_path_value { # @param object $object an object to be serialized to a string # @return string the serialized object sub to_query_value { - my $object = shift; + my ($self, $object) = @_; if (is_array($object)) { return implode(',', $object); } else { - return toString($object); + return $self->to_string($object); } } @@ -186,8 +153,8 @@ sub to_query_value { # @param string $value a string which will be part of the header # @return string the header string sub to_header_value { - my $value = shift; - return to_string($value); + my ($self, $value) = @_; + return $self->to_string($value); } # Take value and turn it into a string suitable for inclusion in @@ -196,8 +163,8 @@ sub to_header_value { # @param string $value the value of the form parameter # @return string the form string sub to_form_value { - my $value = shift; - return to_string($value); + my ($self, $value) = @_; + return $self->to_string($value); } # Take value and turn it into a string suitable for inclusion in @@ -206,7 +173,7 @@ sub to_form_value { # @param string $value the value of the parameter # @return string the header string sub to_string { - my $value = shift; + my ($self, $value) = @_; if (ref($value) eq "DateTime") { # datetime in ISO8601 format return $value->datetime(); } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm new file mode 100644 index 00000000000..b8c57e66843 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm @@ -0,0 +1,16 @@ +package WWW::SwaggerClient::Configuration; + +use strict; +use warnings; +use utf8; + +use Log::Any qw($log); +use Carp; + +# class/static variables +my $api_client = WWW::SwaggerClient::APIClient->new; +my $http_timeout = 180; +my $http_user_agent = 'Perl-Swagger'; + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index 57237a96974..e796022bad1 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -28,9 +28,6 @@ use Carp qw( croak ); use Log::Any qw($log); -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - use WWW::SwaggerClient::APIClient; @@ -91,21 +88,18 @@ sub new { if ($_header_accept) { $header_params->{'Accept'} = $_header_accept; } - $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', 'application/xml', ); + $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', 'application/xml'); my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -142,21 +136,18 @@ sub new { if ($_header_accept) { $header_params->{'Accept'} = $_header_accept; } - $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', 'application/xml', ); + $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', 'application/xml'); my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -195,9 +186,9 @@ sub new { } $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type(); - # query params + # query params if ( exists $args{'status'}) { - $query_params->{'status'} = WWW::::APIClient::to_query_value($args{'status'}); + $query_params->{'status'} = $self->{api_client}->to_query_value($args{'status'}); } @@ -205,9 +196,6 @@ sub new { my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -249,9 +237,9 @@ sub new { } $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type(); - # query params + # query params if ( exists $args{'tags'}) { - $query_params->{'tags'} = WWW::::APIClient::to_query_value($args{'tags'}); + $query_params->{'tags'} = $self->{api_client}->to_query_value($args{'tags'}); } @@ -259,9 +247,6 @@ sub new { my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -310,19 +295,16 @@ sub new { - # path params + # path params if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); + my $_base_value = $self->{api_client}->to_path_value($args{'pet_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -369,33 +351,30 @@ sub new { if ($_header_accept) { $header_params->{'Accept'} = $_header_accept; } - $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/x-www-form-urlencoded', ); + $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/x-www-form-urlencoded'); - # path params + # path params if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); + my $_base_value = $self->{api_client}->to_path_value($args{'pet_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } - # form params + # form params if ( exists $args{'name'} ) { - $form_params->{'name'} = WWW::SwaggerClient::APIClient::to_form_value($args{'name'}); + $form_params->{'name'} = $self->{api_client}->to_form_value($args{'name'}); - } # form params + }# form params if ( exists $args{'status'} ) { - $form_params->{'status'} = WWW::SwaggerClient::APIClient::to_form_value($args{'status'}); + $form_params->{'status'} = $self->{api_client}->to_form_value($args{'status'}); } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -441,23 +420,20 @@ sub new { $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type(); - # header params + # header params if ( exists $args{'api_key'}) { - $header_params->{'api_key'} = WWW::SwaggerClient::APIClient::to_header_value($args{'api_key'}); + $header_params->{'api_key'} = $self->{api_client}->to_header_value($args{'api_key'}); } - # path params + # path params if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); + my $_base_value = $self->{api_client}->to_path_value($args{'pet_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -501,22 +477,22 @@ sub new { if ($_header_accept) { $header_params->{'Accept'} = $_header_accept; } - $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('multipart/form-data', ); + $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('multipart/form-data'); - # path params + # path params if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); + my $_base_value = $self->{api_client}->to_path_value($args{'pet_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } - # form params + # form params if ( exists $args{'additional_metadata'} ) { - $form_params->{'additionalMetadata'} = WWW::SwaggerClient::APIClient::to_form_value($args{'additional_metadata'}); + $form_params->{'additionalMetadata'} = $self->{api_client}->to_form_value($args{'additional_metadata'}); - } # form params + }# form params if ( exists $args{'file'} ) { $form_params->{'file'} = [] unless defined $form_params->{'file'}; push $form_params->{'file'}, $args{'file'}; @@ -526,9 +502,6 @@ sub new { my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm index d4261c6bbec..e457c99cac2 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm @@ -28,9 +28,6 @@ use Carp qw( croak ); use Log::Any qw($log); -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - use WWW::SwaggerClient::APIClient; @@ -95,9 +92,6 @@ sub new { my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -144,14 +138,11 @@ sub new { my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -200,19 +191,16 @@ sub new { - # path params + # path params if ( exists $args{'order_id'}) { my $_base_variable = "{" . "orderId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'order_id'}); + my $_base_value = $self->{api_client}->to_path_value($args{'order_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -261,19 +249,16 @@ sub new { - # path params + # path params if ( exists $args{'order_id'}) { my $_base_variable = "{" . "orderId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'order_id'}); + my $_base_value = $self->{api_client}->to_path_value($args{'order_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm index 2e5889ba39e..ece7f3e544b 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -28,9 +28,6 @@ use Carp qw( croak ); use Log::Any qw($log); -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - use WWW::SwaggerClient::APIClient; @@ -98,14 +95,11 @@ sub new { my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -149,14 +143,11 @@ sub new { my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -200,14 +191,11 @@ sub new { my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -247,12 +235,12 @@ sub new { } $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type(); - # query params + # query params if ( exists $args{'username'}) { - $query_params->{'username'} = WWW::::APIClient::to_query_value($args{'username'}); - } # query params + $query_params->{'username'} = $self->{api_client}->to_query_value($args{'username'}); + }# query params if ( exists $args{'password'}) { - $query_params->{'password'} = WWW::::APIClient::to_query_value($args{'password'}); + $query_params->{'password'} = $self->{api_client}->to_query_value($args{'password'}); } @@ -260,9 +248,6 @@ sub new { my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -310,9 +295,6 @@ sub new { my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -358,19 +340,16 @@ sub new { - # path params + # path params if ( exists $args{'username'}) { my $_base_variable = "{" . "username" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'username'}); + my $_base_value = $self->{api_client}->to_path_value($args{'username'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call my $response = $self->{api_client}->call_api($_resource_path, $_method, $query_params, $form_params, @@ -420,22 +399,19 @@ sub new { - # path params + # path params if ( exists $args{'username'}) { my $_base_variable = "{" . "username" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'username'}); + my $_base_value = $self->{api_client}->to_path_value($args{'username'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # body params + # body params if ( exists $args{'body'}) { $_body_data = $args{'body'}; } - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, @@ -481,19 +457,16 @@ sub new { - # path params + # path params if ( exists $args{'username'}) { my $_base_variable = "{" . "username" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'username'}); + my $_base_value = $self->{api_client}->to_path_value($args{'username'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } my $_body_data; - # for HTTP post (form) - #$_body_data = $_body ? undef : $form_params; - # make the API Call $self->{api_client}->call_api($_resource_path, $_method, diff --git a/samples/client/petstore/perl/t/01_pet_api.t b/samples/client/petstore/perl/t/01_pet_api.t index 7855254e657..4a2ef58ee91 100644 --- a/samples/client/petstore/perl/t/01_pet_api.t +++ b/samples/client/petstore/perl/t/01_pet_api.t @@ -1,4 +1,4 @@ -use Test::More tests => 31; +use Test::More tests => 33; use Test::Exception; use lib 'lib'; @@ -10,8 +10,15 @@ use_ok('WWW::SwaggerClient::APIClient'); use_ok('WWW::SwaggerClient::Object::Pet'); use_ok('WWW::SwaggerClient::Object::Tag'); use_ok('WWW::SwaggerClient::Object::Category'); + +my $api_client = WWW::SwaggerClient::APIClient->new('base_url' => 'http://testing'); +my $pet_api = WWW::SwaggerClient::PetApi->new('api_client' => $api_client); +is $pet_api->{api_client}->{base_url}, 'http://testing', 'get the proper base URL from api client'; + my $api = WWW::SwaggerClient::PetApi->new(); +is $api->{api_client}->{base_url}, 'http://petstore.swagger.io/v2', 'get the default base URL from api client'; + # test select_header_content_type is $api->{api_client}->select_header_content_type('application/xml', 'Application/JSON'), 'application/json', 'get the proper content type application/json but not application/xml'; is $api->{api_client}->select_header_content_type('application/xml'), 'application/xml', 'get the proper content type application/json';