diff --git a/bin/perl-petstore.sh b/bin/perl-petstore.sh new file mode 100755 index 00000000000..64d684e9ec8 --- /dev/null +++ b/bin/perl-petstore.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l perl -o samples/client/petstore/perl" + +java $JAVA_OPTS -jar $executable $ags 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 new file mode 100644 index 00000000000..b25e4490e85 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java @@ -0,0 +1,197 @@ +package com.wordnik.swagger.codegen.languages; + +import com.wordnik.swagger.codegen.*; +import com.wordnik.swagger.util.Json; +import com.wordnik.swagger.models.properties.*; + +import java.util.*; +import java.io.File; + +public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { + protected String invokerPackage = "SwaggerClient"; + protected String groupId = "com.wordnik"; + protected String artifactId = "swagger-client"; + protected String artifactVersion = "1.0.0"; + + public CodegenType getTag() { + return CodegenType.CLIENT; + } + + public String getName() { + return "perl"; + } + + public String getHelp() { + return "Generates a Perl client library."; + } + + public PerlClientCodegen() { + super(); + modelPackage = "Object"; + outputFolder = "generated-code/perl"; + modelTemplateFiles.put("object.mustache", ".pm"); + apiTemplateFiles.put("api.mustache", ".pm"); + templateDir = "perl"; + + typeMapping.clear(); + languageSpecificPrimitives.clear(); + + reservedWords = new HashSet ( + Arrays.asList( + "else", "lock", "qw", + "__END__", "elsif", "lt", "qx", + "__FILE__", "eq", "m", "s", + "__LINE__", "exp", "ne", "sub", + "__PACKAGE__", "for", "no", "tr", + "and", "foreach", "or", "unless", + "cmp", "ge", "package", "until", + "continue", "gt", "q", "while", + "CORE", "if", "qq", "xor", + "do", "le", "qr", "y" + ) + ); + + additionalProperties.put("invokerPackage", invokerPackage); + additionalProperties.put("groupId", groupId); + additionalProperties.put("artifactId", artifactId); + additionalProperties.put("artifactVersion", artifactVersion); + + languageSpecificPrimitives.add("int"); + languageSpecificPrimitives.add("double"); + languageSpecificPrimitives.add("string"); + languageSpecificPrimitives.add("boolean"); + languageSpecificPrimitives.add("DateTime"); + languageSpecificPrimitives.add("ARRAY"); + languageSpecificPrimitives.add("HASH"); + + typeMapping.put("integer", "int"); + typeMapping.put("long", "int"); + typeMapping.put("float", "double"); + typeMapping.put("double", "double"); + typeMapping.put("boolean", "boolean"); + typeMapping.put("string", "string"); + typeMapping.put("date", "DateTime"); + typeMapping.put("dateTime", "DateTime"); + typeMapping.put("password", "string"); + typeMapping.put("array", "ARRAY"); + typeMapping.put("map", "HASH"); + + supportingFiles.add(new SupportingFile("APIClient.mustache", "lib/WWW/" + invokerPackage, "APIClient.pm")); + supportingFiles.add(new SupportingFile("BaseObject.mustache", "lib/WWW/" + invokerPackage, "Object/BaseObject.pm")); + } + + @Override + public String escapeReservedWord(String name) { + return "_" + name; + } + + @Override + public String apiFileFolder() { + return outputFolder + "/lib/WWW/" + invokerPackage + apiPackage().replace('.', File.separatorChar); + } + + public String modelFileFolder() { + return outputFolder + "/lib/WWW/" + invokerPackage + "/" + modelPackage().replace('.', File.separatorChar); + } + + @Override + public String getTypeDeclaration(Property p) { + if(p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]"; + } + else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]"; + } + return super.getTypeDeclaration(p); + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + String type = null; + if(typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + if(languageSpecificPrimitives.contains(type)) { + return type; + } + } + else + type = swaggerType; + if(type == null) + return null; + return type; + } + + public String toDefaultValue(Property p) { + return "null"; + } + + + @Override + public String toVarName(String name) { + // parameter name starting with number won't compile + // need to escape it by appending _ at the beginning + if (name.matches("^[0-9]")) { + name = "_" + name; + } + + // return the name in underscore style + // PhoneNumber => phone_number + return underscore(name); + } + + @Override + public String toParamName(String name) { + // should be the same as variable name + return toVarName(name); + } + + @Override + public String toModelName(String name) { + // model name cannot use reserved keyword + if(reservedWords.contains(name)) + escapeReservedWord(name); // e.g. return => _return + + // camelize the model name + // phone_number => PhoneNumber + return camelize(name); + } + + @Override + public String toModelFilename(String name) { + // should be the same as the model name + return toModelName(name); + } + + @Override + public String toApiFilename(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); + + // e.g. phone_number_api.rb => PhoneNumberApi.rb + return camelize(name) + "Api"; + } + + @Override + public String toApiName(String name) { + if(name.length() == 0) + return "DefaultApi"; + // e.g. phone_number_api => PhoneNumberApi + return camelize(name) + "Api"; + } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return underscore(operationId); + } + + +} diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/com.wordnik.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/com.wordnik.swagger.codegen.CodegenConfig index 54236bffc9c..8cb09dcfc11 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/com.wordnik.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/com.wordnik.swagger.codegen.CodegenConfig @@ -5,6 +5,7 @@ com.wordnik.swagger.codegen.languages.JavaClientCodegen com.wordnik.swagger.codegen.languages.JaxRSServerCodegen com.wordnik.swagger.codegen.languages.NodeJSServerCodegen com.wordnik.swagger.codegen.languages.ObjcClientCodegen +com.wordnik.swagger.codegen.languages.PerlClientCodegen com.wordnik.swagger.codegen.languages.PhpClientCodegen com.wordnik.swagger.codegen.languages.PythonClientCodegen com.wordnik.swagger.codegen.languages.Python3ClientCodegen diff --git a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache new file mode 100644 index 00000000000..b0c3c9b5d39 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache @@ -0,0 +1,256 @@ +package WWW::{{invokerPackage}}::APIClient; + +use strict; +use warnings; +use utf8; + +use LWP::UserAgent; +use HTTP::Headers; +use HTTP::Response; +use HTTP::Request::Common qw(DELETE POST GET HEAD PUT); +use HTTP::Status; +use URI::Query; +use JSON; +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 = @_; + + return bless \%args, $class; +} + +# Set the user agent of the API client +# +# @param string $user_agent The user agent of the API client +# +sub set_user_agent { + my $user_agent = shift; + $http_user_agent= $user_agent; +} + +# Set timeout +# +# @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] +# +sub set_timeout { + my $seconds = shift; + if (!looks_like_number($seconds)) { + croak('Timeout variable must be numeric.'); + } + $http_timeout = $seconds; +} + +# make the HTTP request +# @param string $resourcePath path to method endpoint +# @param string $method method to call +# @param array $queryParams parameters to be place in query URL +# @param array $postData parameters to be placed in POST body +# @param array $headerParams parameters to be place in request header +# @return mixed +sub call_api { + my $self = shift; + my ($resource_path, $method, $query_params, $post_params, $header_params, $body_data) = @_; + + my $headers = HTTP::Headers->new(%$header_params); + + my $_url = $base_url . $resource_path; + + # build query + if (%$query_params) { + $_url = ($_url . '?' . eval { URI::Query->new($query_params)->stringify }); + } + + # body data + $body_data = to_json($body_data->to_hash) if defined $body_data && $body_data->can('to_hash'); # model to json string + my $_body_data = %$post_params ? $post_params : $body_data; + + # Make the HTTP request + my $_request; + switch ($method) { + case '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' { + # 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' { + $_request = GET($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}); + } + case 'HEAD' { + $_request = HEAD($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}); + } + case 'DELETE' { #TODO support form data + $_request = DELETE($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}, Content => $_body_data); + } + case 'PATCH' { #TODO + } + + } + + $ua->timeout($http_timeout); + $ua->agent($http_user_agent); + + my $_response = $ua->request($_request); + + unless ($_response->is_success) { + croak("API Exception(".$_response->code."): ".$_response->message); + } + + return $_response->content; + +} + + +# 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)); +} + + +# Take value and turn it into a string suitable for inclusion in +# the query, by imploding comma-separated if it's an object. +# If it's a string, pass through unchanged. It will be url-encoded +# later. +# @param object $object an object to be serialized to a string +# @return string the serialized object +sub to_query_value { + my $object = shift; + if (is_array($object)) { + return implode(',', $object); + } else { + return toString($object); + } +} + + +# Take value and turn it into a string suitable for inclusion in +# the header. If it's a string, pass through unchanged +# If it's a datetime object, format it in ISO8601 +# @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); +} + +# Take value and turn it into a string suitable for inclusion in +# the http body (form parameter). If it's a string, pass through unchanged +# If it's a datetime object, format it in ISO8601 +# @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); +} + +# Take value and turn it into a string suitable for inclusion in +# the parameter. If it's a string, pass through unchanged +# If it's a datetime object, format it in ISO8601 +# @param string $value the value of the parameter +# @return string the header string +sub to_string { + my $value = shift; + if (ref($value) eq "DateTime") { # datetime in ISO8601 format + return $value->datetime(); + } + else { + return $value; + } +} + +# Deserialize a JSON string into an object +# +# @param string $class class name is passed as a string +# @param string $data data of the body +# @return object an instance of $class +sub deserialize +{ + my ($self, $class, $data) = @_; + $log->debugf("deserializing %s for %s", $data, $class); + my $_result; + + if (not defined $data) { + return undef; + } elsif ( lc(substr($class, 0, 4)) eq 'map[') { #hash + $_result = \(json_decode $data); + } elsif ( lc(substr($class, 0, 6)) eq 'array[' ) { # array of data + return $data if $data eq '[]'; # return if empty array + + my $_sub_class = substr($class, 6, -1); + my @_json_data = json_decode $data; + my @_values = (); + foreach my $_value (@_json_data) { + push @_values, $self->deserialize($_sub_class, $_value); + } + $_result = \@_values; + } elsif ($class eq 'DateTime') { + $_result = DateTime->from_epoch(epoch => str2time($data)); + } elsif (grep /^$data$/, ('string', 'int', 'float', 'bool')) { #TODO revise the primitive type + $_result= $data; + } else { # model + my $_instance = use_module("WWW::{{invokerPackage}}::Object::$class")->new; + $_result = $_instance->from_hash(decode_json $data); + } + + return $_result; + +} + +1; diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache new file mode 100644 index 00000000000..b4a7885a798 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -0,0 +1,76 @@ +package WWW::{{invokerPackage}}::Object::BaseObject; + +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; + + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + + +# return json string +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->get_attribute_map) { + if (defined $self->{$_key}) { + $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; + } + } + return $_data; +} + +# 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 $self->get_swagger_types ) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$self->get_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$/, ('int', 'double', 'string', 'boolean'))) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()"; + return $_instance->from_hash($data); + } +} + +1; diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache new file mode 100644 index 00000000000..7b7d9d98a4e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -0,0 +1,145 @@ +# +# Copyright 2015 Reverb Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# NOTE: This class is auto generated by the swagger code generator program. +# Do not edit the class manually. +# +package WWW::{{invokerPackage}}::{{classname}}; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use Exporter; +use Carp qw( croak ); +use Log::Any qw($log); + + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +{{#operations}} + +use WWW::{{invokerPackage}}::APIClient; + +our @EXPORT_OK = qw( + {{#operation}}{{{nickname}}} + {{/operation}} +); + +sub new { + my $class = shift; + my $default_api_client = WWW::{{invokerPackage}}::APIClient->new; + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); + + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; + + bless \%self, $class; + +} + + {{#operation}} + # + # {{{nickname}}} + # + # {{{summary}}} + # + {{#allParams}} # @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}} + {{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} + # + sub {{nickname}} { + my ($self, %args) = @_; + + {{#allParams}}{{#required}} + # verify the required parameter '{{paramName}}' is set + unless (exists $args{'{{paramName}}'}) { + croak("Missing the required parameter '{{paramName}}' when calling {{nickname}}"); + } + {{/required}}{{/allParams}} + + # parse inputs + my $_resource_path = '{{path}}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = '{{httpMethod}}'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = '{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = ({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + {{#queryParams}} # query params + if ( exists $args{'{{paramName}}'}) { + $query_params->{'{{baseName}}'} = WWW::{{invokerPacakge}}::APIClient::to_query_value($args{'{{paramName}}'}); + }{{/queryParams}} + {{#headerParams}} # header params + if ( exists $args{'{{paramName}}'}) { + $header_params->{'{{baseName}}'} = WWW::{{invokerPackage}}::APIClient::to_header_value($args{'{{paramName}}'}); + }{{/headerParams}} + {{#pathParams}} # path params + if ( exists $args{'{{paramName}}'}) { + my $_base_variable = "{" . "{{baseName}}" . "}"; + my $_base_value = WWW::{{invokerPackage}}::APIClient::to_path_value($args{'{{paramName}}'}); + $_resource_path =~ s/$_base_variable/$_base_value/g; + }{{/pathParams}} + {{#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}} + }{{/formParams}} + my $_body_data; + {{#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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('{{returnType}}', $response); + return $_response_object;{{/returnType}} + {{^returnType}}$self->{api_client}->call_api($_resource_path, $_method, + $query_params, $form_params, + $header_params, $_body_data); + return; + {{/returnType}} + } + {{/operation}} +{{newline}} +{{/operations}} + +1; diff --git a/modules/swagger-codegen/src/main/resources/perl/object.mustache b/modules/swagger-codegen/src/main/resources/perl/object.mustache new file mode 100644 index 00000000000..c527957a9b1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/object.mustache @@ -0,0 +1,58 @@ +{{#models}} +{{#model}} +package WWW::{{invokerPackage}}::Object::{{classname}}; + +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 "WWW::{{invokerPackage}}::Object::BaseObject"; + +# +#{{description}} +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +my $swagger_types = { + {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} +}; + +my $attribute_map = { + {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} +}; + +# new object +sub new { + my ($class, %args) = @_; + my $self = { + {{#vars}}#{{#description}}{{{description}}}{{/description}} + '{{name}}' => $args{'{{baseName}}'}{{#hasMore}}, + {{/hasMore}}{{/vars}} + }; + + return bless $self, $class; +} + +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; +} + +# get attribute mappping +sub get_attribute_map { + return $attribute_map; +} + +1; +{{/model}} +{{/models}} diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm new file mode 100644 index 00000000000..6d0ecc44dc6 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -0,0 +1,256 @@ +package WWW::SwaggerClient::APIClient; + +use strict; +use warnings; +use utf8; + +use LWP::UserAgent; +use HTTP::Headers; +use HTTP::Response; +use HTTP::Request::Common qw(DELETE POST GET HEAD PUT); +use HTTP::Status; +use URI::Query; +use JSON; +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 = @_; + + return bless \%args, $class; +} + +# Set the user agent of the API client +# +# @param string $user_agent The user agent of the API client +# +sub set_user_agent { + my $user_agent = shift; + $http_user_agent= $user_agent; +} + +# Set timeout +# +# @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] +# +sub set_timeout { + my $seconds = shift; + if (!looks_like_number($seconds)) { + croak('Timeout variable must be numeric.'); + } + $http_timeout = $seconds; +} + +# make the HTTP request +# @param string $resourcePath path to method endpoint +# @param string $method method to call +# @param array $queryParams parameters to be place in query URL +# @param array $postData parameters to be placed in POST body +# @param array $headerParams parameters to be place in request header +# @return mixed +sub call_api { + my $self = shift; + my ($resource_path, $method, $query_params, $post_params, $header_params, $body_data) = @_; + + my $headers = HTTP::Headers->new(%$header_params); + + my $_url = $base_url . $resource_path; + + # build query + if (%$query_params) { + $_url = ($_url . '?' . eval { URI::Query->new($query_params)->stringify }); + } + + # body data + $body_data = to_json($body_data->to_hash) if defined $body_data && $body_data->can('to_hash'); # model to json string + my $_body_data = %$post_params ? $post_params : $body_data; + + # Make the HTTP request + my $_request; + switch ($method) { + case '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' { + # 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' { + $_request = GET($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}); + } + case 'HEAD' { + $_request = HEAD($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}); + } + case 'DELETE' { #TODO support form data + $_request = DELETE($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}, Content => $_body_data); + } + case 'PATCH' { #TODO + } + + } + + $ua->timeout($http_timeout); + $ua->agent($http_user_agent); + + my $_response = $ua->request($_request); + + unless ($_response->is_success) { + croak("API Exception(".$_response->code."): ".$_response->message); + } + + return $_response->content; + +} + + +# 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)); +} + + +# Take value and turn it into a string suitable for inclusion in +# the query, by imploding comma-separated if it's an object. +# If it's a string, pass through unchanged. It will be url-encoded +# later. +# @param object $object an object to be serialized to a string +# @return string the serialized object +sub to_query_value { + my $object = shift; + if (is_array($object)) { + return implode(',', $object); + } else { + return toString($object); + } +} + + +# Take value and turn it into a string suitable for inclusion in +# the header. If it's a string, pass through unchanged +# If it's a datetime object, format it in ISO8601 +# @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); +} + +# Take value and turn it into a string suitable for inclusion in +# the http body (form parameter). If it's a string, pass through unchanged +# If it's a datetime object, format it in ISO8601 +# @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); +} + +# Take value and turn it into a string suitable for inclusion in +# the parameter. If it's a string, pass through unchanged +# If it's a datetime object, format it in ISO8601 +# @param string $value the value of the parameter +# @return string the header string +sub to_string { + my $value = shift; + if (ref($value) eq "DateTime") { # datetime in ISO8601 format + return $value->datetime(); + } + else { + return $value; + } +} + +# Deserialize a JSON string into an object +# +# @param string $class class name is passed as a string +# @param string $data data of the body +# @return object an instance of $class +sub deserialize +{ + my ($self, $class, $data) = @_; + $log->debugf("deserializing %s for %s", $data, $class); + my $_result; + + if (not defined $data) { + return undef; + } elsif ( lc(substr($class, 0, 4)) eq 'map[') { #hash + $_result = \(json_decode $data); + } elsif ( lc(substr($class, 0, 6)) eq 'array[' ) { # array of data + return $data if $data eq '[]'; # return if empty array + + my $_sub_class = substr($class, 6, -1); + my @_json_data = json_decode $data; + my @_values = (); + foreach my $_value (@_json_data) { + push @_values, $self->deserialize($_sub_class, $_value); + } + $_result = \@_values; + } elsif ($class eq 'DateTime') { + $_result = DateTime->from_epoch(epoch => str2time($data)); + } elsif (grep /^$data$/, ('string', 'int', 'float', 'bool')) { #TODO revise the primitive type + $_result= $data; + } else { # model + my $_instance = use_module("WWW::SwaggerClient::Object::$class")->new; + $_result = $_instance->from_hash(decode_json $data); + } + + return $_result; + +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm new file mode 100644 index 00000000000..c4fd4e6aece --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm @@ -0,0 +1,76 @@ +package WWW::SwaggerClient::Object::BaseObject; + +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; + + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + + +# return json string +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->get_attribute_map) { + if (defined $self->{$_key}) { + $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; + } + } + return $_data; +} + +# 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 $self->get_swagger_types ) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$self->get_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$/, ('int', 'double', 'string', 'boolean'))) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; + return $_instance->from_hash($data); + } +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm new file mode 100644 index 00000000000..857dccdce5a --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm @@ -0,0 +1,55 @@ +package WWW::SwaggerClient::Object::Category; + +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 "WWW::SwaggerClient::Object::BaseObject"; + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +my $swagger_types = { + 'id' => 'int', + 'name' => 'string' +}; + +my $attribute_map = { + 'id' => 'id', + 'name' => 'name' +}; + +# new object +sub new { + my ($class, %args) = @_; + my $self = { + # + 'id' => $args{'id'}, + # + 'name' => $args{'name'} + }; + + return bless $self, $class; +} + +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; +} + +# get attribute mappping +sub get_attribute_map { + return $attribute_map; +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm new file mode 100644 index 00000000000..35449647e13 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm @@ -0,0 +1,71 @@ +package WWW::SwaggerClient::Object::Order; + +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 "WWW::SwaggerClient::Object::BaseObject"; + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +my $swagger_types = { + 'id' => 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => 'DateTime', + 'status' => 'string', + 'complete' => 'boolean' +}; + +my $attribute_map = { + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' +}; + +# new object +sub new { + my ($class, %args) = @_; + my $self = { + # + 'id' => $args{'id'}, + # + 'pet_id' => $args{'petId'}, + # + 'quantity' => $args{'quantity'}, + # + 'ship_date' => $args{'shipDate'}, + #Order Status + 'status' => $args{'status'}, + # + 'complete' => $args{'complete'} + }; + + return bless $self, $class; +} + +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; +} + +# get attribute mappping +sub get_attribute_map { + return $attribute_map; +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm new file mode 100644 index 00000000000..df32665e826 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm @@ -0,0 +1,71 @@ +package WWW::SwaggerClient::Object::Pet; + +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 "WWW::SwaggerClient::Object::BaseObject"; + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +my $swagger_types = { + 'id' => 'int', + 'category' => 'Category', + 'name' => 'string', + 'photo_urls' => 'ARRAY[string]', + 'tags' => 'ARRAY[Tag]', + 'status' => 'string' +}; + +my $attribute_map = { + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' +}; + +# new object +sub new { + my ($class, %args) = @_; + my $self = { + # + 'id' => $args{'id'}, + # + 'category' => $args{'category'}, + # + 'name' => $args{'name'}, + # + 'photo_urls' => $args{'photoUrls'}, + # + 'tags' => $args{'tags'}, + #pet status in the store + 'status' => $args{'status'} + }; + + return bless $self, $class; +} + +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; +} + +# get attribute mappping +sub get_attribute_map { + return $attribute_map; +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm new file mode 100644 index 00000000000..35850032d5c --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm @@ -0,0 +1,55 @@ +package WWW::SwaggerClient::Object::Tag; + +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 "WWW::SwaggerClient::Object::BaseObject"; + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +my $swagger_types = { + 'id' => 'int', + 'name' => 'string' +}; + +my $attribute_map = { + 'id' => 'id', + 'name' => 'name' +}; + +# new object +sub new { + my ($class, %args) = @_; + my $self = { + # + 'id' => $args{'id'}, + # + 'name' => $args{'name'} + }; + + return bless $self, $class; +} + +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; +} + +# get attribute mappping +sub get_attribute_map { + return $attribute_map; +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm new file mode 100644 index 00000000000..88a396ece3a --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm @@ -0,0 +1,79 @@ +package WWW::SwaggerClient::Object::User; + +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 "WWW::SwaggerClient::Object::BaseObject"; + +# +# +# +#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. +# + +my $swagger_types = { + 'id' => 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' +}; + +my $attribute_map = { + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' +}; + +# new object +sub new { + my ($class, %args) = @_; + my $self = { + # + 'id' => $args{'id'}, + # + 'username' => $args{'username'}, + # + 'first_name' => $args{'firstName'}, + # + 'last_name' => $args{'lastName'}, + # + 'email' => $args{'email'}, + # + 'password' => $args{'password'}, + # + 'phone' => $args{'phone'}, + #User Status + 'user_status' => $args{'userStatus'} + }; + + return bless $self, $class; +} + +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; +} + +# get attribute mappping +sub get_attribute_map { + return $attribute_map; +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm new file mode 100644 index 00000000000..930bd52102b --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -0,0 +1,543 @@ +# +# Copyright 2015 Reverb Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# NOTE: This class is auto generated by the swagger code generator program. +# Do not edit the class manually. +# +package WWW::SwaggerClient::PetApi; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use Exporter; +use Carp qw( croak ); +use Log::Any qw($log); + + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + + +use WWW::SwaggerClient::APIClient; + +our @EXPORT_OK = qw( + update_pet + add_pet + find_pets_by_status + find_pets_by_tags + get_pet_by_id + update_pet_with_form + delete_pet + upload_file + +); + +sub new { + my $class = shift; + my $default_api_client = WWW::SwaggerClient::APIClient->new; + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); + + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; + + bless \%self, $class; + +} + + + # + # update_pet + # + # Update an existing pet + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub update_pet { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/pet'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'PUT'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = ('application/json','application/xml',); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + my $_body_data; + # 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # add_pet + # + # Add a new pet to the store + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub add_pet { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/pet'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = ('application/json','application/xml',); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + my $_body_data; + # 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # find_pets_by_status + # + # Finds Pets by status + # + # @param ARRAY[string] $status Status values that need to be considered for filter (required) + # @return ARRAY[Pet] + # + sub find_pets_by_status { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/pet/findByStatus'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + # query params + if ( exists $args{'status'}) { + $query_params->{'status'} = WWW::::APIClient::to_query_value($args{'status'}); + } + + + + 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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response); + return $_response_object; + + } + + # + # find_pets_by_tags + # + # Finds Pets by tags + # + # @param ARRAY[string] $tags Tags to filter by (required) + # @return ARRAY[Pet] + # + sub find_pets_by_tags { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/pet/findByTags'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + # query params + if ( exists $args{'tags'}) { + $query_params->{'tags'} = WWW::::APIClient::to_query_value($args{'tags'}); + } + + + + 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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response); + return $_response_object; + + } + + # + # get_pet_by_id + # + # Find pet by ID + # + # @param int $pet_id ID of pet that needs to be fetched (required) + # @return Pet + # + sub get_pet_by_id { + 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"); + } + + + # parse inputs + my $_resource_path = '/pet/{petId}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'pet_id'}) { + my $_base_variable = "{" . "petId" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('Pet', $response); + return $_response_object; + + } + + # + # update_pet_with_form + # + # Updates a pet in the store with form data + # + # @param string $pet_id ID of pet that needs to be updated (required) + # @param string $name Updated name of the pet (required) + # @param string $status Updated status of the pet (required) + # @return void + # + sub update_pet_with_form { + 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 update_pet_with_form"); + } + + + # parse inputs + my $_resource_path = '/pet/{petId}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = ('application/x-www-form-urlencoded',); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'pet_id'}) { + my $_base_variable = "{" . "petId" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); + $_resource_path =~ s/$_base_variable/$_base_value/g; + } + # form params + if ( exists $args{'name'} ) { + + $form_params->{'name'} = WWW::SwaggerClient::APIClient::to_form_value($args{'name'}); + + } # form params + if ( exists $args{'status'} ) { + + $form_params->{'status'} = WWW::SwaggerClient::APIClient::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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # delete_pet + # + # Deletes a pet + # + # @param string $api_key (required) + # @param int $pet_id Pet id to delete (required) + # @return void + # + sub delete_pet { + 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 delete_pet"); + } + + + # parse inputs + my $_resource_path = '/pet/{petId}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'DELETE'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + # header params + if ( exists $args{'api_key'}) { + $header_params->{'api_key'} = WWW::SwaggerClient::APIClient::to_header_value($args{'api_key'}); + } + # path params + if ( exists $args{'pet_id'}) { + my $_base_variable = "{" . "petId" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # upload_file + # + # uploads an image + # + # @param int $pet_id ID of pet to update (required) + # @param string $additional_metadata Additional data to pass to server (required) + # @param file $file file to upload (required) + # @return void + # + sub upload_file { + 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 upload_file"); + } + + + # parse inputs + my $_resource_path = '/pet/{petId}/uploadImage'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = ('multipart/form-data',); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'pet_id'}) { + my $_base_variable = "{" . "petId" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); + $_resource_path =~ s/$_base_variable/$_base_value/g; + } + # form params + if ( exists $args{'additional_metadata'} ) { + + $form_params->{'additionalMetadata'} = WWW::SwaggerClient::APIClient::to_form_value($args{'additional_metadata'}); + + } # form params + if ( exists $args{'file'} ) { + $form_params->{'file'} = [] unless defined $form_params->{'file'}; + push $form_params->{'file'}, $args{'file'}; + + + } + 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm new file mode 100644 index 00000000000..bb361d05a43 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm @@ -0,0 +1,288 @@ +# +# Copyright 2015 Reverb Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# NOTE: This class is auto generated by the swagger code generator program. +# Do not edit the class manually. +# +package WWW::SwaggerClient::StoreApi; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use Exporter; +use Carp qw( croak ); +use Log::Any qw($log); + + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + + +use WWW::SwaggerClient::APIClient; + +our @EXPORT_OK = qw( + get_inventory + place_order + get_order_by_id + delete_order + +); + +sub new { + my $class = shift; + my $default_api_client = WWW::SwaggerClient::APIClient->new; + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); + + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; + + bless \%self, $class; + +} + + + # + # get_inventory + # + # Returns pet inventories by status + # + # @return HASH[string,int] + # + sub get_inventory { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/store/inventory'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + 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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('HASH[string,int]', $response); + return $_response_object; + + } + + # + # place_order + # + # Place an order for a pet + # + # @param Order $body order placed for purchasing the pet (required) + # @return Order + # + sub place_order { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/store/order'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + my $_body_data; + # 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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('Order', $response); + return $_response_object; + + } + + # + # get_order_by_id + # + # Find purchase order by ID + # + # @param string $order_id ID of pet that needs to be fetched (required) + # @return Order + # + sub get_order_by_id { + my ($self, %args) = @_; + + + # verify the required parameter 'order_id' is set + unless (exists $args{'order_id'}) { + croak("Missing the required parameter 'order_id' when calling get_order_by_id"); + } + + + # parse inputs + my $_resource_path = '/store/order/{orderId}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'order_id'}) { + my $_base_variable = "{" . "orderId" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('Order', $response); + return $_response_object; + + } + + # + # delete_order + # + # Delete purchase order by ID + # + # @param string $order_id ID of the order that needs to be deleted (required) + # @return void + # + sub delete_order { + my ($self, %args) = @_; + + + # verify the required parameter 'order_id' is set + unless (exists $args{'order_id'}) { + croak("Missing the required parameter 'order_id' when calling delete_order"); + } + + + # parse inputs + my $_resource_path = '/store/order/{orderId}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'DELETE'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'order_id'}) { + my $_base_variable = "{" . "orderId" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm new file mode 100644 index 00000000000..d3869b62555 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -0,0 +1,508 @@ +# +# Copyright 2015 Reverb Technologies, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# NOTE: This class is auto generated by the swagger code generator program. +# Do not edit the class manually. +# +package WWW::SwaggerClient::UserApi; + +require 5.6.0; +use strict; +use warnings; +use utf8; +use Exporter; +use Carp qw( croak ); +use Log::Any qw($log); + + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + + +use WWW::SwaggerClient::APIClient; + +our @EXPORT_OK = qw( + create_user + create_users_with_array_input + create_users_with_list_input + login_user + logout_user + get_user_by_name + update_user + delete_user + +); + +sub new { + my $class = shift; + my $default_api_client = WWW::SwaggerClient::APIClient->new; + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); + + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; + + bless \%self, $class; + +} + + + # + # create_user + # + # Create user + # + # @param User $body Created user object (required) + # @return void + # + sub create_user { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/user'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + my $_body_data; + # 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # create_users_with_array_input + # + # Creates list of users with given input array + # + # @param ARRAY[User] $body List of user object (required) + # @return void + # + sub create_users_with_array_input { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/user/createWithArray'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + my $_body_data; + # 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # create_users_with_list_input + # + # Creates list of users with given input array + # + # @param ARRAY[User] $body List of user object (required) + # @return void + # + sub create_users_with_list_input { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/user/createWithList'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'POST'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + my $_body_data; + # 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # login_user + # + # Logs user into the system + # + # @param string $username The user name for login (required) + # @param string $password The password for login in clear text (required) + # @return string + # + sub login_user { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/user/login'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + # query params + if ( exists $args{'username'}) { + $query_params->{'username'} = WWW::::APIClient::to_query_value($args{'username'}); + } # query params + if ( exists $args{'password'}) { + $query_params->{'password'} = WWW::::APIClient::to_query_value($args{'password'}); + } + + + + 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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('string', $response); + return $_response_object; + + } + + # + # logout_user + # + # Logs out current logged in user session + # + # @return void + # + sub logout_user { + my ($self, %args) = @_; + + + + # parse inputs + my $_resource_path = '/user/logout'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # get_user_by_name + # + # Get user by user name + # + # @param string $username The name that needs to be fetched. Use user1 for testing. (required) + # @return User + # + sub get_user_by_name { + my ($self, %args) = @_; + + + # verify the required parameter 'username' is set + unless (exists $args{'username'}) { + croak("Missing the required parameter 'username' when calling get_user_by_name"); + } + + + # parse inputs + my $_resource_path = '/user/{username}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'GET'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'username'}) { + my $_base_variable = "{" . "username" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::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, + $header_params, $_body_data); + if (!$response) { + return; + } + my $_response_object = $self->{api_client}->deserialize('User', $response); + return $_response_object; + + } + + # + # update_user + # + # Updated user + # + # @param string $username name that need to be deleted (required) + # @param User $body Updated user object (required) + # @return void + # + sub update_user { + my ($self, %args) = @_; + + + # verify the required parameter 'username' is set + unless (exists $args{'username'}) { + croak("Missing the required parameter 'username' when calling update_user"); + } + + + # parse inputs + my $_resource_path = '/user/{username}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'PUT'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'username'}) { + my $_base_variable = "{" . "username" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'username'}); + $_resource_path =~ s/$_base_variable/$_base_value/g; + } + + my $_body_data; + # 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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + # + # delete_user + # + # Delete user + # + # @param string $username The name that needs to be deleted (required) + # @return void + # + sub delete_user { + my ($self, %args) = @_; + + + # verify the required parameter 'username' is set + unless (exists $args{'username'}) { + croak("Missing the required parameter 'username' when calling delete_user"); + } + + + # parse inputs + my $_resource_path = '/user/{username}'; + $_resource_path =~ s/{format}/json/; # default format to json + + my $_method = 'DELETE'; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + my $_header_accept = 'application/json, application/xml'; + if ($_header_accept ne '') { + $header_params->{'Accept'} = $_header_accept; + } + my @_header_content_type = (); + $header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + # path params + if ( exists $args{'username'}) { + my $_base_variable = "{" . "username" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::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, + $query_params, $form_params, + $header_params, $_body_data); + return; + + } + + + +1; diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl new file mode 100755 index 00000000000..eb06f786f98 --- /dev/null +++ b/samples/client/petstore/perl/test.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +# +# +use lib 'lib'; +use strict; +use warnings; +use WWW::SwaggerClient::PetApi; +use WWW::SwaggerClient::APIClient; +use WWW::SwaggerClient::Object::Pet; +use WWW::SwaggerClient::Object::Tag; +use WWW::SwaggerClient::Object::Category; +use JSON; +use Data::Dumper; +use DateTime; + +my $api = WWW::SwaggerClient::PetApi->new(); + +my $pet_id = 10008; + +my $category = WWW::SwaggerClient::Object::Category->new('id' => '2', 'name' => 'perl'); +my $tag = WWW::SwaggerClient::Object::Tag->new('id' => '1', 'name' => 'just kidding'); +my $pet = WWW::SwaggerClient::Object::Pet->new('id' => $pet_id, 'name' => 'perl test', + "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'status' => 'pending', 'category' => $category); + +print "\npet(object)=".Dumper $pet; +my $json = JSON->new->convert_blessed; + +my $new_pet = WWW::SwaggerClient::Object::Pet->new(); +$new_pet = $new_pet->from_hash($pet->to_hash); +print "new_pet(hash):".Dumper($new_pet->to_hash); + +print "\nTest Petstore endpoints\n"; +print "\nupload_file:".Dumper $api->upload_file(pet_id => $pet_id, additional_metadata => 'testabc', file => './test.pl'); +print "\nadd_pet:".Dumper $api->add_pet(body => $pet); +print "\nget_pet_by_id:".Dumper $api->get_pet_by_id(pet_id => $pet_id); +print "\nupdate_pet_with_form:".Dumper $api->update_pet_with_form(pet_id => $pet_id, name => 'test_name', status => 'test status'); +print "\ndelete_pet:".Dumper $api->delete_pet(pet_id => $pet_id); + +