Skip to content

Commit

Permalink
Merge pull request #1897 from wing328/perl_fix_replaceall
Browse files Browse the repository at this point in the history
[Perl] fix replaceAll to avoid index out of bound exception in Windows
  • Loading branch information
wing328 committed Jan 15, 2016
2 parents e0738d2 + bfb8cdc commit 2a5bd0a
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.regex.Matcher;

import org.apache.commons.lang.StringUtils;

public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
public static final String MODULE_NAME = "moduleName";
public static final String MODULE_VERSION = "moduleVersion";
protected String moduleName = "WWW::SwaggerClient";
protected String modulePathPart = moduleName.replaceAll("::",String.valueOf(File.separatorChar));
protected String modulePathPart = moduleName.replaceAll("::", Matcher.quoteReplacement(File.separator));
protected String moduleVersion = "1.0.0";

public PerlClientCodegen() {
Expand Down Expand Up @@ -95,7 +96,7 @@ public void processOpts() {

if (additionalProperties.containsKey(MODULE_NAME)) {
setModuleName((String) additionalProperties.get(MODULE_NAME));
setModulePathPart(moduleName.replaceAll("::",String.valueOf(File.separatorChar)));
setModulePathPart(moduleName.replaceAll("::", Matcher.quoteReplacement(File.separator)));
} else {
additionalProperties.put(MODULE_NAME, moduleName);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/perl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-01-04T20:36:07.450-08:00
- Build date: 2016-01-15T15:57:32.150+08:00
- Build package: class io.swagger.codegen.languages.PerlClientCodegen
- Codegen version:

Expand Down Expand Up @@ -162,7 +162,7 @@ you could also call them on class names.

See the homepage `https://github.com/swagger-api/swagger-codegen` for full details.
But briefly, clone the git repository, build the codegen codebase, set up your build
config file, then run the API build script. You will need git, Java 7 and Apache
config file, then run the API build script. You will need git, Java 7 or 8 and Apache
maven 3.0.3 or better already installed.

The config file should specify the project name for the generated library:
Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/perl/lib/WWW/SwaggerClient/ApiClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,19 @@ sub update_params_for_auth {
if (!defined($auth)) {
# TODO show warning about auth setting not defined
}
elsif ($auth eq 'petstore_auth') {

if ($WWW::SwaggerClient::Configuration::access_token) {
$header_params->{'Authorization'} = 'Bearer ' . $WWW::SwaggerClient::Configuration::access_token;
}
}
elsif ($auth eq 'api_key') {

my $api_key = $self->get_api_key_with_prefix('api_key');
if ($api_key) {
$header_params->{'api_key'} = $api_key;
}
}
elsif ($auth eq 'petstore_auth') {

if ($WWW::SwaggerClient::Configuration::access_token) {
$header_params->{'Authorization'} = 'Bearer ' . $WWW::SwaggerClient::Configuration::access_token;
}
}

else {
# TODO show warning about security definition not found
Expand Down
140 changes: 140 additions & 0 deletions samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -662,5 +662,145 @@ sub upload_file {

}

#
# get_pet_by_id_with_byte_array
#
# Fake endpoint to test byte array return by 'Find pet by ID'
#
# @param int $pet_id ID of pet that needs to be fetched (required)
{
my $params = {
'pet_id' => {
data_type => 'int',
description => 'ID of pet that needs to be fetched',
required => '1',
},
};
__PACKAGE__->method_documentation->{ get_pet_by_id_with_byte_array } = {
summary => 'Fake endpoint to test byte array return by 'Find pet by ID'',
params => $params,
returns => 'binary',
};
}
# @return binary
#
sub get_pet_by_id_with_byte_array {
my ($self, %args) = @_;


# verify the required parameter 'pet_id' is set
unless (exists $args{'pet_id'}) {
croak("Missing the required parameter 'pet_id' when calling get_pet_by_id_with_byte_array");
}


# parse inputs
my $_resource_path = '/pet/{petId}?testing_byte_array=true';
$_resource_path =~ s/{format}/json/; # default format to json

my $_method = 'GET';
my $query_params = {};
my $header_params = {};
my $form_params = {};

# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
$header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type();



# path params
if ( exists $args{'pet_id'}) {
my $_base_variable = "{" . "petId" . "}";
my $_base_value = $self->{api_client}->to_path_value($args{'pet_id'});
$_resource_path =~ s/$_base_variable/$_base_value/g;
}

my $_body_data;


# authentication setting, if any
my $auth_settings = [qw(api_key )];

# make the API Call
my $response = $self->{api_client}->call_api($_resource_path, $_method,
$query_params, $form_params,
$header_params, $_body_data, $auth_settings);
if (!$response) {
return;
}
my $_response_object = $self->{api_client}->deserialize('binary', $response);
return $_response_object;

}

#
# add_pet_using_byte_array
#
# Fake endpoint to test byte array in body parameter for adding a new pet to the store
#
# @param binary $body Pet object in the form of byte array (optional)
{
my $params = {
'body' => {
data_type => 'binary',
description => 'Pet object in the form of byte array',
required => '0',
},
};
__PACKAGE__->method_documentation->{ add_pet_using_byte_array } = {
summary => 'Fake endpoint to test byte array in body parameter for adding a new pet to the store',
params => $params,
returns => undef,
};
}
# @return void
#
sub add_pet_using_byte_array {
my ($self, %args) = @_;



# parse inputs
my $_resource_path = '/pet?testing_byte_array=true';
$_resource_path =~ s/{format}/json/; # default format to json

my $_method = 'POST';
my $query_params = {};
my $header_params = {};
my $form_params = {};

# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
$header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', 'application/xml');





my $_body_data;
# body params
if ( exists $args{'body'}) {
$_body_data = $args{'body'};
}

# authentication setting, if any
my $auth_settings = [qw(petstore_auth )];

# make the API Call

$self->{api_client}->call_api($_resource_path, $_method,
$query_params, $form_params,
$header_params, $_body_data, $auth_settings);
return;

}


1;
6 changes: 3 additions & 3 deletions samples/client/petstore/perl/lib/WWW/SwaggerClient/Role.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ has version_info => ( is => 'ro',
default => sub { {
app_name => 'Swagger Petstore',
app_version => '1.0.0',
generated_date => '2016-01-04T20:36:07.450-08:00',
generated_date => '2016-01-15T15:57:32.150+08:00',
generator_class => 'class io.swagger.codegen.languages.PerlClientCodegen',
} },
documentation => 'Information about the application version and the codegen codebase version'
Expand Down Expand Up @@ -103,7 +103,7 @@ Automatically generated by the Perl Swagger Codegen project:
=over 4
=item Build date: 2016-01-04T20:36:07.450-08:00
=item Build date: 2016-01-15T15:57:32.150+08:00
=item Build package: class io.swagger.codegen.languages.PerlClientCodegen
Expand Down Expand Up @@ -264,7 +264,7 @@ you could also call them on class names.
See the homepage C<https://github.com/swagger-api/swagger-codegen> for full details.
But briefly, clone the git repository, build the codegen codebase, set up your build
config file, then run the API build script. You will need git, Java 7 and Apache
config file, then run the API build script. You will need git, Java 7 or 8 and Apache
maven 3.0.3 or better already installed.
The config file should specify the project name for the generated library:
Expand Down

0 comments on commit 2a5bd0a

Please sign in to comment.