seralization and deserialization work, get_pet_by_id and

update_pet_with_form work
This commit is contained in:
William Cheng 2015-05-06 18:46:31 +08:00
parent a7ef1262e5
commit 07cd23edac
27 changed files with 2356 additions and 2894 deletions

View File

@ -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

View File

@ -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) = @_;
{{#allParams}}{{#required}}
# verify the required parameter '{{paramName}}' is set
unless (exists $args->{'{{paramName}}'}) {
croak("Missing the required parameter '{{paramName}}' when calling {{nickname}}");
}
{{/required}}{{/allParams}}
# parse inputs
my $resource_path = "{{path}}";
$resource_path =~ s/{format}/json/;
my $_resource_path = '{{path}}';
$_resource_path =~ s/{format}/json/; # default format to json
my $method = "{{httpMethod}}";
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}}';
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}}

View File

@ -1,66 +1,100 @@
<?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.
*/
/**
* $model.description$
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
{{#models}}
{{#model}}
package WWW::{{invokerPackage}}::Model::{{classname}};
class {{classname}} implements ArrayAccess {
static $swaggerTypes = array(
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);
#
#{{description}}
#
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
};
static $attributeMap = array(
my $attribute_map = {
{{#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}}
# new object
sub new {
my ($class, $args) = @_;
my $self = {
{{#vars}}#{{#description}}{{{description}}}{{/description}}
'{{name}}' => $args->{'{{baseName}}'}{{#hasMore}},
{{/hasMore}}{{/vars}}
};
return bless $self, $class;
}
public function offsetExists($offset) {
return isset($this->$offset);
# return json string
sub to_hash {
return decode_json(JSON->new->convert_blessed->encode( shift ));
}
public function offsetGet($offset) {
return $this->$offset;
# 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;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
# 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 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;

View File

@ -1,60 +0,0 @@
<?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.
*/
/**
* $model.description$
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
class Category implements ArrayAccess {
static $swaggerTypes = array(
'id' => '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);
}
}

View File

@ -1,79 +0,0 @@
<?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.
*/
/**
* $model.description$
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
class Order implements ArrayAccess {
static $swaggerTypes = array(
'id' => '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);
}
}

View File

@ -1,79 +0,0 @@
<?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.
*/
/**
* $model.description$
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
class Pet implements ArrayAccess {
static $swaggerTypes = array(
'id' => '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);
}
}

View File

@ -1,60 +0,0 @@
<?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.
*/
/**
* $model.description$
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
class Tag implements ArrayAccess {
static $swaggerTypes = array(
'id' => '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);
}
}

View File

@ -1,87 +0,0 @@
<?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.
*/
/**
* $model.description$
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
class User implements ArrayAccess {
static $swaggerTypes = array(
'id' => '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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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";
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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'});