forked from loafle/openapi-generator-original
fix all swagger.pl syntax issue
This commit is contained in:
parent
c5fcf3ba2c
commit
a7ef1262e5
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,326 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
package WWW::Swagger::Swagger;
|
||||
|
||||
/* Autoload the model definition files */
|
||||
/**
|
||||
*
|
||||
* @param string $className the class to attempt to load
|
||||
*/
|
||||
function swagger_autoloader($className) {
|
||||
$currentDir = dirname(__FILE__);
|
||||
if (file_exists($currentDir . '/' . $className . '.php')) {
|
||||
include $currentDir . '/' . $className . '.php';
|
||||
} elseif (file_exists($currentDir . '/models/' . $className . '.php')) {
|
||||
include $currentDir . '/models/' . $className . '.php';
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
229
samples/client/petstore/perl/Swagger.pl
Normal file
229
samples/client/petstore/perl/Swagger.pl
Normal file
@ -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;
|
@ -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,';
|
||||
|
||||
|
||||
|
||||
|
@ -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 = @_;
|
||||
|
||||
|
@ -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 = @_;
|
||||
|
||||
|
486
samples/client/petstore/perl/WWW/Swagger/pet_api.pm
Normal file
486
samples/client/petstore/perl/WWW/Swagger/pet_api.pm
Normal file
@ -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;
|
262
samples/client/petstore/perl/WWW/Swagger/store_api.pm
Normal file
262
samples/client/petstore/perl/WWW/Swagger/store_api.pm
Normal file
@ -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;
|
463
samples/client/petstore/perl/WWW/Swagger/user_api.pm
Normal file
463
samples/client/petstore/perl/WWW/Swagger/user_api.pm
Normal file
@ -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;
|
Loading…
x
Reference in New Issue
Block a user