From d206035e0f5df0864ab8803ac18c0c1e365fcfd2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 31 Mar 2015 23:54:45 +0800 Subject: [PATCH 01/11] add perl support - api template, bin, codegen --- bin/perl-petstore.sh | 31 ++ .../codegen/languages/PerlClientCodegen.java | 152 ++++++ .../com.wordnik.swagger.codegen.CodegenConfig | 1 + .../src/main/resources/perl/Swagger.mustache | 326 ++++++++++++ .../src/main/resources/perl/api.mustache | 121 +++++ .../src/main/resources/perl/model.mustache | 66 +++ samples/client/petstore/perl/PetApi.pl | 489 ++++++++++++++++++ samples/client/petstore/perl/StoreApi.pl | 264 ++++++++++ samples/client/petstore/perl/Swagger.pl | 326 ++++++++++++ samples/client/petstore/perl/UserApi.pl | 468 +++++++++++++++++ .../perl/WWW/Swagger/Model/Category.pl | 60 +++ .../perl/WWW/Swagger/Model/Category.pm | 60 +++ .../petstore/perl/WWW/Swagger/Model/Order.pl | 79 +++ .../petstore/perl/WWW/Swagger/Model/Order.pm | 79 +++ .../petstore/perl/WWW/Swagger/Model/Pet.pl | 79 +++ .../petstore/perl/WWW/Swagger/Model/Pet.pm | 79 +++ .../petstore/perl/WWW/Swagger/Model/Tag.pl | 60 +++ .../petstore/perl/WWW/Swagger/Model/Tag.pm | 60 +++ .../petstore/perl/WWW/Swagger/Model/User.pl | 87 ++++ .../petstore/perl/WWW/Swagger/Model/User.pm | 87 ++++ .../petstore/perl/WWW/Swagger/PetApi.pl | 481 +++++++++++++++++ .../petstore/perl/WWW/Swagger/PetApi.pm | 486 +++++++++++++++++ .../petstore/perl/WWW/Swagger/StoreApi.pl | 260 ++++++++++ .../petstore/perl/WWW/Swagger/StoreApi.pm | 262 ++++++++++ .../petstore/perl/WWW/Swagger/UserApi.pl | 460 ++++++++++++++++ .../petstore/perl/WWW/Swagger/UserApi.pm | 463 +++++++++++++++++ .../client/petstore/perl/models/Category.pl | 60 +++ samples/client/petstore/perl/models/Order.pl | 79 +++ samples/client/petstore/perl/models/Pet.pl | 79 +++ samples/client/petstore/perl/models/Tag.pl | 60 +++ samples/client/petstore/perl/models/User.pl | 87 ++++ 31 files changed, 5751 insertions(+) create mode 100755 bin/perl-petstore.sh create mode 100644 modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java create mode 100644 modules/swagger-codegen/src/main/resources/perl/Swagger.mustache create mode 100644 modules/swagger-codegen/src/main/resources/perl/api.mustache create mode 100644 modules/swagger-codegen/src/main/resources/perl/model.mustache create mode 100644 samples/client/petstore/perl/PetApi.pl create mode 100644 samples/client/petstore/perl/StoreApi.pl create mode 100644 samples/client/petstore/perl/Swagger.pl create mode 100644 samples/client/petstore/perl/UserApi.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Category.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Category.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Order.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Order.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/User.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/User.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/PetApi.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/PetApi.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/StoreApi.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/StoreApi.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/UserApi.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/UserApi.pm create mode 100644 samples/client/petstore/perl/models/Category.pl create mode 100644 samples/client/petstore/perl/models/Order.pl create mode 100644 samples/client/petstore/perl/models/Pet.pl create mode 100644 samples/client/petstore/perl/models/Tag.pl create mode 100644 samples/client/petstore/perl/models/User.pl 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..89afcd23b7e --- /dev/null +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PerlClientCodegen.java @@ -0,0 +1,152 @@ +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 = "com.wordnik.client"; + 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 = "Model"; + outputFolder = "generated-code/perl"; + modelTemplateFiles.put("model.mustache", ".pm"); + apiTemplateFiles.put("api.mustache", ".pm"); + templateDir = "perl"; + + typeMapping.clear(); + languageSpecificPrimitives.clear(); + + reservedWords = new HashSet ( + Arrays.asList( + "__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor") + ); + + additionalProperties.put("invokerPackage", invokerPackage); + additionalProperties.put("groupId", groupId); + additionalProperties.put("artifactId", artifactId); + additionalProperties.put("artifactVersion", artifactVersion); + + languageSpecificPrimitives.add("int"); + languageSpecificPrimitives.add("array"); + languageSpecificPrimitives.add("map"); + languageSpecificPrimitives.add("string"); + languageSpecificPrimitives.add("DateTime"); + + typeMapping.put("long", "int"); + typeMapping.put("integer", "int"); + typeMapping.put("Array", "array"); + typeMapping.put("String", "string"); + typeMapping.put("List", "array"); + typeMapping.put("map", "map"); + + supportingFiles.add(new SupportingFile("Swagger.mustache", "", "Swagger.pl")); + } + + @Override + public String escapeReservedWord(String name) { + return "_" + name; + } + + @Override + public String apiFileFolder() { + return outputFolder + "/WWW/Swagger/" + apiPackage().replace('.', File.separatorChar); + } + + public String modelFileFolder() { + return outputFolder + "/WWW/Swagger/" + 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); + } + +} 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/Swagger.mustache b/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache new file mode 100644 index 00000000000..3d6b77d819e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache @@ -0,0 +1,326 @@ +host = $host; + $this->headerName = $headerName; + $this->headerValue = $headerValue; + } + + /** + * Set the user agent of the API client + * + * @param string $user_agent The user agent of the API client + */ + public function setUserAgent($user_agent) { + if (!is_string($user_agent)) { + throw new Exception('User-agent must be a string.'); + } + $this->user_agent= $user_agent; + } + + /** + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + */ + public function setTimeout($seconds) { + if (!is_numeric($seconds)) { + throw new Exception('Timeout variable must be numeric.'); + } + $this->curl_timout = $seconds; + } + + /** + * @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 + */ + public function callAPI($resourcePath, $method, $queryParams, $postData, + $headerParams) { + + $headers = array(); + + # Allow API key from $headerParams to override default + $added_api_key = False; + if ($headerParams != null) { + foreach ($headerParams as $key => $val) { + $headers[] = "$key: $val"; + if ($key == $this->headerName) { + $added_api_key = True; + } + } + } + if (! $added_api_key && $this->headerName != null) { + $headers[] = $this->headerName . ": " . $this->headerValue; + } + + if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) { + $postData = json_encode($this->sanitizeForSerialization($postData)); + } + + $url = $this->host . $resourcePath; + + $curl = curl_init(); + if ($this->curl_timout) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout); + } + // return the result on success, rather than just TRUE + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + if (! empty($queryParams)) { + $url = ($url . '?' . http_build_query($queryParams)); + } + + if ($method == self::$POST) { + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PATCH) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PUT) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$DELETE) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method != self::$GET) { + throw new Exception('Method ' . $method . ' is not recognized.'); + } + curl_setopt($curl, CURLOPT_URL, $url); + + // Set user agent + if ($this->user_agent) { + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + } else { // use PHP-Swagger as the default user agent + curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger'); + } + + // Make the request + $response = curl_exec($curl); + $response_info = curl_getinfo($curl); + + // Handle the response + if ($response_info['http_code'] == 0) { + throw new APIClientException("TIMEOUT: api call to " . $url . + " took more than 5s to return", 0, $response_info, $response); + } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + $data = json_decode($response); + if (json_last_error() > 0) { // if response is a string + $data = $response; + } + } else if ($response_info['http_code'] == 401) { + throw new APIClientException("Unauthorized API request to " . $url . + ": " . serialize($response), 0, $response_info, $response); + } else if ($response_info['http_code'] == 404) { + $data = null; + } else { + throw new APIClientException("Can't connect to the api: " . $url . + " response code: " . + $response_info['http_code'], 0, $response_info, $response); + } + return $data; + } + + /** + * Build a JSON POST object + */ + protected function sanitizeForSerialization($data) + { + 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 + */ + public static function toPathValue($value) { + return rawurlencode(toString($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 + */ + public static function toQueryValue($object) { + 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 + */ + public static function toHeaderValue($value) { + return toString($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 + */ + public static function toFormValue($value) { + return toString($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 + */ + public static function toString($value) { + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(\DateTime::ISO8601); + } + else { + return $value; + } + } + + /** + * Deserialize a JSON string into an object + * + * @param object $object object or primitive to be deserialized + * @param string $class class name is passed as a string + * @return object an instance of $class + */ + + public static function deserialize($data, $class) + { + if (null === $data) { + $deserialized = null; + } elseif (substr($class, 0, 4) == 'map[') { + $inner = substr($class, 4, -1); + $values = array(); + if(strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $values[] = array($key => self::deserialize($value, $subClass)); + } + } + $deserialized = $values; + } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { + $subClass = substr($class, 6, -1); + $values = array(); + foreach ($data as $key => $value) { + $values[] = self::deserialize($value, $subClass); + } + $deserialized = $values; + } elseif ($class == 'DateTime') { + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { + settype($data, $class); + $deserialized = $data; + } else { + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + if (isset($data->$property)) { + $original_property_name = $instance::$attributeMap[$property]; + $instance->$property = self::deserialize($data->$original_property_name, $type); + } + } + $deserialized = $instance; + } + + return $deserialized; + } + +} + +class APIClientException extends Exception { + protected $response, $response_info; + + public function __construct($message="", $code=0, $response_info=null, $response=null) { + parent::__construct($message, $code); + $this->response_info = $response_info; + $this->response = $response; + } + + public function getResponse() { + return $this->response; + } + + public function getResponseInfo() { + return $this->response_info; + } +} 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..76f7b31aa0b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -0,0 +1,121 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +{{#operations}} +package WWW::Swagger::{{classname}}; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "{{path}}"; + $resource_path =~ s/{format}/json/; + + my $method = "{{httpMethod}}"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}'; + $header_params->{'Content-Type'} = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}'; + + {{#queryParams}} # query params + if($args{ {{paramName}} }) { + $query_params->{'{{baseName}}'} = $self->api_client->to_query_value($args{ {{paramName}} }); + }{{/queryParams}} + {{#headerParams}} # header params + if($args{ {{paramName}} }) { + $header_params->{'{{baseName}}'} = $self->apiClient->to_header_value($args{ {{paramName}} }); + }{{/headerParams}} + {{#pathParams}} # path params + if( $args{ {{paramName}} }) { + my $base_variable = "{" + "{{baseName}}" + "}"; + my $base_value = $self->api_client->to_path_value($args{ {{paramName}} }); + $resource_path = s/$base_variable/$base_value/; + }{{/pathParams}} + {{#formParams}} # form params + if ($args{ {{paramName}} }) { + $form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}$self->api_client->to_form_value($args{ {{paramName}} }); + }{{/formParams}} + my $body; + {{#bodyParams}} # body params + if (isset(${{paramName}})) { + $body = ${{paramName}}; + }{{/bodyParams}} + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + {{#returnType}}if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, '{{returnType}}'); + return $response_object;{{/returnType}} + } + {{/operation}} +{{newline}} +{{/operations}} + +1; diff --git a/modules/swagger-codegen/src/main/resources/perl/model.mustache b/modules/swagger-codegen/src/main/resources/perl/model.mustache new file mode 100644 index 00000000000..4540f973633 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/perl/model.mustache @@ -0,0 +1,66 @@ + '{{{datatype}}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); + + static $attributeMap = array( + {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); + + {{#vars}}{{#description}} + /** + * {{{description}}} + */{{/description}} + public ${{name}}; /* {{{datatype}}} */{{/vars}} + + public function __construct(array $data) { + {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} + {{/hasMore}}{{/vars}} + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} +{{/model}} +{{/models}} diff --git a/samples/client/petstore/perl/PetApi.pl b/samples/client/petstore/perl/PetApi.pl new file mode 100644 index 00000000000..7dc8261cd77 --- /dev/null +++ b/samples/client/petstore/perl/PetApi.pl @@ -0,0 +1,489 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +use WWW::Swagger::Model::Category; +use WWW::Swagger::Model::Pet; + +package WWW::Swagger::PetApiAPI; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client = $option->{api_client} + } + + bless $self, $class; + +} + + + # + # updatePet + # + # Update an existing pet + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub updatePet($body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml'; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # addPet + # + # Add a new pet to the store + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub addPet($body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml'; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # findPetsByStatus + # + # Finds Pets by status + # + # @param array[string] $status Status values that need to be considered for filter (required) + # @return array[Pet] + # + sub findPetsByStatus($status) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/findByStatus"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($status !== null) { + $query_params['status'] = $this->api_client->to_query_value($status); + } + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'array[Pet]'); + return $responseObject; + } + + # + # findPetsByTags + # + # Finds Pets by tags + # + # @param array[string] $tags Tags to filter by (required) + # @return array[Pet] + # + sub findPetsByTags($tags) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/findByTags"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($tags !== null) { + $query_params['tags'] = $this->api_client->to_query_value($tags); + } + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'array[Pet]'); + return $responseObject; + } + + # + # getPetById + # + # Find pet by ID + # + # @param int $pet_id ID of pet that needs to be fetched (required) + # @return Pet + # + sub getPetById($pet_id) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'Pet'); + return $responseObject; + } + + # + # updatePetWithForm + # + # 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 updatePetWithForm($pet_id, $name, $status) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded'; + + + + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + # form params + if ($name !== null) { + $formParams->{'name'} = $this->api_client->to_form_value($name); + } # form params + if ($status !== null) { + $formParams->{'status'} = $this->api_client->to_form_value($status); + } + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # deletePet + # + # Deletes a pet + # + # @param string $api_key (required) + # @param int $pet_id Pet id to delete (required) + # @return void + # + sub deletePet($api_key, $pet_id) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + # header params + if($api_key !== null) { + $headerParams['api_key'] = $this->apiClient->to_header_value($args[api_key]); + } + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # uploadFile + # + # 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 uploadFile($pet_id, $additional_metadata, $file) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}/uploadImage"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'multipart/form-data'; + + + + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + # form params + if ($additional_metadata !== null) { + $formParams->{'additionalMetadata'} = $this->api_client->to_form_value($additional_metadata); + } # form params + if ($file !== null) { + $formParams->{'file'} = '@' . $this->api_client->to_form_value($file); + } + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + +} + +1; diff --git a/samples/client/petstore/perl/StoreApi.pl b/samples/client/petstore/perl/StoreApi.pl new file mode 100644 index 00000000000..6ab1b62758e --- /dev/null +++ b/samples/client/petstore/perl/StoreApi.pl @@ -0,0 +1,264 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +use WWW::Swagger::Model::Category; +use WWW::Swagger::Model::Pet; + +package WWW::Swagger::StoreApiAPI; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client = $option->{api_client} + } + + bless $self, $class; + +} + + + # + # getInventory + # + # Returns pet inventories by status + # + # @return map[string,int] + # + sub getInventory() { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/inventory"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'map[string,int]'); + return $responseObject; + } + + # + # placeOrder + # + # Place an order for a pet + # + # @param Order $body order placed for purchasing the pet (required) + # @return Order + # + sub placeOrder($body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/order"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'Order'); + return $responseObject; + } + + # + # getOrderById + # + # Find purchase order by ID + # + # @param string $order_id ID of pet that needs to be fetched (required) + # @return Order + # + sub getOrderById($order_id) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($order_id !== null) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $this->api_client->to_path_value($order_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'Order'); + return $responseObject; + } + + # + # deleteOrder + # + # Delete purchase order by ID + # + # @param string $order_id ID of the order that needs to be deleted (required) + # @return void + # + sub deleteOrder($order_id) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($order_id !== null) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $this->api_client->to_path_value($order_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + +} + +1; diff --git a/samples/client/petstore/perl/Swagger.pl b/samples/client/petstore/perl/Swagger.pl new file mode 100644 index 00000000000..3d6b77d819e --- /dev/null +++ b/samples/client/petstore/perl/Swagger.pl @@ -0,0 +1,326 @@ +host = $host; + $this->headerName = $headerName; + $this->headerValue = $headerValue; + } + + /** + * Set the user agent of the API client + * + * @param string $user_agent The user agent of the API client + */ + public function setUserAgent($user_agent) { + if (!is_string($user_agent)) { + throw new Exception('User-agent must be a string.'); + } + $this->user_agent= $user_agent; + } + + /** + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + */ + public function setTimeout($seconds) { + if (!is_numeric($seconds)) { + throw new Exception('Timeout variable must be numeric.'); + } + $this->curl_timout = $seconds; + } + + /** + * @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 + */ + public function callAPI($resourcePath, $method, $queryParams, $postData, + $headerParams) { + + $headers = array(); + + # Allow API key from $headerParams to override default + $added_api_key = False; + if ($headerParams != null) { + foreach ($headerParams as $key => $val) { + $headers[] = "$key: $val"; + if ($key == $this->headerName) { + $added_api_key = True; + } + } + } + if (! $added_api_key && $this->headerName != null) { + $headers[] = $this->headerName . ": " . $this->headerValue; + } + + if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) { + $postData = json_encode($this->sanitizeForSerialization($postData)); + } + + $url = $this->host . $resourcePath; + + $curl = curl_init(); + if ($this->curl_timout) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout); + } + // return the result on success, rather than just TRUE + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + if (! empty($queryParams)) { + $url = ($url . '?' . http_build_query($queryParams)); + } + + if ($method == self::$POST) { + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PATCH) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PUT) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$DELETE) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method != self::$GET) { + throw new Exception('Method ' . $method . ' is not recognized.'); + } + curl_setopt($curl, CURLOPT_URL, $url); + + // Set user agent + if ($this->user_agent) { + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + } else { // use PHP-Swagger as the default user agent + curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger'); + } + + // Make the request + $response = curl_exec($curl); + $response_info = curl_getinfo($curl); + + // Handle the response + if ($response_info['http_code'] == 0) { + throw new APIClientException("TIMEOUT: api call to " . $url . + " took more than 5s to return", 0, $response_info, $response); + } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + $data = json_decode($response); + if (json_last_error() > 0) { // if response is a string + $data = $response; + } + } else if ($response_info['http_code'] == 401) { + throw new APIClientException("Unauthorized API request to " . $url . + ": " . serialize($response), 0, $response_info, $response); + } else if ($response_info['http_code'] == 404) { + $data = null; + } else { + throw new APIClientException("Can't connect to the api: " . $url . + " response code: " . + $response_info['http_code'], 0, $response_info, $response); + } + return $data; + } + + /** + * Build a JSON POST object + */ + protected function sanitizeForSerialization($data) + { + 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 + */ + public static function toPathValue($value) { + return rawurlencode(toString($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 + */ + public static function toQueryValue($object) { + 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 + */ + public static function toHeaderValue($value) { + return toString($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 + */ + public static function toFormValue($value) { + return toString($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 + */ + public static function toString($value) { + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(\DateTime::ISO8601); + } + else { + return $value; + } + } + + /** + * Deserialize a JSON string into an object + * + * @param object $object object or primitive to be deserialized + * @param string $class class name is passed as a string + * @return object an instance of $class + */ + + public static function deserialize($data, $class) + { + if (null === $data) { + $deserialized = null; + } elseif (substr($class, 0, 4) == 'map[') { + $inner = substr($class, 4, -1); + $values = array(); + if(strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $values[] = array($key => self::deserialize($value, $subClass)); + } + } + $deserialized = $values; + } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { + $subClass = substr($class, 6, -1); + $values = array(); + foreach ($data as $key => $value) { + $values[] = self::deserialize($value, $subClass); + } + $deserialized = $values; + } elseif ($class == 'DateTime') { + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { + settype($data, $class); + $deserialized = $data; + } else { + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + if (isset($data->$property)) { + $original_property_name = $instance::$attributeMap[$property]; + $instance->$property = self::deserialize($data->$original_property_name, $type); + } + } + $deserialized = $instance; + } + + return $deserialized; + } + +} + +class APIClientException extends Exception { + protected $response, $response_info; + + public function __construct($message="", $code=0, $response_info=null, $response=null) { + parent::__construct($message, $code); + $this->response_info = $response_info; + $this->response = $response; + } + + public function getResponse() { + return $this->response; + } + + public function getResponseInfo() { + return $this->response_info; + } +} diff --git a/samples/client/petstore/perl/UserApi.pl b/samples/client/petstore/perl/UserApi.pl new file mode 100644 index 00000000000..49803ffa66b --- /dev/null +++ b/samples/client/petstore/perl/UserApi.pl @@ -0,0 +1,468 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +use WWW::Swagger::Model::Category; +use WWW::Swagger::Model::Pet; + +package WWW::Swagger::UserApiAPI; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client = $option->{api_client} + } + + bless $self, $class; + +} + + + # + # createUser + # + # Create user + # + # @param User $body Created user object (required) + # @return void + # + sub createUser($body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # createUsersWithArrayInput + # + # Creates list of users with given input array + # + # @param array[User] $body List of user object (required) + # @return void + # + sub createUsersWithArrayInput($body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/createWithArray"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # createUsersWithListInput + # + # Creates list of users with given input array + # + # @param array[User] $body List of user object (required) + # @return void + # + sub createUsersWithListInput($body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/createWithList"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # loginUser + # + # 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 loginUser($username, $password) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/login"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($username !== null) { + $query_params['username'] = $this->api_client->to_query_value($username); + } # query params + if($password !== null) { + $query_params['password'] = $this->api_client->to_query_value($password); + } + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'string'); + return $responseObject; + } + + # + # logoutUser + # + # Logs out current logged in user session + # + # @return void + # + sub logoutUser() { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/logout"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # getUserByName + # + # Get user by user name + # + # @param string $username The name that needs to be fetched. Use user1 for testing. (required) + # @return User + # + sub getUserByName($username) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($username !== null) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $this->api_client->to_path_value($username); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'User'); + return $responseObject; + } + + # + # updateUser + # + # Updated user + # + # @param string $username name that need to be deleted (required) + # @param User $body Updated user object (required) + # @return void + # + sub updateUser($username, $body) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($username !== null) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $this->api_client->to_path_value($username); + $resource_path = s/$base_variable/$base_value/; + } + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # deleteUser + # + # Delete user + # + # @param string $username The name that needs to be deleted (required) + # @return void + # + sub deleteUser($username) { + + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($username !== null) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $this->api_client->to_path_value($username); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + +} + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Category.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Category.pl new file mode 100644 index 00000000000..98e7ba24800 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Category.pl @@ -0,0 +1,60 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Category.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Category.pm new file mode 100644 index 00000000000..98e7ba24800 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Category.pm @@ -0,0 +1,60 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Order.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Order.pl new file mode 100644 index 00000000000..2770e8bbbdf --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Order.pl @@ -0,0 +1,79 @@ + 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => 'DateTime', + 'status' => 'string', + 'complete' => 'boolean' + ); + + static $attributeMap = array( + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); + + + public $id; /* int */ + public $pet_id; /* int */ + public $quantity; /* int */ + public $ship_date; /* DateTime */ + /** + * Order Status + */ + public $status; /* string */ + public $complete; /* boolean */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->pet_id = $data["pet_id"]; + $this->quantity = $data["quantity"]; + $this->ship_date = $data["ship_date"]; + $this->status = $data["status"]; + $this->complete = $data["complete"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Order.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Order.pm new file mode 100644 index 00000000000..2770e8bbbdf --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Order.pm @@ -0,0 +1,79 @@ + 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => 'DateTime', + 'status' => 'string', + 'complete' => 'boolean' + ); + + static $attributeMap = array( + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); + + + public $id; /* int */ + public $pet_id; /* int */ + public $quantity; /* int */ + public $ship_date; /* DateTime */ + /** + * Order Status + */ + public $status; /* string */ + public $complete; /* boolean */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->pet_id = $data["pet_id"]; + $this->quantity = $data["quantity"]; + $this->ship_date = $data["ship_date"]; + $this->status = $data["status"]; + $this->complete = $data["complete"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl new file mode 100644 index 00000000000..eee7fa3784c --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl @@ -0,0 +1,79 @@ + 'int', + 'category' => 'Category', + 'name' => 'string', + 'photo_urls' => 'array[string]', + 'tags' => 'array[Tag]', + 'status' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); + + + public $id; /* int */ + public $category; /* Category */ + public $name; /* string */ + public $photo_urls; /* array[string] */ + public $tags; /* array[Tag] */ + /** + * pet status in the store + */ + public $status; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->category = $data["category"]; + $this->name = $data["name"]; + $this->photo_urls = $data["photo_urls"]; + $this->tags = $data["tags"]; + $this->status = $data["status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm new file mode 100644 index 00000000000..eee7fa3784c --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm @@ -0,0 +1,79 @@ + 'int', + 'category' => 'Category', + 'name' => 'string', + 'photo_urls' => 'array[string]', + 'tags' => 'array[Tag]', + 'status' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); + + + public $id; /* int */ + public $category; /* Category */ + public $name; /* string */ + public $photo_urls; /* array[string] */ + public $tags; /* array[Tag] */ + /** + * pet status in the store + */ + public $status; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->category = $data["category"]; + $this->name = $data["name"]; + $this->photo_urls = $data["photo_urls"]; + $this->tags = $data["tags"]; + $this->status = $data["status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl new file mode 100644 index 00000000000..f8efc998df6 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl @@ -0,0 +1,60 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm new file mode 100644 index 00000000000..f8efc998df6 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm @@ -0,0 +1,60 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/User.pl b/samples/client/petstore/perl/WWW/Swagger/Model/User.pl new file mode 100644 index 00000000000..d6b520eba51 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/User.pl @@ -0,0 +1,87 @@ + 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' + ); + + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' + ); + + + public $id; /* int */ + public $username; /* string */ + public $first_name; /* string */ + public $last_name; /* string */ + public $email; /* string */ + public $password; /* string */ + public $phone; /* string */ + /** + * User Status + */ + public $user_status; /* int */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->username = $data["username"]; + $this->first_name = $data["first_name"]; + $this->last_name = $data["last_name"]; + $this->email = $data["email"]; + $this->password = $data["password"]; + $this->phone = $data["phone"]; + $this->user_status = $data["user_status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/User.pm b/samples/client/petstore/perl/WWW/Swagger/Model/User.pm new file mode 100644 index 00000000000..d6b520eba51 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/Model/User.pm @@ -0,0 +1,87 @@ + 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' + ); + + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' + ); + + + public $id; /* int */ + public $username; /* string */ + public $first_name; /* string */ + public $last_name; /* string */ + public $email; /* string */ + public $password; /* string */ + public $phone; /* string */ + /** + * User Status + */ + public $user_status; /* int */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->username = $data["username"]; + $this->first_name = $data["first_name"]; + $this->last_name = $data["last_name"]; + $this->email = $data["email"]; + $this->password = $data["password"]; + $this->phone = $data["phone"]; + $this->user_status = $data["user_status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/WWW/Swagger/PetApi.pl b/samples/client/petstore/perl/WWW/Swagger/PetApi.pl new file mode 100644 index 00000000000..5d876b4b61e --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/PetApi.pl @@ -0,0 +1,481 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +use WWW::Swagger::Model::Category; +use WWW::Swagger::Model::Pet; + +package WWW::Swagger::PetApiAPI; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client = $option->{api_client} + } + + bless $self, $class; + +} + + + # + # updatePet + # + # Update an existing pet + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub updatePet { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml'; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # addPet + # + # Add a new pet to the store + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub addPet { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml'; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # findPetsByStatus + # + # Finds Pets by status + # + # @param array[string] $status Status values that need to be considered for filter (required) + # @return array[Pet] + # + sub findPetsByStatus { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/findByStatus"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($status !== null) { + $query_params['status'] = $this->api_client->to_query_value($status); + } + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'array[Pet]'); + return $responseObject; + } + + # + # findPetsByTags + # + # Finds Pets by tags + # + # @param array[string] $tags Tags to filter by (required) + # @return array[Pet] + # + sub findPetsByTags { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/findByTags"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($tags !== null) { + $query_params['tags'] = $this->api_client->to_query_value($tags); + } + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'array[Pet]'); + return $responseObject; + } + + # + # getPetById + # + # Find pet by ID + # + # @param int $pet_id ID of pet that needs to be fetched (required) + # @return Pet + # + sub getPetById { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'Pet'); + return $responseObject; + } + + # + # updatePetWithForm + # + # 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 updatePetWithForm { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded'; + + + + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + # form params + if ($name !== null) { + $formParams->{'name'} = $this->api_client->to_form_value($name); + } # form params + if ($status !== null) { + $formParams->{'status'} = $this->api_client->to_form_value($status); + } + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # deletePet + # + # Deletes a pet + # + # @param string $api_key (required) + # @param int $pet_id Pet id to delete (required) + # @return void + # + sub deletePet { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + # header params + if($api_key !== null) { + $headerParams['api_key'] = $this->apiClient->to_header_value($args[api_key]); + } + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # uploadFile + # + # 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 uploadFile { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/pet/{petId}/uploadImage"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'multipart/form-data'; + + + + # path params + if($pet_id !== null) { + my $base_variable = "{" + "petId" + "}"; + my $base_value = $this->api_client->to_path_value($pet_id); + $resource_path = s/$base_variable/$base_value/; + } + # form params + if ($additional_metadata !== null) { + $formParams->{'additionalMetadata'} = $this->api_client->to_form_value($additional_metadata); + } # form params + if ($file !== null) { + $formParams->{'file'} = '@' . $this->api_client->to_form_value($file); + } + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + +} + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/PetApi.pm b/samples/client/petstore/perl/WWW/Swagger/PetApi.pm new file mode 100644 index 00000000000..a76ed8054ba --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/PetApi.pm @@ -0,0 +1,486 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +package WWW::Swagger::PetApi; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{api_client} + }; + + bless $self, $class; + +} + + + # + # updatePet + # + # Update an existing pet + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub updatePet { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml'; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # addPet + # + # Add a new pet to the store + # + # @param Pet $body Pet object that needs to be added to the store (required) + # @return void + # + sub addPet { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml'; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # findPetsByStatus + # + # Finds Pets by status + # + # @param array[string] $status Status values that need to be considered for filter (required) + # @return array[Pet] + # + sub findPetsByStatus { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/findByStatus"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($args{ status }) { + $query_params->{'status'} = $self->api_client->to_query_value($args{ status }); + } + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); + return $response_object; + } + + # + # findPetsByTags + # + # Finds Pets by tags + # + # @param array[string] $tags Tags to filter by (required) + # @return array[Pet] + # + sub findPetsByTags { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/findByTags"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($args{ tags }) { + $query_params->{'tags'} = $self->api_client->to_query_value($args{ tags }); + } + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); + return $response_object; + } + + # + # getPetById + # + # Find pet by ID + # + # @param int $pet_id ID of pet that needs to be fetched (required) + # @return Pet + # + sub getPetById { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $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/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'Pet'); + return $response_object; + } + + # + # updatePetWithForm + # + # 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 updatePetWithForm { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded'; + + + + # path params + if( $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/; + } + # form params + if ($args{ name }) { + $form_params->{'name'} = $self->api_client->to_form_value($args{ name }); + } # form params + if ($args{ status }) { + $form_params->{'status'} = $self->api_client->to_form_value($args{ status }); + } + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # deletePet + # + # Deletes a pet + # + # @param string $api_key (required) + # @param int $pet_id Pet id to delete (required) + # @return void + # + sub deletePet { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + # header params + if($args{ api_key }) { + $header_params->{'api_key'} = $self->apiClient->to_header_value($args{ api_key }); + } + # path params + if( $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/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # uploadFile + # + # 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 uploadFile { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}/uploadImage"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'multipart/form-data'; + + + + # path params + if( $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/; + } + # form params + if ($args{ additional_metadata }) { + $form_params->{'additionalMetadata'} = $self->api_client->to_form_value($args{ additional_metadata }); + } # form params + if ($args{ file }) { + $form_params->{'file'} = '@' . $self->api_client->to_form_value($args{ file }); + } + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pl b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pl new file mode 100644 index 00000000000..64c20c71a66 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pl @@ -0,0 +1,260 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +use WWW::Swagger::Model::Category; +use WWW::Swagger::Model::Pet; + +package WWW::Swagger::StoreApiAPI; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client = $option->{api_client} + } + + bless $self, $class; + +} + + + # + # getInventory + # + # Returns pet inventories by status + # + # @return map[string,int] + # + sub getInventory { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/inventory"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'map[string,int]'); + return $responseObject; + } + + # + # placeOrder + # + # Place an order for a pet + # + # @param Order $body order placed for purchasing the pet (required) + # @return Order + # + sub placeOrder { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/order"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'Order'); + return $responseObject; + } + + # + # getOrderById + # + # Find purchase order by ID + # + # @param string $order_id ID of pet that needs to be fetched (required) + # @return Order + # + sub getOrderById { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($order_id !== null) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $this->api_client->to_path_value($order_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'Order'); + return $responseObject; + } + + # + # deleteOrder + # + # Delete purchase order by ID + # + # @param string $order_id ID of the order that needs to be deleted (required) + # @return void + # + sub deleteOrder { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($order_id !== null) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $this->api_client->to_path_value($order_id); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + +} + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm new file mode 100644 index 00000000000..a9e412ba32c --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm @@ -0,0 +1,262 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +package WWW::Swagger::StoreApi; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{api_client} + }; + + bless $self, $class; + +} + + + # + # getInventory + # + # Returns pet inventories by status + # + # @return map[string,int] + # + sub getInventory { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/inventory"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'map[string,int]'); + return $response_object; + } + + # + # placeOrder + # + # Place an order for a pet + # + # @param Order $body order placed for purchasing the pet (required) + # @return Order + # + sub placeOrder { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/order"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'Order'); + return $response_object; + } + + # + # getOrderById + # + # Find purchase order by ID + # + # @param string $order_id ID of pet that needs to be fetched (required) + # @return Order + # + sub getOrderById { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ order_id }) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $self->api_client->to_path_value($args{ order_id }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'Order'); + return $response_object; + } + + # + # deleteOrder + # + # Delete purchase order by ID + # + # @param string $order_id ID of the order that needs to be deleted (required) + # @return void + # + sub deleteOrder { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ order_id }) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $self->api_client->to_path_value($args{ order_id }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/UserApi.pl b/samples/client/petstore/perl/WWW/Swagger/UserApi.pl new file mode 100644 index 00000000000..ba2877560fb --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/UserApi.pl @@ -0,0 +1,460 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +use WWW::Swagger::Model::Category; +use WWW::Swagger::Model::Pet; + +package WWW::Swagger::UserApiAPI; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client = $option->{api_client} + } + + bless $self, $class; + +} + + + # + # createUser + # + # Create user + # + # @param User $body Created user object (required) + # @return void + # + sub createUser { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # createUsersWithArrayInput + # + # Creates list of users with given input array + # + # @param array[User] $body List of user object (required) + # @return void + # + sub createUsersWithArrayInput { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/createWithArray"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # createUsersWithListInput + # + # Creates list of users with given input array + # + # @param array[User] $body List of user object (required) + # @return void + # + sub createUsersWithListInput { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/createWithList"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # loginUser + # + # 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 loginUser { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/login"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($username !== null) { + $query_params['username'] = $this->api_client->to_query_value($username); + } # query params + if($password !== null) { + $query_params['password'] = $this->api_client->to_query_value($password); + } + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'string'); + return $responseObject; + } + + # + # logoutUser + # + # Logs out current logged in user session + # + # @return void + # + sub logoutUser { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/logout"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # getUserByName + # + # Get user by user name + # + # @param string $username The name that needs to be fetched. Use user1 for testing. (required) + # @return User + # + sub getUserByName { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($username !== null) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $this->api_client->to_path_value($username); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + $response_object = $this->api_client->deserialize($response, 'User'); + return $responseObject; + } + + # + # updateUser + # + # Updated user + # + # @param string $username name that need to be deleted (required) + # @param User $body Updated user object (required) + # @return void + # + sub updateUser { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($username !== null) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $this->api_client->to_path_value($username); + $resource_path = s/$base_variable/$base_value/; + } + + # body params + my $body; + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # deleteUser + # + # Delete user + # + # @param string $username The name that needs to be deleted (required) + # @return void + # + sub deleteUser { + my $self = shift; + my %args = @_; + + // parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if($username !== null) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $this->api_client->to_path_value($username); + $resource_path = s/$base_variable/$base_value/; + } + + + + # for HTTP post (form) + $body = $body ?: $formParams; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + // make the API Call + $response = $this->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + +} + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/UserApi.pm b/samples/client/petstore/perl/WWW/Swagger/UserApi.pm new file mode 100644 index 00000000000..375f6eaf0c1 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/UserApi.pm @@ -0,0 +1,463 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +package WWW::Swagger::UserApi; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{api_client} + }; + + bless $self, $class; + +} + + + # + # createUser + # + # Create user + # + # @param User $body Created user object (required) + # @return void + # + sub createUser { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # createUsersWithArrayInput + # + # Creates list of users with given input array + # + # @param array[User] $body List of user object (required) + # @return void + # + sub createUsersWithArrayInput { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/createWithArray"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # createUsersWithListInput + # + # Creates list of users with given input array + # + # @param array[User] $body List of user object (required) + # @return void + # + sub createUsersWithListInput { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/createWithList"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # loginUser + # + # 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 loginUser { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/login"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($args{ username }) { + $query_params->{'username'} = $self->api_client->to_query_value($args{ username }); + } # query params + if($args{ password }) { + $query_params->{'password'} = $self->api_client->to_query_value($args{ password }); + } + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'string'); + return $response_object; + } + + # + # logoutUser + # + # Logs out current logged in user session + # + # @return void + # + sub logoutUser { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/logout"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # getUserByName + # + # Get user by user name + # + # @param string $username The name that needs to be fetched. Use user1 for testing. (required) + # @return User + # + sub getUserByName { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ username }) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $self->api_client->to_path_value($args{ username }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'User'); + return $response_object; + } + + # + # updateUser + # + # Updated user + # + # @param string $username name that need to be deleted (required) + # @param User $body Updated user object (required) + # @return void + # + sub updateUser { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ username }) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $self->api_client->to_path_value($args{ username }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # deleteUser + # + # Delete user + # + # @param string $username The name that needs to be deleted (required) + # @return void + # + sub deleteUser { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ username }) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $self->api_client->to_path_value($args{ username }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + + +1; diff --git a/samples/client/petstore/perl/models/Category.pl b/samples/client/petstore/perl/models/Category.pl new file mode 100644 index 00000000000..98e7ba24800 --- /dev/null +++ b/samples/client/petstore/perl/models/Category.pl @@ -0,0 +1,60 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/models/Order.pl b/samples/client/petstore/perl/models/Order.pl new file mode 100644 index 00000000000..2770e8bbbdf --- /dev/null +++ b/samples/client/petstore/perl/models/Order.pl @@ -0,0 +1,79 @@ + 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => 'DateTime', + 'status' => 'string', + 'complete' => 'boolean' + ); + + static $attributeMap = array( + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); + + + public $id; /* int */ + public $pet_id; /* int */ + public $quantity; /* int */ + public $ship_date; /* DateTime */ + /** + * Order Status + */ + public $status; /* string */ + public $complete; /* boolean */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->pet_id = $data["pet_id"]; + $this->quantity = $data["quantity"]; + $this->ship_date = $data["ship_date"]; + $this->status = $data["status"]; + $this->complete = $data["complete"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/models/Pet.pl b/samples/client/petstore/perl/models/Pet.pl new file mode 100644 index 00000000000..eee7fa3784c --- /dev/null +++ b/samples/client/petstore/perl/models/Pet.pl @@ -0,0 +1,79 @@ + 'int', + 'category' => 'Category', + 'name' => 'string', + 'photo_urls' => 'array[string]', + 'tags' => 'array[Tag]', + 'status' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); + + + public $id; /* int */ + public $category; /* Category */ + public $name; /* string */ + public $photo_urls; /* array[string] */ + public $tags; /* array[Tag] */ + /** + * pet status in the store + */ + public $status; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->category = $data["category"]; + $this->name = $data["name"]; + $this->photo_urls = $data["photo_urls"]; + $this->tags = $data["tags"]; + $this->status = $data["status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/models/Tag.pl b/samples/client/petstore/perl/models/Tag.pl new file mode 100644 index 00000000000..f8efc998df6 --- /dev/null +++ b/samples/client/petstore/perl/models/Tag.pl @@ -0,0 +1,60 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/perl/models/User.pl b/samples/client/petstore/perl/models/User.pl new file mode 100644 index 00000000000..d6b520eba51 --- /dev/null +++ b/samples/client/petstore/perl/models/User.pl @@ -0,0 +1,87 @@ + 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' + ); + + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' + ); + + + public $id; /* int */ + public $username; /* string */ + public $first_name; /* string */ + public $last_name; /* string */ + public $email; /* string */ + public $password; /* string */ + public $phone; /* string */ + /** + * User Status + */ + public $user_status; /* int */ + + public function __construct(array $data) { + $this->id = $data["id"]; + $this->username = $data["username"]; + $this->first_name = $data["first_name"]; + $this->last_name = $data["last_name"]; + $this->email = $data["email"]; + $this->password = $data["password"]; + $this->phone = $data["phone"]; + $this->user_status = $data["user_status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} From c5fcf3ba2c0b888827a8c15a9d7bc202af5269b8 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 1 Apr 2015 01:30:06 +0800 Subject: [PATCH 02/11] remove pl files --- samples/client/petstore/perl/PetApi.pl | 489 ------------------ samples/client/petstore/perl/StoreApi.pl | 264 ---------- samples/client/petstore/perl/Swagger.pl | 326 ------------ samples/client/petstore/perl/UserApi.pl | 468 ----------------- .../perl/WWW/Swagger/Model/Category.pl | 60 --- .../petstore/perl/WWW/Swagger/Model/Order.pl | 79 --- .../petstore/perl/WWW/Swagger/Model/Pet.pl | 79 --- .../petstore/perl/WWW/Swagger/Model/Tag.pl | 60 --- .../petstore/perl/WWW/Swagger/Model/User.pl | 87 ---- .../petstore/perl/WWW/Swagger/PetApi.pl | 481 ----------------- .../petstore/perl/WWW/Swagger/StoreApi.pl | 260 ---------- .../petstore/perl/WWW/Swagger/UserApi.pl | 460 ---------------- .../client/petstore/perl/models/Category.pl | 60 --- samples/client/petstore/perl/models/Order.pl | 79 --- samples/client/petstore/perl/models/Pet.pl | 79 --- samples/client/petstore/perl/models/Tag.pl | 60 --- samples/client/petstore/perl/models/User.pl | 87 ---- 17 files changed, 3478 deletions(-) delete mode 100644 samples/client/petstore/perl/PetApi.pl delete mode 100644 samples/client/petstore/perl/StoreApi.pl delete mode 100644 samples/client/petstore/perl/Swagger.pl delete mode 100644 samples/client/petstore/perl/UserApi.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Category.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Order.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/User.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/PetApi.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/StoreApi.pl delete mode 100644 samples/client/petstore/perl/WWW/Swagger/UserApi.pl delete mode 100644 samples/client/petstore/perl/models/Category.pl delete mode 100644 samples/client/petstore/perl/models/Order.pl delete mode 100644 samples/client/petstore/perl/models/Pet.pl delete mode 100644 samples/client/petstore/perl/models/Tag.pl delete mode 100644 samples/client/petstore/perl/models/User.pl diff --git a/samples/client/petstore/perl/PetApi.pl b/samples/client/petstore/perl/PetApi.pl deleted file mode 100644 index 7dc8261cd77..00000000000 --- a/samples/client/petstore/perl/PetApi.pl +++ /dev/null @@ -1,489 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -use WWW::Swagger::Model::Category; -use WWW::Swagger::Model::Pet; - -package WWW::Swagger::PetApiAPI; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client = $option->{api_client} - } - - bless $self, $class; - -} - - - # - # updatePet - # - # Update an existing pet - # - # @param Pet $body Pet object that needs to be added to the store (required) - # @return void - # - sub updatePet($body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml'; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # addPet - # - # Add a new pet to the store - # - # @param Pet $body Pet object that needs to be added to the store (required) - # @return void - # - sub addPet($body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml'; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # findPetsByStatus - # - # Finds Pets by status - # - # @param array[string] $status Status values that need to be considered for filter (required) - # @return array[Pet] - # - sub findPetsByStatus($status) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/findByStatus"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($status !== null) { - $query_params['status'] = $this->api_client->to_query_value($status); - } - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'array[Pet]'); - return $responseObject; - } - - # - # findPetsByTags - # - # Finds Pets by tags - # - # @param array[string] $tags Tags to filter by (required) - # @return array[Pet] - # - sub findPetsByTags($tags) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/findByTags"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($tags !== null) { - $query_params['tags'] = $this->api_client->to_query_value($tags); - } - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'array[Pet]'); - return $responseObject; - } - - # - # getPetById - # - # Find pet by ID - # - # @param int $pet_id ID of pet that needs to be fetched (required) - # @return Pet - # - sub getPetById($pet_id) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'Pet'); - return $responseObject; - } - - # - # updatePetWithForm - # - # 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 updatePetWithForm($pet_id, $name, $status) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded'; - - - - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - # form params - if ($name !== null) { - $formParams->{'name'} = $this->api_client->to_form_value($name); - } # form params - if ($status !== null) { - $formParams->{'status'} = $this->api_client->to_form_value($status); - } - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # deletePet - # - # Deletes a pet - # - # @param string $api_key (required) - # @param int $pet_id Pet id to delete (required) - # @return void - # - sub deletePet($api_key, $pet_id) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - # header params - if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->to_header_value($args[api_key]); - } - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # uploadFile - # - # 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 uploadFile($pet_id, $additional_metadata, $file) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}/uploadImage"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'multipart/form-data'; - - - - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - # form params - if ($additional_metadata !== null) { - $formParams->{'additionalMetadata'} = $this->api_client->to_form_value($additional_metadata); - } # form params - if ($file !== null) { - $formParams->{'file'} = '@' . $this->api_client->to_form_value($file); - } - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - -} - -1; diff --git a/samples/client/petstore/perl/StoreApi.pl b/samples/client/petstore/perl/StoreApi.pl deleted file mode 100644 index 6ab1b62758e..00000000000 --- a/samples/client/petstore/perl/StoreApi.pl +++ /dev/null @@ -1,264 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -use WWW::Swagger::Model::Category; -use WWW::Swagger::Model::Pet; - -package WWW::Swagger::StoreApiAPI; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client = $option->{api_client} - } - - bless $self, $class; - -} - - - # - # getInventory - # - # Returns pet inventories by status - # - # @return map[string,int] - # - sub getInventory() { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/inventory"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'map[string,int]'); - return $responseObject; - } - - # - # placeOrder - # - # Place an order for a pet - # - # @param Order $body order placed for purchasing the pet (required) - # @return Order - # - sub placeOrder($body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/order"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'Order'); - return $responseObject; - } - - # - # getOrderById - # - # Find purchase order by ID - # - # @param string $order_id ID of pet that needs to be fetched (required) - # @return Order - # - sub getOrderById($order_id) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($order_id !== null) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $this->api_client->to_path_value($order_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'Order'); - return $responseObject; - } - - # - # deleteOrder - # - # Delete purchase order by ID - # - # @param string $order_id ID of the order that needs to be deleted (required) - # @return void - # - sub deleteOrder($order_id) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($order_id !== null) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $this->api_client->to_path_value($order_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - -} - -1; diff --git a/samples/client/petstore/perl/Swagger.pl b/samples/client/petstore/perl/Swagger.pl deleted file mode 100644 index 3d6b77d819e..00000000000 --- a/samples/client/petstore/perl/Swagger.pl +++ /dev/null @@ -1,326 +0,0 @@ -host = $host; - $this->headerName = $headerName; - $this->headerValue = $headerValue; - } - - /** - * Set the user agent of the API client - * - * @param string $user_agent The user agent of the API client - */ - public function setUserAgent($user_agent) { - if (!is_string($user_agent)) { - throw new Exception('User-agent must be a string.'); - } - $this->user_agent= $user_agent; - } - - /** - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - */ - public function setTimeout($seconds) { - if (!is_numeric($seconds)) { - throw new Exception('Timeout variable must be numeric.'); - } - $this->curl_timout = $seconds; - } - - /** - * @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 - */ - public function callAPI($resourcePath, $method, $queryParams, $postData, - $headerParams) { - - $headers = array(); - - # Allow API key from $headerParams to override default - $added_api_key = False; - if ($headerParams != null) { - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; - if ($key == $this->headerName) { - $added_api_key = True; - } - } - } - if (! $added_api_key && $this->headerName != null) { - $headers[] = $this->headerName . ": " . $this->headerValue; - } - - if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) { - $postData = json_encode($this->sanitizeForSerialization($postData)); - } - - $url = $this->host . $resourcePath; - - $curl = curl_init(); - if ($this->curl_timout) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout); - } - // return the result on success, rather than just TRUE - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - if (! empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($method == self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { - throw new Exception('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - if ($this->user_agent) { - curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); - } else { // use PHP-Swagger as the default user agent - curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger'); - } - - // Make the request - $response = curl_exec($curl); - $response_info = curl_getinfo($curl); - - // Handle the response - if ($response_info['http_code'] == 0) { - throw new APIClientException("TIMEOUT: api call to " . $url . - " took more than 5s to return", 0, $response_info, $response); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { - $data = json_decode($response); - if (json_last_error() > 0) { // if response is a string - $data = $response; - } - } else if ($response_info['http_code'] == 401) { - throw new APIClientException("Unauthorized API request to " . $url . - ": " . serialize($response), 0, $response_info, $response); - } else if ($response_info['http_code'] == 404) { - $data = null; - } else { - throw new APIClientException("Can't connect to the api: " . $url . - " response code: " . - $response_info['http_code'], 0, $response_info, $response); - } - return $data; - } - - /** - * Build a JSON POST object - */ - protected function sanitizeForSerialization($data) - { - 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 - */ - public static function toPathValue($value) { - return rawurlencode(toString($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 - */ - public static function toQueryValue($object) { - 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 - */ - public static function toHeaderValue($value) { - return toString($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 - */ - public static function toFormValue($value) { - return toString($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 - */ - public static function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format - return $value->format(\DateTime::ISO8601); - } - else { - return $value; - } - } - - /** - * Deserialize a JSON string into an object - * - * @param object $object object or primitive to be deserialized - * @param string $class class name is passed as a string - * @return object an instance of $class - */ - - public static function deserialize($data, $class) - { - if (null === $data) { - $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { - $inner = substr($class, 4, -1); - $values = array(); - if(strrpos($inner, ",") !== false) { - $subClass_array = explode(',', $inner, 2); - $subClass = $subClass_array[1]; - foreach ($data as $key => $value) { - $values[] = array($key => self::deserialize($value, $subClass)); - } - } - $deserialized = $values; - } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { - $subClass = substr($class, 6, -1); - $values = array(); - foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass); - } - $deserialized = $values; - } elseif ($class == 'DateTime') { - $deserialized = new \DateTime($data); - } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { - settype($data, $class); - $deserialized = $data; - } else { - $instance = new $class(); - foreach ($instance::$swaggerTypes as $property => $type) { - if (isset($data->$property)) { - $original_property_name = $instance::$attributeMap[$property]; - $instance->$property = self::deserialize($data->$original_property_name, $type); - } - } - $deserialized = $instance; - } - - return $deserialized; - } - -} - -class APIClientException extends Exception { - protected $response, $response_info; - - public function __construct($message="", $code=0, $response_info=null, $response=null) { - parent::__construct($message, $code); - $this->response_info = $response_info; - $this->response = $response; - } - - public function getResponse() { - return $this->response; - } - - public function getResponseInfo() { - return $this->response_info; - } -} diff --git a/samples/client/petstore/perl/UserApi.pl b/samples/client/petstore/perl/UserApi.pl deleted file mode 100644 index 49803ffa66b..00000000000 --- a/samples/client/petstore/perl/UserApi.pl +++ /dev/null @@ -1,468 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -use WWW::Swagger::Model::Category; -use WWW::Swagger::Model::Pet; - -package WWW::Swagger::UserApiAPI; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client = $option->{api_client} - } - - bless $self, $class; - -} - - - # - # createUser - # - # Create user - # - # @param User $body Created user object (required) - # @return void - # - sub createUser($body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # createUsersWithArrayInput - # - # Creates list of users with given input array - # - # @param array[User] $body List of user object (required) - # @return void - # - sub createUsersWithArrayInput($body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/createWithArray"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # createUsersWithListInput - # - # Creates list of users with given input array - # - # @param array[User] $body List of user object (required) - # @return void - # - sub createUsersWithListInput($body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/createWithList"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # loginUser - # - # 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 loginUser($username, $password) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/login"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($username !== null) { - $query_params['username'] = $this->api_client->to_query_value($username); - } # query params - if($password !== null) { - $query_params['password'] = $this->api_client->to_query_value($password); - } - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'string'); - return $responseObject; - } - - # - # logoutUser - # - # Logs out current logged in user session - # - # @return void - # - sub logoutUser() { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/logout"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # getUserByName - # - # Get user by user name - # - # @param string $username The name that needs to be fetched. Use user1 for testing. (required) - # @return User - # - sub getUserByName($username) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($username !== null) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $this->api_client->to_path_value($username); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'User'); - return $responseObject; - } - - # - # updateUser - # - # Updated user - # - # @param string $username name that need to be deleted (required) - # @param User $body Updated user object (required) - # @return void - # - sub updateUser($username, $body) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($username !== null) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $this->api_client->to_path_value($username); - $resource_path = s/$base_variable/$base_value/; - } - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # deleteUser - # - # Delete user - # - # @param string $username The name that needs to be deleted (required) - # @return void - # - sub deleteUser($username) { - - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($username !== null) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $this->api_client->to_path_value($username); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - -} - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Category.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Category.pl deleted file mode 100644 index 98e7ba24800..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Category.pl +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Order.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Order.pl deleted file mode 100644 index 2770e8bbbdf..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Order.pl +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => 'DateTime', - 'status' => 'string', - 'complete' => 'boolean' - ); - - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ - /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl deleted file mode 100644 index eee7fa3784c..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pl +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'category' => 'Category', - 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', - 'status' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ - /** - * pet status in the store - */ - public $status; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl b/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl deleted file mode 100644 index f8efc998df6..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pl +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/User.pl b/samples/client/petstore/perl/WWW/Swagger/Model/User.pl deleted file mode 100644 index d6b520eba51..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/User.pl +++ /dev/null @@ -1,87 +0,0 @@ - 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - - public $id; /* int */ - public $username; /* string */ - public $first_name; /* string */ - public $last_name; /* string */ - public $email; /* string */ - public $password; /* string */ - public $phone; /* string */ - /** - * User Status - */ - public $user_status; /* int */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/PetApi.pl b/samples/client/petstore/perl/WWW/Swagger/PetApi.pl deleted file mode 100644 index 5d876b4b61e..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/PetApi.pl +++ /dev/null @@ -1,481 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -use WWW::Swagger::Model::Category; -use WWW::Swagger::Model::Pet; - -package WWW::Swagger::PetApiAPI; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client = $option->{api_client} - } - - bless $self, $class; - -} - - - # - # updatePet - # - # Update an existing pet - # - # @param Pet $body Pet object that needs to be added to the store (required) - # @return void - # - sub updatePet { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml'; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # addPet - # - # Add a new pet to the store - # - # @param Pet $body Pet object that needs to be added to the store (required) - # @return void - # - sub addPet { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml'; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # findPetsByStatus - # - # Finds Pets by status - # - # @param array[string] $status Status values that need to be considered for filter (required) - # @return array[Pet] - # - sub findPetsByStatus { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/findByStatus"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($status !== null) { - $query_params['status'] = $this->api_client->to_query_value($status); - } - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'array[Pet]'); - return $responseObject; - } - - # - # findPetsByTags - # - # Finds Pets by tags - # - # @param array[string] $tags Tags to filter by (required) - # @return array[Pet] - # - sub findPetsByTags { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/findByTags"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($tags !== null) { - $query_params['tags'] = $this->api_client->to_query_value($tags); - } - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'array[Pet]'); - return $responseObject; - } - - # - # getPetById - # - # Find pet by ID - # - # @param int $pet_id ID of pet that needs to be fetched (required) - # @return Pet - # - sub getPetById { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'Pet'); - return $responseObject; - } - - # - # updatePetWithForm - # - # 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 updatePetWithForm { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded'; - - - - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - # form params - if ($name !== null) { - $formParams->{'name'} = $this->api_client->to_form_value($name); - } # form params - if ($status !== null) { - $formParams->{'status'} = $this->api_client->to_form_value($status); - } - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # deletePet - # - # Deletes a pet - # - # @param string $api_key (required) - # @param int $pet_id Pet id to delete (required) - # @return void - # - sub deletePet { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - # header params - if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->to_header_value($args[api_key]); - } - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # uploadFile - # - # 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 uploadFile { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/pet/{petId}/uploadImage"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'multipart/form-data'; - - - - # path params - if($pet_id !== null) { - my $base_variable = "{" + "petId" + "}"; - my $base_value = $this->api_client->to_path_value($pet_id); - $resource_path = s/$base_variable/$base_value/; - } - # form params - if ($additional_metadata !== null) { - $formParams->{'additionalMetadata'} = $this->api_client->to_form_value($additional_metadata); - } # form params - if ($file !== null) { - $formParams->{'file'} = '@' . $this->api_client->to_form_value($file); - } - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - -} - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pl b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pl deleted file mode 100644 index 64c20c71a66..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pl +++ /dev/null @@ -1,260 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -use WWW::Swagger::Model::Category; -use WWW::Swagger::Model::Pet; - -package WWW::Swagger::StoreApiAPI; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client = $option->{api_client} - } - - bless $self, $class; - -} - - - # - # getInventory - # - # Returns pet inventories by status - # - # @return map[string,int] - # - sub getInventory { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/inventory"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'map[string,int]'); - return $responseObject; - } - - # - # placeOrder - # - # Place an order for a pet - # - # @param Order $body order placed for purchasing the pet (required) - # @return Order - # - sub placeOrder { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/order"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'Order'); - return $responseObject; - } - - # - # getOrderById - # - # Find purchase order by ID - # - # @param string $order_id ID of pet that needs to be fetched (required) - # @return Order - # - sub getOrderById { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($order_id !== null) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $this->api_client->to_path_value($order_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'Order'); - return $responseObject; - } - - # - # deleteOrder - # - # Delete purchase order by ID - # - # @param string $order_id ID of the order that needs to be deleted (required) - # @return void - # - sub deleteOrder { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($order_id !== null) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $this->api_client->to_path_value($order_id); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - -} - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/UserApi.pl b/samples/client/petstore/perl/WWW/Swagger/UserApi.pl deleted file mode 100644 index ba2877560fb..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/UserApi.pl +++ /dev/null @@ -1,460 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -use WWW::Swagger::Model::Category; -use WWW::Swagger::Model::Pet; - -package WWW::Swagger::UserApiAPI; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client = $option->{api_client} - } - - bless $self, $class; - -} - - - # - # createUser - # - # Create user - # - # @param User $body Created user object (required) - # @return void - # - sub createUser { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # createUsersWithArrayInput - # - # Creates list of users with given input array - # - # @param array[User] $body List of user object (required) - # @return void - # - sub createUsersWithArrayInput { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/createWithArray"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # createUsersWithListInput - # - # Creates list of users with given input array - # - # @param array[User] $body List of user object (required) - # @return void - # - sub createUsersWithListInput { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/createWithList"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # loginUser - # - # 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 loginUser { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/login"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($username !== null) { - $query_params['username'] = $this->api_client->to_query_value($username); - } # query params - if($password !== null) { - $query_params['password'] = $this->api_client->to_query_value($password); - } - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'string'); - return $responseObject; - } - - # - # logoutUser - # - # Logs out current logged in user session - # - # @return void - # - sub logoutUser { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/logout"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # getUserByName - # - # Get user by user name - # - # @param string $username The name that needs to be fetched. Use user1 for testing. (required) - # @return User - # - sub getUserByName { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($username !== null) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $this->api_client->to_path_value($username); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - $response_object = $this->api_client->deserialize($response, 'User'); - return $responseObject; - } - - # - # updateUser - # - # Updated user - # - # @param string $username name that need to be deleted (required) - # @param User $body Updated user object (required) - # @return void - # - sub updateUser { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($username !== null) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $this->api_client->to_path_value($username); - $resource_path = s/$base_variable/$base_value/; - } - - # body params - my $body; - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # deleteUser - # - # Delete user - # - # @param string $username The name that needs to be deleted (required) - # @return void - # - sub deleteUser { - my $self = shift; - my %args = @_; - - // parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if($username !== null) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $this->api_client->to_path_value($username); - $resource_path = s/$base_variable/$base_value/; - } - - - - # for HTTP post (form) - $body = $body ?: $formParams; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - // make the API Call - $response = $this->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - -} - -1; diff --git a/samples/client/petstore/perl/models/Category.pl b/samples/client/petstore/perl/models/Category.pl deleted file mode 100644 index 98e7ba24800..00000000000 --- a/samples/client/petstore/perl/models/Category.pl +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/models/Order.pl b/samples/client/petstore/perl/models/Order.pl deleted file mode 100644 index 2770e8bbbdf..00000000000 --- a/samples/client/petstore/perl/models/Order.pl +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => 'DateTime', - 'status' => 'string', - 'complete' => 'boolean' - ); - - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ - /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/models/Pet.pl b/samples/client/petstore/perl/models/Pet.pl deleted file mode 100644 index eee7fa3784c..00000000000 --- a/samples/client/petstore/perl/models/Pet.pl +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'category' => 'Category', - 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', - 'status' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ - /** - * pet status in the store - */ - public $status; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/models/Tag.pl b/samples/client/petstore/perl/models/Tag.pl deleted file mode 100644 index f8efc998df6..00000000000 --- a/samples/client/petstore/perl/models/Tag.pl +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/models/User.pl b/samples/client/petstore/perl/models/User.pl deleted file mode 100644 index d6b520eba51..00000000000 --- a/samples/client/petstore/perl/models/User.pl +++ /dev/null @@ -1,87 +0,0 @@ - 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - - public $id; /* int */ - public $username; /* string */ - public $first_name; /* string */ - public $last_name; /* string */ - public $email; /* string */ - public $password; /* string */ - public $phone; /* string */ - /** - * User Status - */ - public $user_status; /* int */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} From a7ef1262e5b61a679eb5e1843a8b1c0f67c25faf Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 2 May 2015 19:08:07 +0800 Subject: [PATCH 03/11] fix all swagger.pl syntax issue --- .../codegen/languages/PerlClientCodegen.java | 27 + .../src/main/resources/perl/Swagger.mustache | 523 +++++++----------- samples/client/petstore/perl/Swagger.pl | 229 ++++++++ .../petstore/perl/WWW/Swagger/PetApi.pm | 40 +- .../petstore/perl/WWW/Swagger/StoreApi.pm | 16 +- .../petstore/perl/WWW/Swagger/UserApi.pm | 32 +- .../petstore/perl/WWW/Swagger/pet_api.pm | 486 ++++++++++++++++ .../petstore/perl/WWW/Swagger/store_api.pm | 262 +++++++++ .../petstore/perl/WWW/Swagger/user_api.pm | 463 ++++++++++++++++ 9 files changed, 1724 insertions(+), 354 deletions(-) create mode 100644 samples/client/petstore/perl/Swagger.pl create mode 100644 samples/client/petstore/perl/WWW/Swagger/pet_api.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/store_api.pm create mode 100644 samples/client/petstore/perl/WWW/Swagger/user_api.pm 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 89afcd23b7e..92f44872965 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 @@ -149,4 +149,31 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { 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/perl/Swagger.mustache b/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache index 3d6b77d819e..e58f64107cd 100644 --- a/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache @@ -1,326 +1,229 @@ -new; +my $http_user_agent = 'Perl-Swagger'; # HTTP user-agent +my $http_timeout; #timeout +my $base_url; + + +sub new +{ + my $class = shift; + my %args = @_; + + return bless \%args, $class; } -spl_autoload_register('swagger_autoloader'); +# 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; +} -class APIClient { +# 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; +} - public static $POST = "POST"; - public static $GET = "GET"; - public static $PUT = "PUT"; - public static $DELETE = "DELETE"; +# 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) = @_; - /** - * @param string $host the address of the API server - * @param string $headerName a header to pass on requests - */ - function __construct($host, $headerName = null, $headerValue = null) { - $this->host = $host; - $this->headerName = $headerName; - $this->headerValue = $headerValue; + 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 }); } - /** - * Set the user agent of the API client - * - * @param string $user_agent The user agent of the API client - */ - public function setUserAgent($user_agent) { - if (!is_string($user_agent)) { - throw new Exception('User-agent must be a string.'); - } - $this->user_agent= $user_agent; - } - - /** - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - */ - public function setTimeout($seconds) { - if (!is_numeric($seconds)) { - throw new Exception('Timeout variable must be numeric.'); - } - $this->curl_timout = $seconds; - } - - /** - * @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 - */ - public function callAPI($resourcePath, $method, $queryParams, $postData, - $headerParams) { - - $headers = array(); - - # Allow API key from $headerParams to override default - $added_api_key = False; - if ($headerParams != null) { - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; - if ($key == $this->headerName) { - $added_api_key = True; - } - } - } - if (! $added_api_key && $this->headerName != null) { - $headers[] = $this->headerName . ": " . $this->headerValue; - } - - if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) { - $postData = json_encode($this->sanitizeForSerialization($postData)); - } - - $url = $this->host . $resourcePath; - - $curl = curl_init(); - if ($this->curl_timout) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout); - } - // return the result on success, rather than just TRUE - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - if (! empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($method == self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { - throw new Exception('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - if ($this->user_agent) { - curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); - } else { // use PHP-Swagger as the default user agent - curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger'); - } - - // Make the request - $response = curl_exec($curl); - $response_info = curl_getinfo($curl); - - // Handle the response - if ($response_info['http_code'] == 0) { - throw new APIClientException("TIMEOUT: api call to " . $url . - " took more than 5s to return", 0, $response_info, $response); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { - $data = json_decode($response); - if (json_last_error() > 0) { // if response is a string - $data = $response; - } - } else if ($response_info['http_code'] == 401) { - throw new APIClientException("Unauthorized API request to " . $url . - ": " . serialize($response), 0, $response_info, $response); - } else if ($response_info['http_code'] == 404) { - $data = null; - } else { - throw new APIClientException("Can't connect to the api: " . $url . - " response code: " . - $response_info['http_code'], 0, $response_info, $response); - } - return $data; - } - - /** - * Build a JSON POST object - */ - protected function sanitizeForSerialization($data) - { - 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 - */ - public static function toPathValue($value) { - return rawurlencode(toString($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 - */ - public static function toQueryValue($object) { - 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 - */ - public static function toHeaderValue($value) { - return toString($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 - */ - public static function toFormValue($value) { - return toString($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 - */ - public static function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format - return $value->format(\DateTime::ISO8601); - } - else { - return $value; - } - } - - /** - * Deserialize a JSON string into an object - * - * @param object $object object or primitive to be deserialized - * @param string $class class name is passed as a string - * @return object an instance of $class - */ - - public static function deserialize($data, $class) - { - if (null === $data) { - $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { - $inner = substr($class, 4, -1); - $values = array(); - if(strrpos($inner, ",") !== false) { - $subClass_array = explode(',', $inner, 2); - $subClass = $subClass_array[1]; - foreach ($data as $key => $value) { - $values[] = array($key => self::deserialize($value, $subClass)); - } - } - $deserialized = $values; - } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { - $subClass = substr($class, 6, -1); - $values = array(); - foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass); - } - $deserialized = $values; - } elseif ($class == 'DateTime') { - $deserialized = new \DateTime($data); - } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { - settype($data, $class); - $deserialized = $data; - } else { - $instance = new $class(); - foreach ($instance::$swaggerTypes as $property => $type) { - if (isset($data->$property)) { - $original_property_name = $instance::$attributeMap[$property]; - $instance->$property = self::deserialize($data->$original_property_name, $type); - } - } - $deserialized = $instance; - } - - return $deserialized; + # body data + my $_body_data = $post_params ? $post_params : $body_data; + + # Make the HTTP request + my $_request = HTTP::Request->new( + $method, $_url, $headers, $_body_data + ); + + $ua->timeout($http_timeout); + $ua->agent($http_user_agent); + my $_response = $ua->request($_request); + + if (!$_response->is_success) { + #TODO croak("Can't connect ot the api ($_response{code}): $_response{message}"); } + + return $_response->content; } -class APIClientException extends Exception { - protected $response, $response_info; - public function __construct($message="", $code=0, $response_info=null, $response=null) { - parent::__construct($message, $code); - $this->response_info = $response_info; - $this->response = $response; +# 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(); } - - public function getResponse() { - return $this->response; - } - - public function getResponseInfo() { - return $this->response_info; + else { + return $value; } } + + +# Deserialize a JSON string into an object +# +# @param object $object object or primitive to be deserialized +# @param string $class class name is passed as a string +# @return object an instance of $class +#sub deserialize +#{ +# my ($data, $class) = @_; +# if (null === $data) { +# $deserialized = null; +# } elseif (substr($class, 0, 4) == 'map[') { +# $inner = substr($class, 4, -1); +# $values = array(); +# if(strrpos($inner, ",") !== false) { +# $subClass_array = explode(',', $inner, 2); +# $subClass = $subClass_array[1]; +# foreach ($data as $key => $value) { +# $values[] = array($key => self::deserialize($value, $subClass)); +# } +# } +# $deserialized = $values; +# } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { +# $subClass = substr($class, 6, -1); +# $values = array(); +# foreach ($data as $key => $value) { +# $values[] = self::deserialize($value, $subClass); +# } +# $deserialized = $values; +# } elseif ($class == 'DateTime') { +# $deserialized = new \DateTime($data); +# } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { +# settype($data, $class); +# $deserialized = $data; +# } else { +# $instance = new $class(); +# foreach ($instance::$swaggerTypes as $property => $type) { +# if (isset($data->$property)) { +# $original_property_name = $instance::$attributeMap[$property]; +# $instance->$property = self::deserialize($data->$original_property_name, $type); +# } +# } +# $deserialized = $instance; +# } +# +# return $deserialized; +#} + +1; diff --git a/samples/client/petstore/perl/Swagger.pl b/samples/client/petstore/perl/Swagger.pl new file mode 100644 index 00000000000..e58f64107cd --- /dev/null +++ b/samples/client/petstore/perl/Swagger.pl @@ -0,0 +1,229 @@ +package WWW::Swagger::Swagger; + +use strict; +use warnings; +use utf8; + +use LWP::UserAgent; +use HTTP::Headers; +use HTTP::Response; +use HTTP::Status; +use URI::Query; +use JSON; + +use Scalar::Util; + +# class variables +my $ua = LWP::UserAgent->new; +my $http_user_agent = 'Perl-Swagger'; # HTTP user-agent +my $http_timeout; #timeout +my $base_url; + + +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 + my $_body_data = $post_params ? $post_params : $body_data; + + # Make the HTTP request + my $_request = HTTP::Request->new( + $method, $_url, $headers, $_body_data + ); + + $ua->timeout($http_timeout); + $ua->agent($http_user_agent); + my $_response = $ua->request($_request); + + if (!$_response->is_success) { + #TODO croak("Can't connect ot the api ($_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 object $object object or primitive to be deserialized +# @param string $class class name is passed as a string +# @return object an instance of $class +#sub deserialize +#{ +# my ($data, $class) = @_; +# if (null === $data) { +# $deserialized = null; +# } elseif (substr($class, 0, 4) == 'map[') { +# $inner = substr($class, 4, -1); +# $values = array(); +# if(strrpos($inner, ",") !== false) { +# $subClass_array = explode(',', $inner, 2); +# $subClass = $subClass_array[1]; +# foreach ($data as $key => $value) { +# $values[] = array($key => self::deserialize($value, $subClass)); +# } +# } +# $deserialized = $values; +# } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { +# $subClass = substr($class, 6, -1); +# $values = array(); +# foreach ($data as $key => $value) { +# $values[] = self::deserialize($value, $subClass); +# } +# $deserialized = $values; +# } elseif ($class == 'DateTime') { +# $deserialized = new \DateTime($data); +# } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { +# settype($data, $class); +# $deserialized = $data; +# } else { +# $instance = new $class(); +# foreach ($instance::$swaggerTypes as $property => $type) { +# if (isset($data->$property)) { +# $original_property_name = $instance::$attributeMap[$property]; +# $instance->$property = self::deserialize($data->$original_property_name, $type); +# } +# } +# $deserialized = $instance; +# } +# +# return $deserialized; +#} + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/PetApi.pm b/samples/client/petstore/perl/WWW/Swagger/PetApi.pm index a76ed8054ba..94c92c55374 100644 --- a/samples/client/petstore/perl/WWW/Swagger/PetApi.pm +++ b/samples/client/petstore/perl/WWW/Swagger/PetApi.pm @@ -47,14 +47,14 @@ sub new { # - # updatePet + # update_pet # # Update an existing pet # # @param Pet $body Pet object that needs to be added to the store (required) # @return void # - sub updatePet { + sub update_pet { my $self = shift; my %args = @_; @@ -68,7 +68,7 @@ sub new { my $form_params = {}; $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml,'; @@ -96,14 +96,14 @@ sub new { } # - # addPet + # 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 addPet { + sub add_pet { my $self = shift; my %args = @_; @@ -117,7 +117,7 @@ sub new { my $form_params = {}; $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml,'; @@ -145,14 +145,14 @@ sub new { } # - # findPetsByStatus + # 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 findPetsByStatus { + sub find_pets_by_status { my $self = shift; my %args = @_; @@ -199,14 +199,14 @@ sub new { } # - # findPetsByTags + # find_pets_by_tags # # Finds Pets by tags # # @param array[string] $tags Tags to filter by (required) # @return array[Pet] # - sub findPetsByTags { + sub find_pets_by_tags { my $self = shift; my %args = @_; @@ -253,14 +253,14 @@ sub new { } # - # getPetById + # get_pet_by_id # # Find pet by ID # # @param int $pet_id ID of pet that needs to be fetched (required) # @return Pet # - sub getPetById { + sub get_pet_by_id { my $self = shift; my %args = @_; @@ -309,7 +309,7 @@ sub new { } # - # updatePetWithForm + # update_pet_with_form # # Updates a pet in the store with form data # @@ -318,7 +318,7 @@ sub new { # @param string $status Updated status of the pet (required) # @return void # - sub updatePetWithForm { + sub update_pet_with_form { my $self = shift; my %args = @_; @@ -332,7 +332,7 @@ sub new { my $form_params = {}; $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded'; + $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded,'; @@ -368,7 +368,7 @@ sub new { } # - # deletePet + # delete_pet # # Deletes a pet # @@ -376,7 +376,7 @@ sub new { # @param int $pet_id Pet id to delete (required) # @return void # - sub deletePet { + sub delete_pet { my $self = shift; my %args = @_; @@ -423,7 +423,7 @@ sub new { } # - # uploadFile + # upload_file # # uploads an image # @@ -432,7 +432,7 @@ sub new { # @param file $file file to upload (required) # @return void # - sub uploadFile { + sub upload_file { my $self = shift; my %args = @_; @@ -446,7 +446,7 @@ sub new { my $form_params = {}; $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'multipart/form-data'; + $header_params->{'Content-Type'} = 'multipart/form-data,'; diff --git a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm index a9e412ba32c..cc355cd3b6b 100644 --- a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm +++ b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm @@ -47,13 +47,13 @@ sub new { # - # getInventory + # get_inventory # # Returns pet inventories by status # # @return map[string,int] # - sub getInventory { + sub get_inventory { my $self = shift; my %args = @_; @@ -97,14 +97,14 @@ sub new { } # - # placeOrder + # place_order # # Place an order for a pet # # @param Order $body order placed for purchasing the pet (required) # @return Order # - sub placeOrder { + sub place_order { my $self = shift; my %args = @_; @@ -151,14 +151,14 @@ sub new { } # - # getOrderById + # 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 getOrderById { + sub get_order_by_id { my $self = shift; my %args = @_; @@ -207,14 +207,14 @@ sub new { } # - # deleteOrder + # delete_order # # Delete purchase order by ID # # @param string $order_id ID of the order that needs to be deleted (required) # @return void # - sub deleteOrder { + sub delete_order { my $self = shift; my %args = @_; diff --git a/samples/client/petstore/perl/WWW/Swagger/UserApi.pm b/samples/client/petstore/perl/WWW/Swagger/UserApi.pm index 375f6eaf0c1..316c6e8b99d 100644 --- a/samples/client/petstore/perl/WWW/Swagger/UserApi.pm +++ b/samples/client/petstore/perl/WWW/Swagger/UserApi.pm @@ -47,14 +47,14 @@ sub new { # - # createUser + # create_user # # Create user # # @param User $body Created user object (required) # @return void # - sub createUser { + sub create_user { my $self = shift; my %args = @_; @@ -96,14 +96,14 @@ sub new { } # - # createUsersWithArrayInput + # 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 createUsersWithArrayInput { + sub create_users_with_array_input { my $self = shift; my %args = @_; @@ -145,14 +145,14 @@ sub new { } # - # createUsersWithListInput + # 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 createUsersWithListInput { + sub create_users_with_list_input { my $self = shift; my %args = @_; @@ -194,7 +194,7 @@ sub new { } # - # loginUser + # login_user # # Logs user into the system # @@ -202,7 +202,7 @@ sub new { # @param string $password The password for login in clear text (required) # @return string # - sub loginUser { + sub login_user { my $self = shift; my %args = @_; @@ -252,13 +252,13 @@ sub new { } # - # logoutUser + # logout_user # # Logs out current logged in user session # # @return void # - sub logoutUser { + sub logout_user { my $self = shift; my %args = @_; @@ -297,14 +297,14 @@ sub new { } # - # getUserByName + # 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 getUserByName { + sub get_user_by_name { my $self = shift; my %args = @_; @@ -353,7 +353,7 @@ sub new { } # - # updateUser + # update_user # # Updated user # @@ -361,7 +361,7 @@ sub new { # @param User $body Updated user object (required) # @return void # - sub updateUser { + sub update_user { my $self = shift; my %args = @_; @@ -408,14 +408,14 @@ sub new { } # - # deleteUser + # delete_user # # Delete user # # @param string $username The name that needs to be deleted (required) # @return void # - sub deleteUser { + sub delete_user { my $self = shift; my %args = @_; diff --git a/samples/client/petstore/perl/WWW/Swagger/pet_api.pm b/samples/client/petstore/perl/WWW/Swagger/pet_api.pm new file mode 100644 index 00000000000..94c92c55374 --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/pet_api.pm @@ -0,0 +1,486 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +package WWW::Swagger::PetApi; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml,'; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/json,application/xml,'; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/findByStatus"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($args{ status }) { + $query_params->{'status'} = $self->api_client->to_query_value($args{ status }); + } + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/findByTags"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($args{ tags }) { + $query_params->{'tags'} = $self->api_client->to_query_value($args{ tags }); + } + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $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/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'Pet'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded,'; + + + + # path params + if( $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/; + } + # form params + if ($args{ name }) { + $form_params->{'name'} = $self->api_client->to_form_value($args{ name }); + } # form params + if ($args{ status }) { + $form_params->{'status'} = $self->api_client->to_form_value($args{ status }); + } + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + # header params + if($args{ api_key }) { + $header_params->{'api_key'} = $self->apiClient->to_header_value($args{ api_key }); + } + # path params + if( $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/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/pet/{petId}/uploadImage"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = 'multipart/form-data,'; + + + + # path params + if( $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/; + } + # form params + if ($args{ additional_metadata }) { + $form_params->{'additionalMetadata'} = $self->api_client->to_form_value($args{ additional_metadata }); + } # form params + if ($args{ file }) { + $form_params->{'file'} = '@' . $self->api_client->to_form_value($args{ file }); + } + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/store_api.pm b/samples/client/petstore/perl/WWW/Swagger/store_api.pm new file mode 100644 index 00000000000..cc355cd3b6b --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/store_api.pm @@ -0,0 +1,262 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +package WWW::Swagger::StoreApi; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{api_client} + }; + + bless $self, $class; + +} + + + # + # get_inventory + # + # Returns pet inventories by status + # + # @return map[string,int] + # + sub get_inventory { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/inventory"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'map[string,int]'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/order"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'Order'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ order_id }) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $self->api_client->to_path_value($args{ order_id }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'Order'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/store/order/{orderId}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ order_id }) { + my $base_variable = "{" + "orderId" + "}"; + my $base_value = $self->api_client->to_path_value($args{ order_id }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/user_api.pm b/samples/client/petstore/perl/WWW/Swagger/user_api.pm new file mode 100644 index 00000000000..316c6e8b99d --- /dev/null +++ b/samples/client/petstore/perl/WWW/Swagger/user_api.pm @@ -0,0 +1,463 @@ +# +# 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. +# + +require 5.6.0; +use strict; +use warnings; + +#use WWW::Swagger::Model::Category; +#use WWW::Swagger::Model::Pet; + +package WWW::Swagger::UserApi; + +our $VERSION = '2.09'; + + +sub new { + my $class = shift; + my $options = shift; + + croak("You must supply an API client") + unless $options->{api_client}; + + my $self = { + api_client => $options->{api_client} + }; + + bless $self, $class; + +} + + + # + # create_user + # + # Create user + # + # @param User $body Created user object (required) + # @return void + # + sub create_user { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/createWithArray"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/createWithList"; + $resource_path =~ s/{format}/json/; + + my $method = "POST"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/login"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + # query params + if($args{ username }) { + $query_params->{'username'} = $self->api_client->to_query_value($args{ username }); + } # query params + if($args{ password }) { + $query_params->{'password'} = $self->api_client->to_query_value($args{ password }); + } + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'string'); + return $response_object; + } + + # + # logout_user + # + # Logs out current logged in user session + # + # @return void + # + sub logout_user { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/logout"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "GET"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ username }) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $self->api_client->to_path_value($args{ username }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + if(!$response) { + return; + } + + my $response_object = $self->api_client->deserialize($response, 'User'); + 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 = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "PUT"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ username }) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $self->api_client->to_path_value($args{ username }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + # body params + if (isset($body)) { + $body = $body; + } + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + # + # delete_user + # + # Delete user + # + # @param string $username The name that needs to be deleted (required) + # @return void + # + sub delete_user { + my $self = shift; + my %args = @_; + + # parse inputs + my $resource_path = "/user/{username}"; + $resource_path =~ s/{format}/json/; + + my $method = "DELETE"; + my $query_params = {}; + my $header_params = {}; + my $form_params = {}; + + $header_params->{'Accept'} = 'application/json,application/xml'; + $header_params->{'Content-Type'} = ''; + + + + # path params + if( $args{ username }) { + my $base_variable = "{" + "username" + "}"; + my $base_value = $self->api_client->to_path_value($args{ username }); + $resource_path = s/$base_variable/$base_value/; + } + + my $body; + + + # for HTTP post (form) + $body = $body ? undef : $form_params; + + if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { + $body = http_build_query($body); + } + + # make the API Call + my $response = $self->api_client->call_api($resource_path, $method, + $query_params, $body, + $header_params); + + + } + + + +1; From 07cd23edac7cfbfa4d3a1918bb4e3598c5efc92b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 6 May 2015 18:46:31 +0800 Subject: [PATCH 04/11] seralization and deserialization work, get_pet_by_id and update_pet_with_form work --- .../codegen/languages/PerlClientCodegen.java | 8 +- .../src/main/resources/perl/api.mustache | 112 ++-- .../src/main/resources/perl/model.mustache | 134 +++-- .../perl/WWW/Swagger/Model/Category.pm | 60 -- .../petstore/perl/WWW/Swagger/Model/Order.pm | 79 --- .../petstore/perl/WWW/Swagger/Model/Pet.pm | 79 --- .../petstore/perl/WWW/Swagger/Model/Tag.pm | 60 -- .../petstore/perl/WWW/Swagger/Model/User.pm | 87 --- .../petstore/perl/WWW/Swagger/PetApi.pm | 486 ---------------- .../petstore/perl/WWW/Swagger/StoreApi.pm | 262 --------- .../petstore/perl/WWW/Swagger/UserApi.pm | 463 --------------- .../petstore/perl/WWW/Swagger/pet_api.pm | 486 ---------------- .../petstore/perl/WWW/Swagger/store_api.pm | 262 --------- .../petstore/perl/WWW/Swagger/user_api.pm | 463 --------------- samples/client/petstore/perl/http.pl | 25 + .../perl/lib/WWW/SwaggerClient/APIClient.pm | 239 ++++++++ .../lib/WWW/SwaggerClient/Model/Category.pm | 97 ++++ .../perl/lib/WWW/SwaggerClient/Model/Order.pm | 113 ++++ .../perl/lib/WWW/SwaggerClient/Model/Pet.pm | 113 ++++ .../perl/lib/WWW/SwaggerClient/Model/Tag.pm | 97 ++++ .../perl/lib/WWW/SwaggerClient/Model/User.pm | 121 ++++ .../perl/lib/WWW/SwaggerClient/PetApi.pm | 538 ++++++++++++++++++ .../perl/lib/WWW/SwaggerClient/StoreApi.pm | 292 ++++++++++ .../{ => lib/WWW/SwaggerClient}/Swagger.pl | 3 +- .../perl/lib/WWW/SwaggerClient/Swagger.pm | 17 +- .../perl/lib/WWW/SwaggerClient/UserApi.pm | 512 +++++++++++++++++ samples/client/petstore/perl/test.pl | 42 ++ 27 files changed, 2356 insertions(+), 2894 deletions(-) delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Category.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Order.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/Model/User.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/PetApi.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/StoreApi.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/UserApi.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/pet_api.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/store_api.pm delete mode 100644 samples/client/petstore/perl/WWW/Swagger/user_api.pm create mode 100644 samples/client/petstore/perl/http.pl create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Category.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm rename samples/client/petstore/perl/{ => lib/WWW/SwaggerClient}/Swagger.pl (99%) rename modules/swagger-codegen/src/main/resources/perl/Swagger.mustache => samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm (97%) create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm create mode 100644 samples/client/petstore/perl/test.pl 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 92f44872965..d187bcd9011 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 @@ -8,7 +8,7 @@ import java.util.*; import java.io.File; public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { - protected String invokerPackage = "com.wordnik.client"; + protected String invokerPackage = "SwaggerClient"; protected String groupId = "com.wordnik"; protected String artifactId = "swagger-client"; protected String artifactVersion = "1.0.0"; @@ -59,7 +59,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("List", "array"); typeMapping.put("map", "map"); - supportingFiles.add(new SupportingFile("Swagger.mustache", "", "Swagger.pl")); + supportingFiles.add(new SupportingFile("APIClient.mustache", "lib/WWW/" + invokerPackage, "APIClient.pm")); } @Override @@ -69,11 +69,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String apiFileFolder() { - return outputFolder + "/WWW/Swagger/" + apiPackage().replace('.', File.separatorChar); + return outputFolder + "/lib/WWW/" + invokerPackage + apiPackage().replace('.', File.separatorChar); } public String modelFileFolder() { - return outputFolder + "/WWW/Swagger/" + modelPackage().replace('.', File.separatorChar); + return outputFolder + "/lib/WWW/" + invokerPackage + "/" + modelPackage().replace('.', File.separatorChar); } @Override diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache index 76f7b31aa0b..56596c5733d 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -17,29 +17,44 @@ # 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}} -package WWW::Swagger::{{classname}}; -our $VERSION = '2.09'; +use WWW::{{invokerPackage}}::APIClient; +our @EXPORT_OK = qw( + {{#operation}}{{{nickname}}} + {{/operation}} +); sub new { my $class = shift; - my $options = shift; + my $default_api_client = WWW::{{invokerPackage}}::APIClient->new; + #TODO fix default + #my (%arg) = ( + # 'api_client' => $default_api_client, + # @_ + #); - croak("You must supply an API client") - unless $options->{api_client}; + #croak("You must supply an API client") + # unless $options->{api_client}; my $self = { - api_client => $options->{api_client} + #api_client => $options->{api_client} + api_client => $default_api_client }; bless $self, $class; @@ -56,63 +71,72 @@ sub new { {{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} # sub {{nickname}} { - my $self = shift; - my %args = @_; + my ($self, $args) = @_; - # parse inputs - my $resource_path = "{{path}}"; - $resource_path =~ s/{format}/json/; + {{#allParams}}{{#required}} + # verify the required parameter '{{paramName}}' is set + unless (exists $args->{'{{paramName}}'}) { + croak("Missing the required parameter '{{paramName}}' when calling {{nickname}}"); + } + {{/required}}{{/allParams}} - my $method = "{{httpMethod}}"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}'; - $header_params->{'Content-Type'} = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}'; + # 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($args{ {{paramName}} }) { - $query_params->{'{{baseName}}'} = $self->api_client->to_query_value($args{ {{paramName}} }); + if ( exists $args->{'{{paramName}}'}) { + $query_params->{'{{baseName}}'} = WWW::SwaggerClient::APIClient::to_query_value($args->{'{{paramName}}'}); }{{/queryParams}} {{#headerParams}} # header params - if($args{ {{paramName}} }) { - $header_params->{'{{baseName}}'} = $self->apiClient->to_header_value($args{ {{paramName}} }); + if ( exists $args->{'{{paramName}}'}) { + $header_params->{'{{baseName}}'} = WWW::SwaggerClient::APIClient::to_header_value($args->{'{{paramName}}'}); }{{/headerParams}} {{#pathParams}} # path params - if( $args{ {{paramName}} }) { - my $base_variable = "{" + "{{baseName}}" + "}"; - my $base_value = $self->api_client->to_path_value($args{ {{paramName}} }); - $resource_path = s/$base_variable/$base_value/; + if ( exists $args->{'{{paramName}}'}) { + my $_base_variable = "{" . "{{baseName}}" . "}"; + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'{{paramName}}'}); + $_resource_path =~ s/$_base_variable/$_base_value/g; }{{/pathParams}} {{#formParams}} # form params - if ($args{ {{paramName}} }) { - $form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}$self->api_client->to_form_value($args{ {{paramName}} }); + if ( exists $args->{'{{paramName}}'} ) { + $form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}WWW::SwaggerClient::APIClient::to_form_value($args->{'{{paramName}}'}); }{{/formParams}} - my $body; + my $_body_data; {{#bodyParams}} # body params - if (isset(${{paramName}})) { - $body = ${{paramName}}; + if ( exists $args->{'{{paramName}}'}) { + $_body_data = $args->{'{{paramName}}'}; }{{/bodyParams}} # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } + #$_body_data = $_body ? undef : $form_params; # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - {{#returnType}}if(!$response) { + {{#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($response, '{{returnType}}'); - return $response_object;{{/returnType}} + 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}} diff --git a/modules/swagger-codegen/src/main/resources/perl/model.mustache b/modules/swagger-codegen/src/main/resources/perl/model.mustache index 4540f973633..3612ed1050a 100644 --- a/modules/swagger-codegen/src/main/resources/perl/model.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/model.mustache @@ -1,66 +1,100 @@ - '{{{datatype}}}'{{#hasMore}}, {{/hasMore}}{{/vars}} - ); +}; - static $attributeMap = array( +my $attribute_map = { {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, {{/hasMore}}{{/vars}} - ); +}; - {{#vars}}{{#description}} - /** - * {{{description}}} - */{{/description}} - public ${{name}}; /* {{{datatype}}} */{{/vars}} +# new object +sub new { + my ($class, $args) = @_; + my $self = { + {{#vars}}#{{#description}}{{{description}}}{{/description}} + '{{name}}' => $args->{'{{baseName}}'}{{#hasMore}}, + {{/hasMore}}{{/vars}} + }; - public function __construct(array $data) { - {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} - {{/hasMore}}{{/vars}} + return bless $self, $class; +} + +# 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 $attribute_map) { + if (defined $self->{$attribute_map->{$_key}}) { + $_data->{$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 $swagger_types) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$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); + } } - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); + 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$/, ('string', 'int', 'float', 'bool')) ) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + return $_instance->from_hash($data); } } + {{/model}} {{/models}} + +1; diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Category.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Category.pm deleted file mode 100644 index 98e7ba24800..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Category.pm +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Order.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Order.pm deleted file mode 100644 index 2770e8bbbdf..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Order.pm +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => 'DateTime', - 'status' => 'string', - 'complete' => 'boolean' - ); - - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ - /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm deleted file mode 100644 index eee7fa3784c..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Pet.pm +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'category' => 'Category', - 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', - 'status' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ - /** - * pet status in the store - */ - public $status; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm b/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm deleted file mode 100644 index f8efc998df6..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/Tag.pm +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/Model/User.pm b/samples/client/petstore/perl/WWW/Swagger/Model/User.pm deleted file mode 100644 index d6b520eba51..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/Model/User.pm +++ /dev/null @@ -1,87 +0,0 @@ - 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - - public $id; /* int */ - public $username; /* string */ - public $first_name; /* string */ - public $last_name; /* string */ - public $email; /* string */ - public $password; /* string */ - public $phone; /* string */ - /** - * User Status - */ - public $user_status; /* int */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/perl/WWW/Swagger/PetApi.pm b/samples/client/petstore/perl/WWW/Swagger/PetApi.pm deleted file mode 100644 index 94c92c55374..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/PetApi.pm +++ /dev/null @@ -1,486 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - -package WWW::Swagger::PetApi; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client => $options->{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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml,'; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml,'; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/findByStatus"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($args{ status }) { - $query_params->{'status'} = $self->api_client->to_query_value($args{ status }); - } - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/findByTags"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($args{ tags }) { - $query_params->{'tags'} = $self->api_client->to_query_value($args{ tags }); - } - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $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/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'Pet'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded,'; - - - - # path params - if( $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/; - } - # form params - if ($args{ name }) { - $form_params->{'name'} = $self->api_client->to_form_value($args{ name }); - } # form params - if ($args{ status }) { - $form_params->{'status'} = $self->api_client->to_form_value($args{ status }); - } - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - # header params - if($args{ api_key }) { - $header_params->{'api_key'} = $self->apiClient->to_header_value($args{ api_key }); - } - # path params - if( $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/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}/uploadImage"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'multipart/form-data,'; - - - - # path params - if( $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/; - } - # form params - if ($args{ additional_metadata }) { - $form_params->{'additionalMetadata'} = $self->api_client->to_form_value($args{ additional_metadata }); - } # form params - if ($args{ file }) { - $form_params->{'file'} = '@' . $self->api_client->to_form_value($args{ file }); - } - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm b/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm deleted file mode 100644 index cc355cd3b6b..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/StoreApi.pm +++ /dev/null @@ -1,262 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - -package WWW::Swagger::StoreApi; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client => $options->{api_client} - }; - - bless $self, $class; - -} - - - # - # get_inventory - # - # Returns pet inventories by status - # - # @return map[string,int] - # - sub get_inventory { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/inventory"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'map[string,int]'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/order"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'Order'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ order_id }) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $self->api_client->to_path_value($args{ order_id }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'Order'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ order_id }) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $self->api_client->to_path_value($args{ order_id }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/UserApi.pm b/samples/client/petstore/perl/WWW/Swagger/UserApi.pm deleted file mode 100644 index 316c6e8b99d..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/UserApi.pm +++ /dev/null @@ -1,463 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - -package WWW::Swagger::UserApi; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client => $options->{api_client} - }; - - bless $self, $class; - -} - - - # - # create_user - # - # Create user - # - # @param User $body Created user object (required) - # @return void - # - sub create_user { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/createWithArray"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/createWithList"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/login"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($args{ username }) { - $query_params->{'username'} = $self->api_client->to_query_value($args{ username }); - } # query params - if($args{ password }) { - $query_params->{'password'} = $self->api_client->to_query_value($args{ password }); - } - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'string'); - return $response_object; - } - - # - # logout_user - # - # Logs out current logged in user session - # - # @return void - # - sub logout_user { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/logout"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ username }) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $self->api_client->to_path_value($args{ username }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'User'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ username }) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $self->api_client->to_path_value($args{ username }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # delete_user - # - # Delete user - # - # @param string $username The name that needs to be deleted (required) - # @return void - # - sub delete_user { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ username }) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $self->api_client->to_path_value($args{ username }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/pet_api.pm b/samples/client/petstore/perl/WWW/Swagger/pet_api.pm deleted file mode 100644 index 94c92c55374..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/pet_api.pm +++ /dev/null @@ -1,486 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - -package WWW::Swagger::PetApi; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client => $options->{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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml,'; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/json,application/xml,'; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/findByStatus"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($args{ status }) { - $query_params->{'status'} = $self->api_client->to_query_value($args{ status }); - } - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/findByTags"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($args{ tags }) { - $query_params->{'tags'} = $self->api_client->to_query_value($args{ tags }); - } - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'array[Pet]'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $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/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'Pet'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'application/x-www-form-urlencoded,'; - - - - # path params - if( $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/; - } - # form params - if ($args{ name }) { - $form_params->{'name'} = $self->api_client->to_form_value($args{ name }); - } # form params - if ($args{ status }) { - $form_params->{'status'} = $self->api_client->to_form_value($args{ status }); - } - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - # header params - if($args{ api_key }) { - $header_params->{'api_key'} = $self->apiClient->to_header_value($args{ api_key }); - } - # path params - if( $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/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/pet/{petId}/uploadImage"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = 'multipart/form-data,'; - - - - # path params - if( $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/; - } - # form params - if ($args{ additional_metadata }) { - $form_params->{'additionalMetadata'} = $self->api_client->to_form_value($args{ additional_metadata }); - } # form params - if ($args{ file }) { - $form_params->{'file'} = '@' . $self->api_client->to_form_value($args{ file }); - } - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/store_api.pm b/samples/client/petstore/perl/WWW/Swagger/store_api.pm deleted file mode 100644 index cc355cd3b6b..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/store_api.pm +++ /dev/null @@ -1,262 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - -package WWW::Swagger::StoreApi; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client => $options->{api_client} - }; - - bless $self, $class; - -} - - - # - # get_inventory - # - # Returns pet inventories by status - # - # @return map[string,int] - # - sub get_inventory { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/inventory"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'map[string,int]'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/order"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'Order'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ order_id }) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $self->api_client->to_path_value($args{ order_id }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'Order'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/store/order/{orderId}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ order_id }) { - my $base_variable = "{" + "orderId" + "}"; - my $base_value = $self->api_client->to_path_value($args{ order_id }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - - -1; diff --git a/samples/client/petstore/perl/WWW/Swagger/user_api.pm b/samples/client/petstore/perl/WWW/Swagger/user_api.pm deleted file mode 100644 index 316c6e8b99d..00000000000 --- a/samples/client/petstore/perl/WWW/Swagger/user_api.pm +++ /dev/null @@ -1,463 +0,0 @@ -# -# 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. -# - -require 5.6.0; -use strict; -use warnings; - -#use WWW::Swagger::Model::Category; -#use WWW::Swagger::Model::Pet; - -package WWW::Swagger::UserApi; - -our $VERSION = '2.09'; - - -sub new { - my $class = shift; - my $options = shift; - - croak("You must supply an API client") - unless $options->{api_client}; - - my $self = { - api_client => $options->{api_client} - }; - - bless $self, $class; - -} - - - # - # create_user - # - # Create user - # - # @param User $body Created user object (required) - # @return void - # - sub create_user { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/createWithArray"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/createWithList"; - $resource_path =~ s/{format}/json/; - - my $method = "POST"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/login"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - # query params - if($args{ username }) { - $query_params->{'username'} = $self->api_client->to_query_value($args{ username }); - } # query params - if($args{ password }) { - $query_params->{'password'} = $self->api_client->to_query_value($args{ password }); - } - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'string'); - return $response_object; - } - - # - # logout_user - # - # Logs out current logged in user session - # - # @return void - # - sub logout_user { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/logout"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "GET"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ username }) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $self->api_client->to_path_value($args{ username }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - if(!$response) { - return; - } - - my $response_object = $self->api_client->deserialize($response, 'User'); - 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 = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "PUT"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ username }) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $self->api_client->to_path_value($args{ username }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - # body params - if (isset($body)) { - $body = $body; - } - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - # - # delete_user - # - # Delete user - # - # @param string $username The name that needs to be deleted (required) - # @return void - # - sub delete_user { - my $self = shift; - my %args = @_; - - # parse inputs - my $resource_path = "/user/{username}"; - $resource_path =~ s/{format}/json/; - - my $method = "DELETE"; - my $query_params = {}; - my $header_params = {}; - my $form_params = {}; - - $header_params->{'Accept'} = 'application/json,application/xml'; - $header_params->{'Content-Type'} = ''; - - - - # path params - if( $args{ username }) { - my $base_variable = "{" + "username" + "}"; - my $base_value = $self->api_client->to_path_value($args{ username }); - $resource_path = s/$base_variable/$base_value/; - } - - my $body; - - - # for HTTP post (form) - $body = $body ? undef : $form_params; - - if ($header_params->{'Content-Type'} eq "application/x-www-form-urlencoded") { - $body = http_build_query($body); - } - - # make the API Call - my $response = $self->api_client->call_api($resource_path, $method, - $query_params, $body, - $header_params); - - - } - - - -1; diff --git a/samples/client/petstore/perl/http.pl b/samples/client/petstore/perl/http.pl new file mode 100644 index 00000000000..282b06ba3e5 --- /dev/null +++ b/samples/client/petstore/perl/http.pl @@ -0,0 +1,25 @@ +use LWP::UserAgent; + +my $ua = LWP::UserAgent->new; + +my $server_endpoint = "http://petstore.swagger.io/v2/pet/10002"; + +# set custom HTTP request header fields +my $req = HTTP::Request->new(GET => $server_endpoint); +$req->header('content-type' => 'application/json'); + +use Data::Dumper; +print Dumper($req); + +my $resp = $ua->request($req); +if ($resp->is_success) { + my $message = $resp->decoded_content; + print "Received reply: $message\n"; +} +else { + print "HTTP GET error code: ", $resp->code, "\n"; + print "HTTP GET error message: ", $resp->message, "\n"; +} + + + 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..cf9e85119fd --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -0,0 +1,239 @@ +package WWW::SwaggerClient::APIClient; + +use strict; +use warnings; +use utf8; + +use LWP::UserAgent; +use HTTP::Headers; +use HTTP::Response; +use HTTP::Request::Common; +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 + my $_body_data = $post_params ? $post_params : $body_data; + + # Make the HTTP request + my $_request; + switch ($method) { + case 'POST' { + #TODO: multipart + $_request = POST($_url, Accept => $header_params->{Accept}, + Content_Type => $header_params->{'Content-Type'}, Content => $_body_data); + } + case 'GET' { + $_request = GET($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}); + } + case 'PUT' { + + } + } + + $ua->timeout($http_timeout); + $ua->agent($http_user_agent); + + my $_response = $ua->request($_request); + + unless ($_response->is_success) { + croak("Can't connect to the server"); + #croak("Can't connect to the api ($_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 object $object object or primitive to be deserialized +# @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 (substr($class, 0, 4) eq 'map[') { #TODO map + $_result = $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::Model::$class")->new; + $_result = $_instance->from_hash(decode_json $data); + } + + return $_result; + +} + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Category.pm new file mode 100644 index 00000000000..03e22e073a2 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Category.pm @@ -0,0 +1,97 @@ +package WWW::SwaggerClient::Model::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); + + +# +# +# +#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; +} + +# 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 $attribute_map) { + if (defined $self->{$attribute_map->{$_key}}) { + $_data->{$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 $swagger_types) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + return $_instance->from_hash($data); + } +} + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm new file mode 100644 index 00000000000..7bfc8e4a85c --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm @@ -0,0 +1,113 @@ +package WWW::SwaggerClient::Model::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); + + +# +# +# +#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; +} + +# 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 $attribute_map) { + if (defined $self->{$attribute_map->{$_key}}) { + $_data->{$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 $swagger_types) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + return $_instance->from_hash($data); + } +} + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm new file mode 100644 index 00000000000..1b41f6fd88c --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm @@ -0,0 +1,113 @@ +package WWW::SwaggerClient::Model::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); + + +# +# +# +#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; +} + +# 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 $attribute_map) { + if (defined $self->{$attribute_map->{$_key}}) { + $_data->{$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 $swagger_types) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + return $_instance->from_hash($data); + } +} + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm new file mode 100644 index 00000000000..eb838d1d7ec --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm @@ -0,0 +1,97 @@ +package WWW::SwaggerClient::Model::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); + + +# +# +# +#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; +} + +# 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 $attribute_map) { + if (defined $self->{$attribute_map->{$_key}}) { + $_data->{$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 $swagger_types) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + return $_instance->from_hash($data); + } +} + + +1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm new file mode 100644 index 00000000000..4a431457ab7 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm @@ -0,0 +1,121 @@ +package WWW::SwaggerClient::Model::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); + + +# +# +# +#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; +} + +# 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 $attribute_map) { + if (defined $self->{$attribute_map->{$_key}}) { + $_data->{$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 $swagger_types) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { + return $data; + } else { # hash(model) + my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + return $_instance->from_hash($data); + } +} + + +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..4771c559887 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -0,0 +1,538 @@ +# +# 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; + #TODO fix default + #my (%arg) = ( + # 'api_client' => $default_api_client, + # @_ + #); + + #croak("You must supply an API client") + # unless $options->{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::SwaggerClient::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::SwaggerClient::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'} = '@' . WWW::SwaggerClient::APIClient::to_form_value($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..eaf819a16d0 --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm @@ -0,0 +1,292 @@ +# +# 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; + #TODO fix default + #my (%arg) = ( + # 'api_client' => $default_api_client, + # @_ + #); + + #croak("You must supply an API client") + # unless $options->{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 map[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('map[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/Swagger.pl b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl similarity index 99% rename from samples/client/petstore/perl/Swagger.pl rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl index e58f64107cd..a5a82fcbd3f 100644 --- a/samples/client/petstore/perl/Swagger.pl +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl @@ -1,4 +1,4 @@ -package WWW::Swagger::Swagger; +package WWW::SwaggerClient::Swagger; use strict; use warnings; @@ -79,6 +79,7 @@ sub call_api { $ua->timeout($http_timeout); $ua->agent($http_user_agent); + my $_response = $ua->request($_request); if (!$_response->is_success) { diff --git a/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm similarity index 97% rename from modules/swagger-codegen/src/main/resources/perl/Swagger.mustache rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm index e58f64107cd..6f7e645bfd0 100644 --- a/modules/swagger-codegen/src/main/resources/perl/Swagger.mustache +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm @@ -1,4 +1,4 @@ -package WWW::Swagger::Swagger; +package WWW::SwaggerClient::Swagger; use strict; use warnings; @@ -17,7 +17,7 @@ use Scalar::Util; my $ua = LWP::UserAgent->new; my $http_user_agent = 'Perl-Swagger'; # HTTP user-agent my $http_timeout; #timeout -my $base_url; +my $base_url = "http://petstore.swagger.io/v2"; sub new @@ -79,6 +79,7 @@ sub call_api { $ua->timeout($http_timeout); $ua->agent($http_user_agent); + my $_response = $ua->request($_request); if (!$_response->is_success) { @@ -91,8 +92,8 @@ sub call_api { # Build a JSON POST object -#sub sanitize_for_serialization -#{ +sub sanitize_for_serialization +{ # my $data = shift; # if (is_scalar($data) || null === $data) { # $sanitized = $data; @@ -114,7 +115,7 @@ sub call_api { # } # # return $sanitized; -#} +} # Take value and turn it into a string suitable for inclusion in @@ -184,8 +185,8 @@ sub to_string { # @param object $object object or primitive to be deserialized # @param string $class class name is passed as a string # @return object an instance of $class -#sub deserialize -#{ +sub deserialize +{ # my ($data, $class) = @_; # if (null === $data) { # $deserialized = null; @@ -224,6 +225,6 @@ sub to_string { # } # # return $deserialized; -#} +} 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..3582520cd5c --- /dev/null +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -0,0 +1,512 @@ +# +# 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; + #TODO fix default + #my (%arg) = ( + # 'api_client' => $default_api_client, + # @_ + #); + + #croak("You must supply an API client") + # unless $options->{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::SwaggerClient::APIClient::to_query_value($args->{'username'}); + } # query params + if ( exists $args->{'password'}) { + $query_params->{'password'} = WWW::SwaggerClient::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 100644 index 00000000000..f415dc36c09 --- /dev/null +++ b/samples/client/petstore/perl/test.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +# +# + +use strict; +use warnings; +use WWW::SwaggerClient::PetApi; +use WWW::SwaggerClient::APIClient; +use WWW::SwaggerClient::Model::Pet; +use WWW::SwaggerClient::Model::Tag; +use WWW::SwaggerClient::Model::Category; +use JSON; +use Data::Dumper; + +my $api = WWW::SwaggerClient::PetApi->new(); + +print WWW::SwaggerClient::APIClient::to_form_value('testing 123'); + +my $pet_id = 5; + +my $tag = WWW::SwaggerClient::Model::Tag->new({'id' => 'tag1', 'name' => 'just kidding', + "photoUrls" => ['123', 'oop']}); +my $pet = WWW::SwaggerClient::Model::Pet->new({'id' => 5, 'name' => 'haha', + "photoUrls" => ['123', 'oop'], 'tags' => [$tag]}); + +##print Dumper $pet; + +my $json = JSON->new->convert_blessed; + +#print $json->convert_blessed->encode($pet); +#print $json->get_convert_blessed; +##print Dumper($pet->to_hash); + + +#my $pet2 = WWW::SwaggerClient::Model::Pet->from_json($pet->to_hash); +my $pet2 = WWW::SwaggerClient::Model::Pet->new(); +$pet2 = $pet2->from_hash($pet->to_hash); +#$pet2->from_json($pet->to_hash); +##print Dumper($pet2->to_hash); +print "============================\n"; +print Dumper $api->get_pet_by_id({pet_id => $pet_id}); +print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'}); From 0a34793f5abc3462ccd36754e94b37a8e2a2a189 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 7 May 2015 10:03:30 +0800 Subject: [PATCH 05/11] add inheritance to object (model) --- .../codegen/languages/PerlClientCodegen.java | 5 +- .../main/resources/perl/APIClient.mustache | 106 ++++---- .../main/resources/perl/BaseObject.mustache | 76 ++++++ .../src/main/resources/perl/api.mustache | 8 +- .../perl/{model.mustache => object.mustache} | 7 +- .../perl/lib/WWW/SwaggerClient/APIClient.pm | 7 +- .../WWW/SwaggerClient/Object/BaseObject.pm | 76 ++++++ .../{Model => Object}/Category.pm | 7 +- .../SwaggerClient/{Model => Object}/Order.pm | 7 +- .../SwaggerClient/{Model => Object}/Pet.pm | 7 +- .../SwaggerClient/{Model => Object}/Tag.pm | 7 +- .../SwaggerClient/{Model => Object}/User.pm | 7 +- .../perl/lib/WWW/SwaggerClient/PetApi.pm | 4 +- .../perl/lib/WWW/SwaggerClient/Swagger.pl | 230 ------------------ .../perl/lib/WWW/SwaggerClient/UserApi.pm | 4 +- samples/client/petstore/perl/test.pl | 20 +- 16 files changed, 262 insertions(+), 316 deletions(-) rename samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm => modules/swagger-codegen/src/main/resources/perl/APIClient.mustache (71%) create mode 100644 modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache rename modules/swagger-codegen/src/main/resources/perl/{model.mustache => object.mustache} (91%) create mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm rename samples/client/petstore/perl/lib/WWW/SwaggerClient/{Model => Object}/Category.pm (91%) rename samples/client/petstore/perl/lib/WWW/SwaggerClient/{Model => Object}/Order.pm (93%) rename samples/client/petstore/perl/lib/WWW/SwaggerClient/{Model => Object}/Pet.pm (93%) rename samples/client/petstore/perl/lib/WWW/SwaggerClient/{Model => Object}/Tag.pm (91%) rename samples/client/petstore/perl/lib/WWW/SwaggerClient/{Model => Object}/User.pm (93%) delete mode 100644 samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl 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 d187bcd9011..4edead804d5 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 @@ -27,9 +27,9 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { public PerlClientCodegen() { super(); - modelPackage = "Model"; + modelPackage = "Object"; outputFolder = "generated-code/perl"; - modelTemplateFiles.put("model.mustache", ".pm"); + modelTemplateFiles.put("object.mustache", ".pm"); apiTemplateFiles.put("api.mustache", ".pm"); templateDir = "perl"; @@ -60,6 +60,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("map", "map"); supportingFiles.add(new SupportingFile("APIClient.mustache", "lib/WWW/" + invokerPackage, "APIClient.pm")); + supportingFiles.add(new SupportingFile("BaseObject.mustache", "lib/WWW/" + invokerPackage, "Object/BaseObject.pm")); } @Override diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache similarity index 71% rename from samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm rename to modules/swagger-codegen/src/main/resources/perl/APIClient.mustache index 6f7e645bfd0..44d5b60b21e 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pm +++ b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache @@ -1,4 +1,4 @@ -package WWW::SwaggerClient::Swagger; +package WWW::{{invokerPackage}}::APIClient; use strict; use warnings; @@ -7,17 +7,22 @@ use utf8; use LWP::UserAgent; use HTTP::Headers; use HTTP::Response; +use HTTP::Request::Common; 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"; +my $base_url = "{{basePath}}"; sub new @@ -65,7 +70,7 @@ sub call_api { my $_url = $base_url . $resource_path; # build query - if ($query_params) { + if (%$query_params) { $_url = ($_url . '?' . eval { URI::Query->new($query_params)->stringify }); } @@ -73,17 +78,30 @@ sub call_api { my $_body_data = $post_params ? $post_params : $body_data; # Make the HTTP request - my $_request = HTTP::Request->new( - $method, $_url, $headers, $_body_data - ); + my $_request; + switch ($method) { + case 'POST' { + #TODO: multipart + $_request = POST($_url, Accept => $header_params->{Accept}, + Content_Type => $header_params->{'Content-Type'}, Content => $_body_data); + } + case 'GET' { + $_request = GET($_url, Accept => $header_params->{'Accept'}, + Content_Type => $header_params->{'Content-Type'}); + } + case 'PUT' { + + } + } $ua->timeout($http_timeout); $ua->agent($http_user_agent); my $_response = $ua->request($_request); - if (!$_response->is_success) { - #TODO croak("Can't connect ot the api ($_response{code}): $_response{message}"); + unless ($_response->is_success) { + croak("Can't connect to the server"); + #croak("Can't connect to the api ($_response{code}): $_response{message}"); } return $_response->content; @@ -179,52 +197,42 @@ sub to_string { } } - # Deserialize a JSON string into an object # -# @param object $object object or primitive to be deserialized # @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 ($data, $class) = @_; -# if (null === $data) { -# $deserialized = null; -# } elseif (substr($class, 0, 4) == 'map[') { -# $inner = substr($class, 4, -1); -# $values = array(); -# if(strrpos($inner, ",") !== false) { -# $subClass_array = explode(',', $inner, 2); -# $subClass = $subClass_array[1]; -# foreach ($data as $key => $value) { -# $values[] = array($key => self::deserialize($value, $subClass)); -# } -# } -# $deserialized = $values; -# } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { -# $subClass = substr($class, 6, -1); -# $values = array(); -# foreach ($data as $key => $value) { -# $values[] = self::deserialize($value, $subClass); -# } -# $deserialized = $values; -# } elseif ($class == 'DateTime') { -# $deserialized = new \DateTime($data); -# } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { -# settype($data, $class); -# $deserialized = $data; -# } else { -# $instance = new $class(); -# foreach ($instance::$swaggerTypes as $property => $type) { -# if (isset($data->$property)) { -# $original_property_name = $instance::$attributeMap[$property]; -# $instance->$property = self::deserialize($data->$original_property_name, $type); -# } -# } -# $deserialized = $instance; -# } -# -# return $deserialized; + 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..be8937a16f0 --- /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->{attribute_map}) { + if (defined $self->{$self->{attribute_map}->{$_key}}) { + $_data->{$self->{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->{swagger_types}) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$self->{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$/, ('string', 'int', 'float', 'bool')) ) { + 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 index 56596c5733d..7eb16b8a1a5 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -98,21 +98,21 @@ sub new { {{#queryParams}} # query params if ( exists $args->{'{{paramName}}'}) { - $query_params->{'{{baseName}}'} = WWW::SwaggerClient::APIClient::to_query_value($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::SwaggerClient::APIClient::to_header_value($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::SwaggerClient::APIClient::to_path_value($args->{'{{paramName}}'}); + 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}}'} ) { - $form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}WWW::SwaggerClient::APIClient::to_form_value($args->{'{{paramName}}'}); + $form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}WWW::{{invokerPackage}}::APIClient::to_form_value($args->{'{{paramName}}'}); }{{/formParams}} my $_body_data; {{#bodyParams}} # body params diff --git a/modules/swagger-codegen/src/main/resources/perl/model.mustache b/modules/swagger-codegen/src/main/resources/perl/object.mustache similarity index 91% rename from modules/swagger-codegen/src/main/resources/perl/model.mustache rename to modules/swagger-codegen/src/main/resources/perl/object.mustache index 3612ed1050a..73b2e749ea3 100644 --- a/modules/swagger-codegen/src/main/resources/perl/model.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/object.mustache @@ -1,6 +1,6 @@ {{#models}} {{#model}} -package WWW::{{invokerPackage}}::Model::{{classname}}; +package WWW::{{invokerPackage}}::Object::{{classname}}; require 5.6.0; use strict; @@ -10,7 +10,10 @@ 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}} @@ -89,7 +92,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { return $data; } else { # hash(model) - my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm index cf9e85119fd..18246004781 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -199,7 +199,6 @@ sub to_string { # Deserialize a JSON string into an object # -# @param object $object object or primitive to be deserialized # @param string $class class name is passed as a string # @param string $data data of the body # @return object an instance of $class @@ -211,8 +210,8 @@ sub deserialize if (not defined $data) { return undef; - } elsif (substr($class, 0, 4) eq 'map[') { #TODO map - $_result = $data; + } 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 @@ -228,7 +227,7 @@ sub deserialize } elsif (grep /^$data$/, ('string', 'int', 'float', 'bool')) { #TODO revise the primitive type $_result= $data; } else { # model - my $_instance = use_module("WWW::SwaggerClient::Model::$class")->new; + my $_instance = use_module("WWW::SwaggerClient::Object::$class")->new; $_result = $_instance->from_hash(decode_json $data); } 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..276b3f46f0f --- /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->{attribute_map}) { + if (defined $self->{$self->{attribute_map}->{$_key}}) { + $_data->{$self->{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->{swagger_types}) { + if ($_type =~ /^array\[/i) { # array + my $_subclass = substr($_type, 6, -1); + my @_array = (); + foreach my $_element (@{$hash->{$self->{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$/, ('string', 'int', 'float', 'bool')) ) { + 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/Model/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm similarity index 91% rename from samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Category.pm rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm index 03e22e073a2..b82bd5f82a2 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Category.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm @@ -1,4 +1,4 @@ -package WWW::SwaggerClient::Model::Category; +package WWW::SwaggerClient::Object::Category; require 5.6.0; use strict; @@ -8,7 +8,10 @@ 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"; # # @@ -88,7 +91,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { return $data; } else { # hash(model) - my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm similarity index 93% rename from samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm index 7bfc8e4a85c..35a6e96fac8 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Order.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm @@ -1,4 +1,4 @@ -package WWW::SwaggerClient::Model::Order; +package WWW::SwaggerClient::Object::Order; require 5.6.0; use strict; @@ -8,7 +8,10 @@ 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"; # # @@ -104,7 +107,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { return $data; } else { # hash(model) - my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm similarity index 93% rename from samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm index 1b41f6fd88c..1e692d7bb51 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Pet.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm @@ -1,4 +1,4 @@ -package WWW::SwaggerClient::Model::Pet; +package WWW::SwaggerClient::Object::Pet; require 5.6.0; use strict; @@ -8,7 +8,10 @@ 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"; # # @@ -104,7 +107,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { return $data; } else { # hash(model) - my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm similarity index 91% rename from samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm index eb838d1d7ec..b46b44927f8 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/Tag.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm @@ -1,4 +1,4 @@ -package WWW::SwaggerClient::Model::Tag; +package WWW::SwaggerClient::Object::Tag; require 5.6.0; use strict; @@ -8,7 +8,10 @@ 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"; # # @@ -88,7 +91,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { return $data; } else { # hash(model) - my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm similarity index 93% rename from samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm rename to samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm index 4a431457ab7..08d9ff6b080 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Model/User.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm @@ -1,4 +1,4 @@ -package WWW::SwaggerClient::Model::User; +package WWW::SwaggerClient::Object::User; require 5.6.0; use strict; @@ -8,7 +8,10 @@ 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"; # # @@ -112,7 +115,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { return $data; } else { # hash(model) - my $_instance = eval "WWW::SwaggerClient::Model::$type->new()"; + my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index 4771c559887..8b02083e637 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -201,7 +201,7 @@ sub new { # query params if ( exists $args->{'status'}) { - $query_params->{'status'} = WWW::SwaggerClient::APIClient::to_query_value($args->{'status'}); + $query_params->{'status'} = WWW::::APIClient::to_query_value($args->{'status'}); } @@ -255,7 +255,7 @@ sub new { # query params if ( exists $args->{'tags'}) { - $query_params->{'tags'} = WWW::SwaggerClient::APIClient::to_query_value($args->{'tags'}); + $query_params->{'tags'} = WWW::::APIClient::to_query_value($args->{'tags'}); } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl deleted file mode 100644 index a5a82fcbd3f..00000000000 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Swagger.pl +++ /dev/null @@ -1,230 +0,0 @@ -package WWW::SwaggerClient::Swagger; - -use strict; -use warnings; -use utf8; - -use LWP::UserAgent; -use HTTP::Headers; -use HTTP::Response; -use HTTP::Status; -use URI::Query; -use JSON; - -use Scalar::Util; - -# class variables -my $ua = LWP::UserAgent->new; -my $http_user_agent = 'Perl-Swagger'; # HTTP user-agent -my $http_timeout; #timeout -my $base_url; - - -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 - my $_body_data = $post_params ? $post_params : $body_data; - - # Make the HTTP request - my $_request = HTTP::Request->new( - $method, $_url, $headers, $_body_data - ); - - $ua->timeout($http_timeout); - $ua->agent($http_user_agent); - - my $_response = $ua->request($_request); - - if (!$_response->is_success) { - #TODO croak("Can't connect ot the api ($_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 object $object object or primitive to be deserialized -# @param string $class class name is passed as a string -# @return object an instance of $class -#sub deserialize -#{ -# my ($data, $class) = @_; -# if (null === $data) { -# $deserialized = null; -# } elseif (substr($class, 0, 4) == 'map[') { -# $inner = substr($class, 4, -1); -# $values = array(); -# if(strrpos($inner, ",") !== false) { -# $subClass_array = explode(',', $inner, 2); -# $subClass = $subClass_array[1]; -# foreach ($data as $key => $value) { -# $values[] = array($key => self::deserialize($value, $subClass)); -# } -# } -# $deserialized = $values; -# } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { -# $subClass = substr($class, 6, -1); -# $values = array(); -# foreach ($data as $key => $value) { -# $values[] = self::deserialize($value, $subClass); -# } -# $deserialized = $values; -# } elseif ($class == 'DateTime') { -# $deserialized = new \DateTime($data); -# } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { -# settype($data, $class); -# $deserialized = $data; -# } else { -# $instance = new $class(); -# foreach ($instance::$swaggerTypes as $property => $type) { -# if (isset($data->$property)) { -# $original_property_name = $instance::$attributeMap[$property]; -# $instance->$property = self::deserialize($data->$original_property_name, $type); -# } -# } -# $deserialized = $instance; -# } -# -# return $deserialized; -#} - -1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm index 3582520cd5c..a8a52ae48ad 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -253,10 +253,10 @@ sub new { # query params if ( exists $args->{'username'}) { - $query_params->{'username'} = WWW::SwaggerClient::APIClient::to_query_value($args->{'username'}); + $query_params->{'username'} = WWW::::APIClient::to_query_value($args->{'username'}); } # query params if ( exists $args->{'password'}) { - $query_params->{'password'} = WWW::SwaggerClient::APIClient::to_query_value($args->{'password'}); + $query_params->{'password'} = WWW::::APIClient::to_query_value($args->{'password'}); } diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl index f415dc36c09..25ac786166c 100644 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -6,22 +6,22 @@ use strict; use warnings; use WWW::SwaggerClient::PetApi; use WWW::SwaggerClient::APIClient; -use WWW::SwaggerClient::Model::Pet; -use WWW::SwaggerClient::Model::Tag; -use WWW::SwaggerClient::Model::Category; +use WWW::SwaggerClient::Object::Pet; +use WWW::SwaggerClient::Object::Tag; +use WWW::SwaggerClient::Object::Category; use JSON; use Data::Dumper; my $api = WWW::SwaggerClient::PetApi->new(); -print WWW::SwaggerClient::APIClient::to_form_value('testing 123'); +#print WWW::SwaggerClient::APIClient::to_form_value('testing 123'); my $pet_id = 5; -my $tag = WWW::SwaggerClient::Model::Tag->new({'id' => 'tag1', 'name' => 'just kidding', +my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => 'tag1', 'name' => 'just kidding', "photoUrls" => ['123', 'oop']}); -my $pet = WWW::SwaggerClient::Model::Pet->new({'id' => 5, 'name' => 'haha', - "photoUrls" => ['123', 'oop'], 'tags' => [$tag]}); +my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => 5, 'name' => 'haha', + "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => '2003-04-05 02:58:00'}); ##print Dumper $pet; @@ -29,11 +29,9 @@ my $json = JSON->new->convert_blessed; #print $json->convert_blessed->encode($pet); #print $json->get_convert_blessed; -##print Dumper($pet->to_hash); - - +print Dumper($pet->to_hash); #my $pet2 = WWW::SwaggerClient::Model::Pet->from_json($pet->to_hash); -my $pet2 = WWW::SwaggerClient::Model::Pet->new(); +my $pet2 = WWW::SwaggerClient::Object::Pet->new(); $pet2 = $pet2->from_hash($pet->to_hash); #$pet2->from_json($pet->to_hash); ##print Dumper($pet2->to_hash); From f69fb40c71bd5c432a359b7dd59083ade779ecba Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 7 May 2015 14:41:58 +0800 Subject: [PATCH 06/11] add methods for static variable --- .../main/resources/perl/BaseObject.mustache | 10 +-- .../src/main/resources/perl/object.mustache | 61 +++---------------- .../WWW/SwaggerClient/Object/BaseObject.pm | 10 +-- .../lib/WWW/SwaggerClient/Object/Category.pm | 57 ++--------------- .../lib/WWW/SwaggerClient/Object/Order.pm | 57 ++--------------- .../perl/lib/WWW/SwaggerClient/Object/Pet.pm | 57 ++--------------- .../perl/lib/WWW/SwaggerClient/Object/Tag.pm | 57 ++--------------- .../perl/lib/WWW/SwaggerClient/Object/User.pm | 57 ++--------------- samples/client/petstore/perl/test.pl | 22 ++++++- 9 files changed, 67 insertions(+), 321 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache index be8937a16f0..4a0be0aaea0 100644 --- a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -28,9 +28,9 @@ sub to_hash { sub TO_JSON { my $self = shift; my $_data = {}; - foreach my $_key (keys $self->{attribute_map}) { - if (defined $self->{$self->{attribute_map}->{$_key}}) { - $_data->{$self->{attribute_map}->{$_key}} = $self->{$_key}; + foreach my $_key (keys $self->get_attribute_map) { + if (defined $self->{$self->get_attribute_map->{$_key}}) { + $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; } } return $_data; @@ -40,11 +40,11 @@ sub TO_JSON { sub from_hash { my ($self, $hash) = @_; # loop through attributes and use swagger_types to deserialize the data - while ( my ($_key, $_type) = each $self->{swagger_types}) { + 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->{attribute_map}->{$_key}}}) { + foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) { push @_array, $self->_deserialize($_subclass, $_element); } $self->{$_key} = \@_array; diff --git a/modules/swagger-codegen/src/main/resources/perl/object.mustache b/modules/swagger-codegen/src/main/resources/perl/object.mustache index 73b2e749ea3..34e504819a0 100644 --- a/modules/swagger-codegen/src/main/resources/perl/object.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/object.mustache @@ -43,61 +43,16 @@ sub new { return bless $self, $class; } -# return json string -sub to_hash { - return decode_json(JSON->new->convert_blessed->encode( shift )); +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; } -# used by JSON for serialization -sub TO_JSON { - my $self = shift; - my $_data = {}; - foreach my $_key (keys $attribute_map) { - if (defined $self->{$attribute_map->{$_key}}) { - $_data->{$attribute_map->{$_key}} = $self->{$_key}; - } - } - return $_data; +# get attribute mappping +sub get_attribute_map { + return $attribute_map; } -# 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 $swagger_types) { - if ($_type =~ /^array\[/i) { # array - my $_subclass = substr($_type, 6, -1); - my @_array = (); - foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { - return $data; - } else { # hash(model) - my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()"; - return $_instance->from_hash($data); - } -} - -{{/model}} -{{/models}} - 1; +{{/model}} +{{/models}} diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm index 276b3f46f0f..584710238ad 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm @@ -28,9 +28,9 @@ sub to_hash { sub TO_JSON { my $self = shift; my $_data = {}; - foreach my $_key (keys $self->{attribute_map}) { - if (defined $self->{$self->{attribute_map}->{$_key}}) { - $_data->{$self->{attribute_map}->{$_key}} = $self->{$_key}; + foreach my $_key (keys $self->get_attribute_map) { + if (defined $self->{$self->get_attribute_map->{$_key}}) { + $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; } } return $_data; @@ -40,11 +40,11 @@ sub TO_JSON { sub from_hash { my ($self, $hash) = @_; # loop through attributes and use swagger_types to deserialize the data - while ( my ($_key, $_type) = each $self->{swagger_types}) { + 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->{attribute_map}->{$_key}}}) { + foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) { push @_array, $self->_deserialize($_subclass, $_element); } $self->{$_key} = \@_array; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm index b82bd5f82a2..2ae61e3a7fa 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm @@ -42,59 +42,14 @@ sub new { return bless $self, $class; } -# return json string -sub to_hash { - return decode_json(JSON->new->convert_blessed->encode( shift )); +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; } -# used by JSON for serialization -sub TO_JSON { - my $self = shift; - my $_data = {}; - foreach my $_key (keys $attribute_map) { - if (defined $self->{$attribute_map->{$_key}}) { - $_data->{$attribute_map->{$_key}} = $self->{$_key}; - } - } - return $_data; +# get attribute mappping +sub get_attribute_map { + return $attribute_map; } -# 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 $swagger_types) { - if ($_type =~ /^array\[/i) { # array - my $_subclass = substr($_type, 6, -1); - my @_array = (); - foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { - 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/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm index 35a6e96fac8..5693ecd2177 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm @@ -58,59 +58,14 @@ sub new { return bless $self, $class; } -# return json string -sub to_hash { - return decode_json(JSON->new->convert_blessed->encode( shift )); +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; } -# used by JSON for serialization -sub TO_JSON { - my $self = shift; - my $_data = {}; - foreach my $_key (keys $attribute_map) { - if (defined $self->{$attribute_map->{$_key}}) { - $_data->{$attribute_map->{$_key}} = $self->{$_key}; - } - } - return $_data; +# get attribute mappping +sub get_attribute_map { + return $attribute_map; } -# 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 $swagger_types) { - if ($_type =~ /^array\[/i) { # array - my $_subclass = substr($_type, 6, -1); - my @_array = (); - foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { - 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/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm index 1e692d7bb51..6c31afb5b91 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm @@ -58,59 +58,14 @@ sub new { return bless $self, $class; } -# return json string -sub to_hash { - return decode_json(JSON->new->convert_blessed->encode( shift )); +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; } -# used by JSON for serialization -sub TO_JSON { - my $self = shift; - my $_data = {}; - foreach my $_key (keys $attribute_map) { - if (defined $self->{$attribute_map->{$_key}}) { - $_data->{$attribute_map->{$_key}} = $self->{$_key}; - } - } - return $_data; +# get attribute mappping +sub get_attribute_map { + return $attribute_map; } -# 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 $swagger_types) { - if ($_type =~ /^array\[/i) { # array - my $_subclass = substr($_type, 6, -1); - my @_array = (); - foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { - 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/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm index b46b44927f8..45c570a7506 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm @@ -42,59 +42,14 @@ sub new { return bless $self, $class; } -# return json string -sub to_hash { - return decode_json(JSON->new->convert_blessed->encode( shift )); +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; } -# used by JSON for serialization -sub TO_JSON { - my $self = shift; - my $_data = {}; - foreach my $_key (keys $attribute_map) { - if (defined $self->{$attribute_map->{$_key}}) { - $_data->{$attribute_map->{$_key}} = $self->{$_key}; - } - } - return $_data; +# get attribute mappping +sub get_attribute_map { + return $attribute_map; } -# 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 $swagger_types) { - if ($_type =~ /^array\[/i) { # array - my $_subclass = substr($_type, 6, -1); - my @_array = (); - foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { - 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/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm index 08d9ff6b080..f5d7c1dbce2 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm @@ -66,59 +66,14 @@ sub new { return bless $self, $class; } -# return json string -sub to_hash { - return decode_json(JSON->new->convert_blessed->encode( shift )); +# get swagger type of the attribute +sub get_swagger_types { + return $swagger_types; } -# used by JSON for serialization -sub TO_JSON { - my $self = shift; - my $_data = {}; - foreach my $_key (keys $attribute_map) { - if (defined $self->{$attribute_map->{$_key}}) { - $_data->{$attribute_map->{$_key}} = $self->{$_key}; - } - } - return $_data; +# get attribute mappping +sub get_attribute_map { + return $attribute_map; } -# 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 $swagger_types) { - if ($_type =~ /^array\[/i) { # array - my $_subclass = substr($_type, 6, -1); - my @_array = (); - foreach my $_element (@{$hash->{$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$/, ('string', 'int', 'float', 'bool')) ) { - 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/test.pl b/samples/client/petstore/perl/test.pl index 25ac786166c..ed7dff0b33c 100644 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -11,20 +11,35 @@ use WWW::SwaggerClient::Object::Tag; use WWW::SwaggerClient::Object::Category; use JSON; use Data::Dumper; +use DateTime; my $api = WWW::SwaggerClient::PetApi->new(); #print WWW::SwaggerClient::APIClient::to_form_value('testing 123'); my $pet_id = 5; +my $dt = DateTime->new( + year => 1972, + month => 12, + day => 31, + hour => 23, + minute => 59, + second => 30, + time_zone => 'UTC' +); + +print "dt = $dt\n"; +print "dt = ".$dt->datetime()."\n"; + my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => 'tag1', 'name' => 'just kidding', "photoUrls" => ['123', 'oop']}); my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => 5, 'name' => 'haha', - "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => '2003-04-05 02:58:00'}); + "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => $dt}); ##print Dumper $pet; - +print "pet ref=".ref($pet)."\n"; +print "tag ref=".ref($tag)."\n"; my $json = JSON->new->convert_blessed; #print $json->convert_blessed->encode($pet); @@ -34,7 +49,8 @@ print Dumper($pet->to_hash); my $pet2 = WWW::SwaggerClient::Object::Pet->new(); $pet2 = $pet2->from_hash($pet->to_hash); #$pet2->from_json($pet->to_hash); -##print Dumper($pet2->to_hash); +print Dumper($pet2->to_hash); +#exit; print "============================\n"; print Dumper $api->get_pet_by_id({pet_id => $pet_id}); print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'}); From 48844442fc4a604b24ebf16487519f864f6ebedf Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 7 May 2015 15:46:43 +0800 Subject: [PATCH 07/11] test post body (model), fix to_hash attribute mapping --- .../main/resources/perl/APIClient.mustache | 15 +++++++++--- .../main/resources/perl/BaseObject.mustache | 2 +- .../perl/lib/WWW/SwaggerClient/APIClient.pm | 15 +++++++++--- .../WWW/SwaggerClient/Object/BaseObject.pm | 2 +- samples/client/petstore/perl/test.pl | 23 +++++++++++-------- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache index 44d5b60b21e..04f0a006356 100644 --- a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache @@ -75,15 +75,24 @@ sub call_api { } # body data - my $_body_data = $post_params ? $post_params : $body_data; + my $_body_data = %$post_params ? $post_params : to_json($body_data->to_hash); # Make the HTTP request my $_request; switch ($method) { case 'POST' { - #TODO: multipart + # 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 => $header_params->{'Content-Type'}, Content => $_body_data); + 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'}, diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache index 4a0be0aaea0..9fab6611593 100644 --- a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -29,7 +29,7 @@ sub TO_JSON { my $self = shift; my $_data = {}; foreach my $_key (keys $self->get_attribute_map) { - if (defined $self->{$self->get_attribute_map->{$_key}}) { + if (defined $self->{$_key}) { $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; } } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm index 18246004781..577bd23003f 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -75,15 +75,24 @@ sub call_api { } # body data - my $_body_data = $post_params ? $post_params : $body_data; + my $_body_data = %$post_params ? $post_params : to_json($body_data->to_hash); # Make the HTTP request my $_request; switch ($method) { case 'POST' { - #TODO: multipart + # 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 => $header_params->{'Content-Type'}, Content => $_body_data); + 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'}, diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm index 584710238ad..a5be613d472 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm @@ -29,7 +29,7 @@ sub TO_JSON { my $self = shift; my $_data = {}; foreach my $_key (keys $self->get_attribute_map) { - if (defined $self->{$self->get_attribute_map->{$_key}}) { + if (defined $self->{$_key}) { $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; } } diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl index ed7dff0b33c..3fb7c3e0a08 100644 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -17,7 +17,7 @@ my $api = WWW::SwaggerClient::PetApi->new(); #print WWW::SwaggerClient::APIClient::to_form_value('testing 123'); -my $pet_id = 5; +my $pet_id = 88; my $dt = DateTime->new( year => 1972, month => 12, @@ -32,14 +32,13 @@ print "dt = $dt\n"; print "dt = ".$dt->datetime()."\n"; -my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => 'tag1', 'name' => 'just kidding', +my $category = WWW::SwaggerClient::Object::Category->new({'id' => '2', 'name' => 'pending'}); +my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => '1', 'name' => 'just kidding', "photoUrls" => ['123', 'oop']}); -my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => 5, 'name' => 'haha', - "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => $dt}); +my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => $pet_id, 'name' => 'perl test', + "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'status' => 'pending'}); -##print Dumper $pet; -print "pet ref=".ref($pet)."\n"; -print "tag ref=".ref($tag)."\n"; +print Dumper $pet; my $json = JSON->new->convert_blessed; #print $json->convert_blessed->encode($pet); @@ -52,5 +51,11 @@ $pet2 = $pet2->from_hash($pet->to_hash); print Dumper($pet2->to_hash); #exit; print "============================\n"; -print Dumper $api->get_pet_by_id({pet_id => $pet_id}); -print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'}); +print Dumper $api->add_pet({body => $pet}); +#print Dumper $api->get_pet_by_id({pet_id => $pet_id}); +#print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'}); +#print Dumper $api->delete_pet({pet_id => $pet_id}); + + + + From c03250132d9d325217d681bcbea3560ec8b60784 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 7 May 2015 18:01:56 +0800 Subject: [PATCH 08/11] update error message, update test script --- .../main/resources/perl/APIClient.mustache | 21 +++++--- .../src/main/resources/perl/api.mustache | 6 ++- samples/client/petstore/perl/http.pl | 25 ---------- .../perl/lib/WWW/SwaggerClient/APIClient.pm | 21 +++++--- .../perl/lib/WWW/SwaggerClient/PetApi.pm | 11 +++- samples/client/petstore/perl/test.pl | 50 ++++++------------- 6 files changed, 60 insertions(+), 74 deletions(-) delete mode 100644 samples/client/petstore/perl/http.pl diff --git a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache index 04f0a006356..b0c3c9b5d39 100644 --- a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache @@ -7,7 +7,7 @@ use utf8; use LWP::UserAgent; use HTTP::Headers; use HTTP::Response; -use HTTP::Request::Common; +use HTTP::Request::Common qw(DELETE POST GET HEAD PUT); use HTTP::Status; use URI::Query; use JSON; @@ -75,7 +75,8 @@ sub call_api { } # body data - my $_body_data = %$post_params ? $post_params : to_json($body_data->to_hash); + $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; @@ -84,6 +85,7 @@ sub call_api { # 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); } @@ -98,9 +100,17 @@ sub call_api { $_request = GET($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}); } - case 'PUT' { - + 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); @@ -109,8 +119,7 @@ sub call_api { my $_response = $ua->request($_request); unless ($_response->is_success) { - croak("Can't connect to the server"); - #croak("Can't connect to the api ($_response{code}): $_response{message}"); + croak("API Exception(".$_response->code."): ".$_response->message); } return $_response->content; diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache index 7eb16b8a1a5..25c0d80fb95 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -112,7 +112,11 @@ sub new { }{{/pathParams}} {{#formParams}} # form params if ( exists $args->{'{{paramName}}'} ) { - $form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}WWW::{{invokerPackage}}::APIClient::to_form_value($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 diff --git a/samples/client/petstore/perl/http.pl b/samples/client/petstore/perl/http.pl deleted file mode 100644 index 282b06ba3e5..00000000000 --- a/samples/client/petstore/perl/http.pl +++ /dev/null @@ -1,25 +0,0 @@ -use LWP::UserAgent; - -my $ua = LWP::UserAgent->new; - -my $server_endpoint = "http://petstore.swagger.io/v2/pet/10002"; - -# set custom HTTP request header fields -my $req = HTTP::Request->new(GET => $server_endpoint); -$req->header('content-type' => 'application/json'); - -use Data::Dumper; -print Dumper($req); - -my $resp = $ua->request($req); -if ($resp->is_success) { - my $message = $resp->decoded_content; - print "Received reply: $message\n"; -} -else { - print "HTTP GET error code: ", $resp->code, "\n"; - print "HTTP GET error message: ", $resp->message, "\n"; -} - - - diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm index 577bd23003f..6d0ecc44dc6 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -7,7 +7,7 @@ use utf8; use LWP::UserAgent; use HTTP::Headers; use HTTP::Response; -use HTTP::Request::Common; +use HTTP::Request::Common qw(DELETE POST GET HEAD PUT); use HTTP::Status; use URI::Query; use JSON; @@ -75,7 +75,8 @@ sub call_api { } # body data - my $_body_data = %$post_params ? $post_params : to_json($body_data->to_hash); + $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; @@ -84,6 +85,7 @@ sub call_api { # 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); } @@ -98,9 +100,17 @@ sub call_api { $_request = GET($_url, Accept => $header_params->{'Accept'}, Content_Type => $header_params->{'Content-Type'}); } - case 'PUT' { - + 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); @@ -109,8 +119,7 @@ sub call_api { my $_response = $ua->request($_request); unless ($_response->is_success) { - croak("Can't connect to the server"); - #croak("Can't connect to the api ($_response{code}): $_response{message}"); + croak("API Exception(".$_response->code."): ".$_response->message); } return $_response->content; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index 8b02083e637..bd7c0b5fc6b 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -385,10 +385,14 @@ sub new { } # 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; @@ -513,10 +517,15 @@ sub new { } # 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'} = '@' . WWW::SwaggerClient::APIClient::to_form_value($args->{'file'}); + $form_params->{'file'} = [] unless defined $form_params->{'file'}; + push $form_params->{'file'}, $args->{'file'}; + + } my $_body_data; diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl index 3fb7c3e0a08..504461710cd 100644 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # # - +use lib 'lib'; use strict; use warnings; use WWW::SwaggerClient::PetApi; @@ -15,46 +15,26 @@ use DateTime; my $api = WWW::SwaggerClient::PetApi->new(); -#print WWW::SwaggerClient::APIClient::to_form_value('testing 123'); - my $pet_id = 88; -my $dt = DateTime->new( - year => 1972, - month => 12, - day => 31, - hour => 23, - minute => 59, - second => 30, - time_zone => 'UTC' -); -print "dt = $dt\n"; -print "dt = ".$dt->datetime()."\n"; - - -my $category = WWW::SwaggerClient::Object::Category->new({'id' => '2', 'name' => 'pending'}); -my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => '1', 'name' => 'just kidding', - "photoUrls" => ['123', 'oop']}); +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'}); + "photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'status' => 'pending', 'category' => $category}); -print Dumper $pet; +print "\npet(object)=".Dumper $pet; my $json = JSON->new->convert_blessed; -#print $json->convert_blessed->encode($pet); -#print $json->get_convert_blessed; -print Dumper($pet->to_hash); -#my $pet2 = WWW::SwaggerClient::Model::Pet->from_json($pet->to_hash); -my $pet2 = WWW::SwaggerClient::Object::Pet->new(); -$pet2 = $pet2->from_hash($pet->to_hash); -#$pet2->from_json($pet->to_hash); -print Dumper($pet2->to_hash); -#exit; -print "============================\n"; -print Dumper $api->add_pet({body => $pet}); -#print Dumper $api->get_pet_by_id({pet_id => $pet_id}); -#print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'}); -#print Dumper $api->delete_pet({pet_id => $pet_id}); +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 => '/var/tmp/f5.jpg'}); +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}); From 1d4735f76d973b78538184448e6aaacc3c94c981 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 7 May 2015 20:49:35 +0800 Subject: [PATCH 09/11] update subroutine argument --- .../src/main/resources/perl/api.mustache | 48 +++++---- .../src/main/resources/perl/object.mustache | 4 +- .../lib/WWW/SwaggerClient/Object/Category.pm | 6 +- .../lib/WWW/SwaggerClient/Object/Order.pm | 14 +-- .../perl/lib/WWW/SwaggerClient/Object/Pet.pm | 14 +-- .../perl/lib/WWW/SwaggerClient/Object/Tag.pm | 6 +- .../perl/lib/WWW/SwaggerClient/Object/User.pm | 18 ++-- .../perl/lib/WWW/SwaggerClient/PetApi.pm | 98 +++++++++---------- .../perl/lib/WWW/SwaggerClient/StoreApi.pm | 46 ++++----- .../perl/lib/WWW/SwaggerClient/UserApi.pm | 80 +++++++-------- samples/client/petstore/perl/test.pl | 18 ++-- 11 files changed, 168 insertions(+), 184 deletions(-) mode change 100644 => 100755 samples/client/petstore/perl/test.pl diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache index 25c0d80fb95..7b7d9d98a4e 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -43,21 +43,17 @@ our @EXPORT_OK = qw( sub new { my $class = shift; my $default_api_client = WWW::{{invokerPackage}}::APIClient->new; - #TODO fix default - #my (%arg) = ( - # 'api_client' => $default_api_client, - # @_ - #); + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); - #croak("You must supply an API client") - # unless $options->{api_client}; + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; - my $self = { - #api_client => $options->{api_client} - api_client => $default_api_client - }; - - bless $self, $class; + bless \%self, $class; } @@ -71,11 +67,11 @@ sub new { {{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} # sub {{nickname}} { - my ($self, $args) = @_; + my ($self, %args) = @_; {{#allParams}}{{#required}} # verify the required parameter '{{paramName}}' is set - unless (exists $args->{'{{paramName}}'}) { + unless (exists $args{'{{paramName}}'}) { croak("Missing the required parameter '{{paramName}}' when calling {{nickname}}"); } {{/required}}{{/allParams}} @@ -97,31 +93,31 @@ sub new { $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}}'}); + 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}}'}); + if ( exists $args{'{{paramName}}'}) { + $header_params->{'{{baseName}}'} = WWW::{{invokerPackage}}::APIClient::to_header_value($args{'{{paramName}}'}); }{{/headerParams}} {{#pathParams}} # path params - if ( exists $args->{'{{paramName}}'}) { + if ( exists $args{'{{paramName}}'}) { my $_base_variable = "{" . "{{baseName}}" . "}"; - my $_base_value = WWW::{{invokerPackage}}::APIClient::to_path_value($args->{'{{paramName}}'}); + 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}}'} ) { + if ( exists $args{'{{paramName}}'} ) { {{#isFile}}$form_params->{'{{baseName}}'} = [] unless defined $form_params->{'{{baseName}}'}; - push $form_params->{'{{baseName}}'}, $args->{'{{paramName}}'}; + push $form_params->{'{{baseName}}'}, $args{'{{paramName}}'}; {{/isFile}} - {{^isFile}}$form_params->{'{{baseName}}'} = WWW::{{invokerPackage}}::APIClient::to_form_value($args->{'{{paramName}}'}); + {{^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}}'}; + if ( exists $args{'{{paramName}}'}) { + $_body_data = $args{'{{paramName}}'}; }{{/bodyParams}} # for HTTP post (form) diff --git a/modules/swagger-codegen/src/main/resources/perl/object.mustache b/modules/swagger-codegen/src/main/resources/perl/object.mustache index 34e504819a0..c527957a9b1 100644 --- a/modules/swagger-codegen/src/main/resources/perl/object.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/object.mustache @@ -33,10 +33,10 @@ my $attribute_map = { # new object sub new { - my ($class, $args) = @_; + my ($class, %args) = @_; my $self = { {{#vars}}#{{#description}}{{{description}}}{{/description}} - '{{name}}' => $args->{'{{baseName}}'}{{#hasMore}}, + '{{name}}' => $args{'{{baseName}}'}{{#hasMore}}, {{/hasMore}}{{/vars}} }; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm index 2ae61e3a7fa..857dccdce5a 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm @@ -31,12 +31,12 @@ my $attribute_map = { # new object sub new { - my ($class, $args) = @_; + my ($class, %args) = @_; my $self = { # - 'id' => $args->{'id'}, + 'id' => $args{'id'}, # - 'name' => $args->{'name'} + 'name' => $args{'name'} }; return bless $self, $class; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm index 5693ecd2177..35449647e13 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm @@ -39,20 +39,20 @@ my $attribute_map = { # new object sub new { - my ($class, $args) = @_; + my ($class, %args) = @_; my $self = { # - 'id' => $args->{'id'}, + 'id' => $args{'id'}, # - 'pet_id' => $args->{'petId'}, + 'pet_id' => $args{'petId'}, # - 'quantity' => $args->{'quantity'}, + 'quantity' => $args{'quantity'}, # - 'ship_date' => $args->{'shipDate'}, + 'ship_date' => $args{'shipDate'}, #Order Status - 'status' => $args->{'status'}, + 'status' => $args{'status'}, # - 'complete' => $args->{'complete'} + 'complete' => $args{'complete'} }; return bless $self, $class; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm index 6c31afb5b91..f53aacdf0d3 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm @@ -39,20 +39,20 @@ my $attribute_map = { # new object sub new { - my ($class, $args) = @_; + my ($class, %args) = @_; my $self = { # - 'id' => $args->{'id'}, + 'id' => $args{'id'}, # - 'category' => $args->{'category'}, + 'category' => $args{'category'}, # - 'name' => $args->{'name'}, + 'name' => $args{'name'}, # - 'photo_urls' => $args->{'photoUrls'}, + 'photo_urls' => $args{'photoUrls'}, # - 'tags' => $args->{'tags'}, + 'tags' => $args{'tags'}, #pet status in the store - 'status' => $args->{'status'} + 'status' => $args{'status'} }; return bless $self, $class; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm index 45c570a7506..35850032d5c 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm @@ -31,12 +31,12 @@ my $attribute_map = { # new object sub new { - my ($class, $args) = @_; + my ($class, %args) = @_; my $self = { # - 'id' => $args->{'id'}, + 'id' => $args{'id'}, # - 'name' => $args->{'name'} + 'name' => $args{'name'} }; return bless $self, $class; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm index f5d7c1dbce2..88a396ece3a 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm @@ -43,24 +43,24 @@ my $attribute_map = { # new object sub new { - my ($class, $args) = @_; + my ($class, %args) = @_; my $self = { # - 'id' => $args->{'id'}, + 'id' => $args{'id'}, # - 'username' => $args->{'username'}, + 'username' => $args{'username'}, # - 'first_name' => $args->{'firstName'}, + 'first_name' => $args{'firstName'}, # - 'last_name' => $args->{'lastName'}, + 'last_name' => $args{'lastName'}, # - 'email' => $args->{'email'}, + 'email' => $args{'email'}, # - 'password' => $args->{'password'}, + 'password' => $args{'password'}, # - 'phone' => $args->{'phone'}, + 'phone' => $args{'phone'}, #User Status - 'user_status' => $args->{'userStatus'} + 'user_status' => $args{'userStatus'} }; return bless $self, $class; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index bd7c0b5fc6b..9dbceba4291 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -49,21 +49,17 @@ our @EXPORT_OK = qw( sub new { my $class = shift; my $default_api_client = WWW::SwaggerClient::APIClient->new; - #TODO fix default - #my (%arg) = ( - # 'api_client' => $default_api_client, - # @_ - #); + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); - #croak("You must supply an API client") - # unless $options->{api_client}; + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; - my $self = { - #api_client => $options->{api_client} - api_client => $default_api_client - }; - - bless $self, $class; + bless \%self, $class; } @@ -77,7 +73,7 @@ sub new { # @return void # sub update_pet { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -103,8 +99,8 @@ sub new { my $_body_data; # body params - if ( exists $args->{'body'}) { - $_body_data = $args->{'body'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -128,7 +124,7 @@ sub new { # @return void # sub add_pet { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -154,8 +150,8 @@ sub new { my $_body_data; # body params - if ( exists $args->{'body'}) { - $_body_data = $args->{'body'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -179,7 +175,7 @@ sub new { # @return array[Pet] # sub find_pets_by_status { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -200,8 +196,8 @@ sub new { $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'}); + if ( exists $args{'status'}) { + $query_params->{'status'} = WWW::::APIClient::to_query_value($args{'status'}); } @@ -233,7 +229,7 @@ sub new { # @return array[Pet] # sub find_pets_by_tags { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -254,8 +250,8 @@ sub new { $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'}); + if ( exists $args{'tags'}) { + $query_params->{'tags'} = WWW::::APIClient::to_query_value($args{'tags'}); } @@ -287,11 +283,11 @@ sub new { # @return Pet # sub get_pet_by_id { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'pet_id' is set - unless (exists $args->{'pet_id'}) { + unless (exists $args{'pet_id'}) { croak("Missing the required parameter 'pet_id' when calling get_pet_by_id"); } @@ -315,9 +311,9 @@ sub new { # path params - if ( exists $args->{'pet_id'}) { + if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'pet_id'}); + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } @@ -350,11 +346,11 @@ sub new { # @return void # sub update_pet_with_form { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'pet_id' is set - unless (exists $args->{'pet_id'}) { + unless (exists $args{'pet_id'}) { croak("Missing the required parameter 'pet_id' when calling update_pet_with_form"); } @@ -378,20 +374,20 @@ sub new { # path params - if ( exists $args->{'pet_id'}) { + if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'pet_id'}); + 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'} ) { + if ( exists $args{'name'} ) { - $form_params->{'name'} = WWW::SwaggerClient::APIClient::to_form_value($args->{'name'}); + $form_params->{'name'} = WWW::SwaggerClient::APIClient::to_form_value($args{'name'}); } # form params - if ( exists $args->{'status'} ) { + if ( exists $args{'status'} ) { - $form_params->{'status'} = WWW::SwaggerClient::APIClient::to_form_value($args->{'status'}); + $form_params->{'status'} = WWW::SwaggerClient::APIClient::to_form_value($args{'status'}); } my $_body_data; @@ -419,11 +415,11 @@ sub new { # @return void # sub delete_pet { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'pet_id' is set - unless (exists $args->{'pet_id'}) { + unless (exists $args{'pet_id'}) { croak("Missing the required parameter 'pet_id' when calling delete_pet"); } @@ -446,13 +442,13 @@ sub new { # header params - if ( exists $args->{'api_key'}) { - $header_params->{'api_key'} = WWW::SwaggerClient::APIClient::to_header_value($args->{'api_key'}); + 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'}) { + if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'pet_id'}); + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'pet_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } @@ -482,11 +478,11 @@ sub new { # @return void # sub upload_file { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'pet_id' is set - unless (exists $args->{'pet_id'}) { + unless (exists $args{'pet_id'}) { croak("Missing the required parameter 'pet_id' when calling upload_file"); } @@ -510,20 +506,20 @@ sub new { # path params - if ( exists $args->{'pet_id'}) { + if ( exists $args{'pet_id'}) { my $_base_variable = "{" . "petId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'pet_id'}); + 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'} ) { + if ( exists $args{'additional_metadata'} ) { - $form_params->{'additionalMetadata'} = WWW::SwaggerClient::APIClient::to_form_value($args->{'additional_metadata'}); + $form_params->{'additionalMetadata'} = WWW::SwaggerClient::APIClient::to_form_value($args{'additional_metadata'}); } # form params - if ( exists $args->{'file'} ) { + if ( exists $args{'file'} ) { $form_params->{'file'} = [] unless defined $form_params->{'file'}; - push $form_params->{'file'}, $args->{'file'}; + push $form_params->{'file'}, $args{'file'}; } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm index eaf819a16d0..6ef68489325 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm @@ -45,21 +45,17 @@ our @EXPORT_OK = qw( sub new { my $class = shift; my $default_api_client = WWW::SwaggerClient::APIClient->new; - #TODO fix default - #my (%arg) = ( - # 'api_client' => $default_api_client, - # @_ - #); + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); - #croak("You must supply an API client") - # unless $options->{api_client}; + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; - my $self = { - #api_client => $options->{api_client} - api_client => $default_api_client - }; - - bless $self, $class; + bless \%self, $class; } @@ -72,7 +68,7 @@ sub new { # @return map[string,int] # sub get_inventory { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -123,7 +119,7 @@ sub new { # @return Order # sub place_order { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -149,8 +145,8 @@ sub new { my $_body_data; # body params - if ( exists $args->{'body'}) { - $_body_data = $args->{'body'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -177,11 +173,11 @@ sub new { # @return Order # sub get_order_by_id { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'order_id' is set - unless (exists $args->{'order_id'}) { + unless (exists $args{'order_id'}) { croak("Missing the required parameter 'order_id' when calling get_order_by_id"); } @@ -205,9 +201,9 @@ sub new { # path params - if ( exists $args->{'order_id'}) { + if ( exists $args{'order_id'}) { my $_base_variable = "{" . "orderId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'order_id'}); + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'order_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } @@ -238,11 +234,11 @@ sub new { # @return void # sub delete_order { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'order_id' is set - unless (exists $args->{'order_id'}) { + unless (exists $args{'order_id'}) { croak("Missing the required parameter 'order_id' when calling delete_order"); } @@ -266,9 +262,9 @@ sub new { # path params - if ( exists $args->{'order_id'}) { + if ( exists $args{'order_id'}) { my $_base_variable = "{" . "orderId" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'order_id'}); + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'order_id'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm index a8a52ae48ad..a3955b7d4f8 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -49,21 +49,17 @@ our @EXPORT_OK = qw( sub new { my $class = shift; my $default_api_client = WWW::SwaggerClient::APIClient->new; - #TODO fix default - #my (%arg) = ( - # 'api_client' => $default_api_client, - # @_ - #); + my (%self) = ( + 'api_client' => $default_api_client, + @_ + ); - #croak("You must supply an API client") - # unless $options->{api_client}; + #my $self = { + # #api_client => $options->{api_client} + # api_client => $default_api_client + #}; - my $self = { - #api_client => $options->{api_client} - api_client => $default_api_client - }; - - bless $self, $class; + bless \%self, $class; } @@ -77,7 +73,7 @@ sub new { # @return void # sub create_user { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -103,8 +99,8 @@ sub new { my $_body_data; # body params - if ( exists $args->{'body'}) { - $_body_data = $args->{'body'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -128,7 +124,7 @@ sub new { # @return void # sub create_users_with_array_input { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -154,8 +150,8 @@ sub new { my $_body_data; # body params - if ( exists $args->{'body'}) { - $_body_data = $args->{'body'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -179,7 +175,7 @@ sub new { # @return void # sub create_users_with_list_input { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -205,8 +201,8 @@ sub new { my $_body_data; # body params - if ( exists $args->{'body'}) { - $_body_data = $args->{'body'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -231,7 +227,7 @@ sub new { # @return string # sub login_user { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -252,11 +248,11 @@ sub new { $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'}); + 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'}); + if ( exists $args{'password'}) { + $query_params->{'password'} = WWW::::APIClient::to_query_value($args{'password'}); } @@ -287,7 +283,7 @@ sub new { # @return void # sub logout_user { - my ($self, $args) = @_; + my ($self, %args) = @_; @@ -335,11 +331,11 @@ sub new { # @return User # sub get_user_by_name { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'username' is set - unless (exists $args->{'username'}) { + unless (exists $args{'username'}) { croak("Missing the required parameter 'username' when calling get_user_by_name"); } @@ -363,9 +359,9 @@ sub new { # path params - if ( exists $args->{'username'}) { + if ( exists $args{'username'}) { my $_base_variable = "{" . "username" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'username'}); + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'username'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } @@ -397,11 +393,11 @@ sub new { # @return void # sub update_user { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'username' is set - unless (exists $args->{'username'}) { + unless (exists $args{'username'}) { croak("Missing the required parameter 'username' when calling update_user"); } @@ -425,16 +421,16 @@ sub new { # path params - if ( exists $args->{'username'}) { + if ( exists $args{'username'}) { my $_base_variable = "{" . "username" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'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'}; + if ( exists $args{'body'}) { + $_body_data = $args{'body'}; } # for HTTP post (form) @@ -458,11 +454,11 @@ sub new { # @return void # sub delete_user { - my ($self, $args) = @_; + my ($self, %args) = @_; # verify the required parameter 'username' is set - unless (exists $args->{'username'}) { + unless (exists $args{'username'}) { croak("Missing the required parameter 'username' when calling delete_user"); } @@ -486,9 +482,9 @@ sub new { # path params - if ( exists $args->{'username'}) { + if ( exists $args{'username'}) { my $_base_variable = "{" . "username" . "}"; - my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args->{'username'}); + my $_base_value = WWW::SwaggerClient::APIClient::to_path_value($args{'username'}); $_resource_path =~ s/$_base_variable/$_base_value/g; } diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl old mode 100644 new mode 100755 index 504461710cd..b92e4cfcff1 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -17,10 +17,10 @@ my $api = WWW::SwaggerClient::PetApi->new(); my $pet_id = 88; -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}); +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; @@ -30,11 +30,11 @@ $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 => '/var/tmp/f5.jpg'}); -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}); +print "\nupload_file:".Dumper $api->upload_file(pet_id => $pet_id, additional_metadata => 'testabc', file => '/var/tmp/f5.jpg'); +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); From 063a1ffd3645b2f593be3f60ea9d73565fc529c2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 7 May 2015 22:41:50 +0800 Subject: [PATCH 10/11] update type list in deserialize --- .../codegen/languages/PerlClientCodegen.java | 34 ++++++++++++++----- .../main/resources/perl/BaseObject.mustache | 2 +- .../WWW/SwaggerClient/Object/BaseObject.pm | 2 +- .../lib/WWW/SwaggerClient/Object/Category.pm | 2 +- .../lib/WWW/SwaggerClient/Object/Order.pm | 4 +-- .../perl/lib/WWW/SwaggerClient/Object/Pet.pm | 6 ++-- .../perl/lib/WWW/SwaggerClient/Object/Tag.pm | 2 +- .../perl/lib/WWW/SwaggerClient/Object/User.pm | 2 +- .../perl/lib/WWW/SwaggerClient/PetApi.pm | 18 +++++----- .../perl/lib/WWW/SwaggerClient/StoreApi.pm | 4 +-- .../perl/lib/WWW/SwaggerClient/UserApi.pm | 4 +-- samples/client/petstore/perl/test.pl | 2 -- 12 files changed, 49 insertions(+), 33 deletions(-) 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 4edead804d5..9062c2722d7 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 @@ -38,7 +38,17 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { reservedWords = new HashSet ( Arrays.asList( - "__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor") + "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); @@ -47,17 +57,25 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { additionalProperties.put("artifactVersion", artifactVersion); languageSpecificPrimitives.add("int"); - languageSpecificPrimitives.add("array"); - languageSpecificPrimitives.add("map"); + languageSpecificPrimitives.add("Math::BigInt"); + languageSpecificPrimitives.add("double"); languageSpecificPrimitives.add("string"); + languageSpecificPrimitives.add("boolean"); languageSpecificPrimitives.add("DateTime"); + languageSpecificPrimitives.add("ARRAY"); + languageSpecificPrimitives.add("HASH"); - typeMapping.put("long", "int"); typeMapping.put("integer", "int"); - typeMapping.put("Array", "array"); - typeMapping.put("String", "string"); - typeMapping.put("List", "array"); - typeMapping.put("map", "map"); + typeMapping.put("long", "Math::BigInt"); + 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")); diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache index 9fab6611593..7ae05c07585 100644 --- a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -65,7 +65,7 @@ sub _deserialize { if ($type eq 'DateTime') { return DateTime->from_epoch(epoch => str2time($data)); - } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { + } elsif ( grep( /^$type$/, ('int', 'Math::BigInt', 'double', 'string', 'boolean'))) { return $data; } else { # hash(model) my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()"; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm index a5be613d472..d1146ec4536 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm @@ -65,7 +65,7 @@ sub _deserialize { if ($type eq 'DateTime') { return DateTime->from_epoch(epoch => str2time($data)); - } elsif ( grep( /^$type$/, ('string', 'int', 'float', 'bool')) ) { + } elsif ( grep( /^$type$/, ('int', 'Math::BigInt', 'double', 'string', 'boolean'))) { return $data; } else { # hash(model) my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm index 857dccdce5a..d72dc2c78c7 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'int', + 'id' => 'Math::BigInt', 'name' => 'string' }; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm index 35449647e13..d76d03d8d3b 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm @@ -20,8 +20,8 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'int', - 'pet_id' => 'int', + 'id' => 'Math::BigInt', + 'pet_id' => 'Math::BigInt', 'quantity' => 'int', 'ship_date' => 'DateTime', 'status' => 'string', diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm index f53aacdf0d3..ddcc0793f23 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm @@ -20,11 +20,11 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'int', + 'id' => 'Math::BigInt', 'category' => 'Category', 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', + 'photo_urls' => 'ARRAY[string]', + 'tags' => 'ARRAY[Tag]', 'status' => 'string' }; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm index 35850032d5c..79f259340ba 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'int', + 'id' => 'Math::BigInt', 'name' => 'string' }; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm index 88a396ece3a..bc8971fb5e2 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'int', + 'id' => 'Math::BigInt', 'username' => 'string', 'first_name' => 'string', 'last_name' => 'string', diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index 9dbceba4291..b1985703ddd 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -171,8 +171,8 @@ sub new { # # Finds Pets by status # - # @param array[string] $status Status values that need to be considered for filter (required) - # @return array[Pet] + # @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) = @_; @@ -215,7 +215,7 @@ sub new { if (!$response) { return; } - my $_response_object = $self->{api_client}->deserialize('array[Pet]', $response); + my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response); return $_response_object; } @@ -225,8 +225,8 @@ sub new { # # Finds Pets by tags # - # @param array[string] $tags Tags to filter by (required) - # @return array[Pet] + # @param ARRAY[string] $tags Tags to filter by (required) + # @return ARRAY[Pet] # sub find_pets_by_tags { my ($self, %args) = @_; @@ -269,7 +269,7 @@ sub new { if (!$response) { return; } - my $_response_object = $self->{api_client}->deserialize('array[Pet]', $response); + my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response); return $_response_object; } @@ -279,7 +279,7 @@ sub new { # # Find pet by ID # - # @param int $pet_id ID of pet that needs to be fetched (required) + # @param Math::BigInt $pet_id ID of pet that needs to be fetched (required) # @return Pet # sub get_pet_by_id { @@ -411,7 +411,7 @@ sub new { # Deletes a pet # # @param string $api_key (required) - # @param int $pet_id Pet id to delete (required) + # @param Math::BigInt $pet_id Pet id to delete (required) # @return void # sub delete_pet { @@ -472,7 +472,7 @@ sub new { # # uploads an image # - # @param int $pet_id ID of pet to update (required) + # @param Math::BigInt $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 diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm index 6ef68489325..bb361d05a43 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm @@ -65,7 +65,7 @@ sub new { # # Returns pet inventories by status # - # @return map[string,int] + # @return HASH[string,int] # sub get_inventory { my ($self, %args) = @_; @@ -105,7 +105,7 @@ sub new { if (!$response) { return; } - my $_response_object = $self->{api_client}->deserialize('map[string,int]', $response); + my $_response_object = $self->{api_client}->deserialize('HASH[string,int]', $response); return $_response_object; } diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm index a3955b7d4f8..d3869b62555 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -120,7 +120,7 @@ sub new { # # Creates list of users with given input array # - # @param array[User] $body List of user object (required) + # @param ARRAY[User] $body List of user object (required) # @return void # sub create_users_with_array_input { @@ -171,7 +171,7 @@ sub new { # # Creates list of users with given input array # - # @param array[User] $body List of user object (required) + # @param ARRAY[User] $body List of user object (required) # @return void # sub create_users_with_list_input { diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl index b92e4cfcff1..2c545c7aac9 100755 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -37,5 +37,3 @@ print "\nupdate_pet_with_form:".Dumper $api->update_pet_with_form(pet_id => $pet print "\ndelete_pet:".Dumper $api->delete_pet(pet_id => $pet_id); - - From fc43828c20b4a002e016fe655af4d5e5243cb7dc Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 8 May 2015 03:56:35 +0800 Subject: [PATCH 11/11] update type mapping, update test.pl to use local file for testing upload --- .../swagger/codegen/languages/PerlClientCodegen.java | 3 +-- .../src/main/resources/perl/BaseObject.mustache | 2 +- .../perl/lib/WWW/SwaggerClient/Object/BaseObject.pm | 2 +- .../petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm | 2 +- .../petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm | 4 ++-- .../petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm | 2 +- .../petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm | 2 +- .../petstore/perl/lib/WWW/SwaggerClient/Object/User.pm | 2 +- .../client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm | 6 +++--- samples/client/petstore/perl/test.pl | 4 ++-- 10 files changed, 14 insertions(+), 15 deletions(-) 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 9062c2722d7..b25e4490e85 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 @@ -57,7 +57,6 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { additionalProperties.put("artifactVersion", artifactVersion); languageSpecificPrimitives.add("int"); - languageSpecificPrimitives.add("Math::BigInt"); languageSpecificPrimitives.add("double"); languageSpecificPrimitives.add("string"); languageSpecificPrimitives.add("boolean"); @@ -66,7 +65,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { languageSpecificPrimitives.add("HASH"); typeMapping.put("integer", "int"); - typeMapping.put("long", "Math::BigInt"); + typeMapping.put("long", "int"); typeMapping.put("float", "double"); typeMapping.put("double", "double"); typeMapping.put("boolean", "boolean"); diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache index 7ae05c07585..b4a7885a798 100644 --- a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -65,7 +65,7 @@ sub _deserialize { if ($type eq 'DateTime') { return DateTime->from_epoch(epoch => str2time($data)); - } elsif ( grep( /^$type$/, ('int', 'Math::BigInt', 'double', 'string', 'boolean'))) { + } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) { return $data; } else { # hash(model) my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()"; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm index d1146ec4536..c4fd4e6aece 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/BaseObject.pm @@ -65,7 +65,7 @@ sub _deserialize { if ($type eq 'DateTime') { return DateTime->from_epoch(epoch => str2time($data)); - } elsif ( grep( /^$type$/, ('int', 'Math::BigInt', 'double', 'string', 'boolean'))) { + } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) { return $data; } else { # hash(model) my $_instance = eval "WWW::SwaggerClient::Object::$type->new()"; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm index d72dc2c78c7..857dccdce5a 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Category.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'Math::BigInt', + 'id' => 'int', 'name' => 'string' }; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm index d76d03d8d3b..35449647e13 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Order.pm @@ -20,8 +20,8 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'Math::BigInt', - 'pet_id' => 'Math::BigInt', + 'id' => 'int', + 'pet_id' => 'int', 'quantity' => 'int', 'ship_date' => 'DateTime', 'status' => 'string', diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm index ddcc0793f23..df32665e826 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Pet.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'Math::BigInt', + 'id' => 'int', 'category' => 'Category', 'name' => 'string', 'photo_urls' => 'ARRAY[string]', diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm index 79f259340ba..35850032d5c 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/Tag.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'Math::BigInt', + 'id' => 'int', 'name' => 'string' }; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm index bc8971fb5e2..88a396ece3a 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Object/User.pm @@ -20,7 +20,7 @@ use base "WWW::SwaggerClient::Object::BaseObject"; # my $swagger_types = { - 'id' => 'Math::BigInt', + 'id' => 'int', 'username' => 'string', 'first_name' => 'string', 'last_name' => 'string', diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index b1985703ddd..930bd52102b 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -279,7 +279,7 @@ sub new { # # Find pet by ID # - # @param Math::BigInt $pet_id ID of pet that needs to be fetched (required) + # @param int $pet_id ID of pet that needs to be fetched (required) # @return Pet # sub get_pet_by_id { @@ -411,7 +411,7 @@ sub new { # Deletes a pet # # @param string $api_key (required) - # @param Math::BigInt $pet_id Pet id to delete (required) + # @param int $pet_id Pet id to delete (required) # @return void # sub delete_pet { @@ -472,7 +472,7 @@ sub new { # # uploads an image # - # @param Math::BigInt $pet_id ID of pet to update (required) + # @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 diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl index 2c545c7aac9..eb06f786f98 100755 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -15,7 +15,7 @@ use DateTime; my $api = WWW::SwaggerClient::PetApi->new(); -my $pet_id = 88; +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'); @@ -30,7 +30,7 @@ $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 => '/var/tmp/f5.jpg'); +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');