Fix errors from using wrong JSON spec

I've been using http://petstore.swagger.io/v2/swagger.json instead of
modules/swagger-codegen/src/test/resources/2_0/petstore.json as the
input spec for building the petstore. This commit reverts the changes
introduced from that.
This commit is contained in:
Dave Baird 2015-11-04 22:24:49 +01:00
parent f521680c0f
commit baf20ca226
5 changed files with 40 additions and 134 deletions

View File

@ -1,36 +0,0 @@
package WWW::SwaggerClient::Object::ApiResponse;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Date::Parse;
use DateTime;
use base "WWW::SwaggerClient::Object::BaseObject";
#
#
#
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
__PACKAGE__->swagger_types( {
'code' => 'int',
'type' => 'string',
'message' => 'string'
} );
__PACKAGE__->attribute_map( {
'code' => 'code',
'type' => 'type',
'message' => 'message'
} );
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;

View File

@ -52,18 +52,13 @@ sub new {
#
# Update an existing pet
#
# @param Pet $body Pet object that needs to be added to the store (required)
# @param Pet $body Pet object that needs to be added to the store (optional)
# @return void
#
sub update_pet {
my ($self, %args) = @_;
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling update_pet");
}
# parse inputs
my $_resource_path = '/pet';
@ -75,7 +70,7 @@ sub update_pet {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -107,18 +102,13 @@ sub update_pet {
#
# Add a new pet to the store
#
# @param Pet $body Pet object that needs to be added to the store (required)
# @param Pet $body Pet object that needs to be added to the store (optional)
# @return void
#
sub add_pet {
my ($self, %args) = @_;
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling add_pet");
}
# parse inputs
my $_resource_path = '/pet';
@ -130,7 +120,7 @@ sub add_pet {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -162,18 +152,13 @@ sub add_pet {
#
# Finds Pets by status
#
# @param ARRAY[string] $status Status values that need to be considered for filter (required)
# @param ARRAY[string] $status Status values that need to be considered for filter (optional)
# @return ARRAY[Pet]
#
sub find_pets_by_status {
my ($self, %args) = @_;
# verify the required parameter 'status' is set
unless (exists $args{'status'}) {
croak("Missing the required parameter 'status' when calling find_pets_by_status");
}
# parse inputs
my $_resource_path = '/pet/findByStatus';
@ -185,7 +170,7 @@ sub find_pets_by_status {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -220,18 +205,13 @@ sub find_pets_by_status {
#
# Finds Pets by tags
#
# @param ARRAY[string] $tags Tags to filter by (required)
# @param ARRAY[string] $tags Tags to filter by (optional)
# @return ARRAY[Pet]
#
sub find_pets_by_tags {
my ($self, %args) = @_;
# verify the required parameter 'tags' is set
unless (exists $args{'tags'}) {
croak("Missing the required parameter 'tags' when calling find_pets_by_tags");
}
# parse inputs
my $_resource_path = '/pet/findByTags';
@ -243,7 +223,7 @@ sub find_pets_by_tags {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -278,7 +258,7 @@ sub find_pets_by_tags {
#
# Find pet by ID
#
# @param int $pet_id ID of pet to return (required)
# @param int $pet_id ID of pet that needs to be fetched (required)
# @return Pet
#
sub get_pet_by_id {
@ -301,7 +281,7 @@ sub get_pet_by_id {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -338,7 +318,7 @@ sub get_pet_by_id {
#
# Updates a pet in the store with form data
#
# @param int $pet_id ID of pet that needs to be updated (required)
# @param string $pet_id ID of pet that needs to be updated (required)
# @param string $name Updated name of the pet (optional)
# @param string $status Updated status of the pet (optional)
# @return void
@ -363,7 +343,7 @@ sub update_pet_with_form {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -431,7 +411,7 @@ sub delete_pet {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -471,7 +451,7 @@ sub delete_pet {
# @param int $pet_id ID of pet to update (required)
# @param string $additional_metadata Additional data to pass to server (optional)
# @param file $file file to upload (optional)
# @return ApiResponse
# @return void
#
sub upload_file {
my ($self, %args) = @_;
@ -493,7 +473,7 @@ sub upload_file {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -526,14 +506,11 @@ sub upload_file {
my $auth_settings = ['petstore_auth'];
# make the API Call
my $response = $self->{api_client}->call_api($_resource_path, $_method,
$self->{api_client}->call_api($_resource_path, $_method,
$query_params, $form_params,
$header_params, $_body_data, $auth_settings);
if (!$response) {
return;
}
my $_response_object = $self->{api_client}->deserialize('ApiResponse', $response);
return $_response_object;
return;
}

View File

@ -69,7 +69,7 @@ sub get_inventory {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -101,18 +101,13 @@ sub get_inventory {
#
# Place an order for a pet
#
# @param Order $body order placed for purchasing the pet (required)
# @param Order $body order placed for purchasing the pet (optional)
# @return Order
#
sub place_order {
my ($self, %args) = @_;
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling place_order");
}
# parse inputs
my $_resource_path = '/store/order';
@ -124,7 +119,7 @@ sub place_order {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -159,7 +154,7 @@ sub place_order {
#
# Find purchase order by ID
#
# @param int $order_id ID of pet that needs to be fetched (required)
# @param string $order_id ID of pet that needs to be fetched (required)
# @return Order
#
sub get_order_by_id {
@ -182,7 +177,7 @@ sub get_order_by_id {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -242,7 +237,7 @@ sub delete_order {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}

View File

@ -52,18 +52,13 @@ sub new {
#
# Create user
#
# @param User $body Created user object (required)
# @param User $body Created user object (optional)
# @return void
#
sub create_user {
my ($self, %args) = @_;
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling create_user");
}
# parse inputs
my $_resource_path = '/user';
@ -75,7 +70,7 @@ sub create_user {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -107,18 +102,13 @@ sub create_user {
#
# Creates list of users with given input array
#
# @param ARRAY[User] $body List of user object (required)
# @param ARRAY[User] $body List of user object (optional)
# @return void
#
sub create_users_with_array_input {
my ($self, %args) = @_;
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling create_users_with_array_input");
}
# parse inputs
my $_resource_path = '/user/createWithArray';
@ -130,7 +120,7 @@ sub create_users_with_array_input {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -162,18 +152,13 @@ sub create_users_with_array_input {
#
# Creates list of users with given input array
#
# @param ARRAY[User] $body List of user object (required)
# @param ARRAY[User] $body List of user object (optional)
# @return void
#
sub create_users_with_list_input {
my ($self, %args) = @_;
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling create_users_with_list_input");
}
# parse inputs
my $_resource_path = '/user/createWithList';
@ -185,7 +170,7 @@ sub create_users_with_list_input {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -217,24 +202,14 @@ sub create_users_with_list_input {
#
# 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)
# @param string $username The user name for login (optional)
# @param string $password The password for login in clear text (optional)
# @return string
#
sub login_user {
my ($self, %args) = @_;
# verify the required parameter 'username' is set
unless (exists $args{'username'}) {
croak("Missing the required parameter 'username' when calling login_user");
}
# verify the required parameter 'password' is set
unless (exists $args{'password'}) {
croak("Missing the required parameter 'password' when calling login_user");
}
# parse inputs
my $_resource_path = '/user/login';
@ -246,7 +221,7 @@ sub login_user {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -301,7 +276,7 @@ sub logout_user {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -353,7 +328,7 @@ sub get_user_by_name {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -391,7 +366,7 @@ sub get_user_by_name {
# Updated user
#
# @param string $username name that need to be deleted (required)
# @param User $body Updated user object (required)
# @param User $body Updated user object (optional)
# @return void
#
sub update_user {
@ -403,11 +378,6 @@ sub update_user {
croak("Missing the required parameter 'username' when calling update_user");
}
# verify the required parameter 'body' is set
unless (exists $args{'body'}) {
croak("Missing the required parameter 'body' when calling update_user");
}
# parse inputs
my $_resource_path = '/user/{username}';
@ -419,7 +389,7 @@ sub update_user {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}
@ -479,7 +449,7 @@ sub delete_user {
my $form_params = {};
# 'Accept' and 'Content-Type' header
my $_header_accept = $self->{api_client}->select_header_accept('application/xml', 'application/json');
my $_header_accept = $self->{api_client}->select_header_accept('application/json', 'application/xml');
if ($_header_accept) {
$header_params->{'Accept'} = $_header_accept;
}

View File

@ -69,8 +69,8 @@ is $update_pet_with_form, undef, 'get the null response from update_pet_wth_form
my $get_pet_after_update = $api->get_pet_by_id(pet_id => $pet_id);
is $get_pet_after_update->{status}, 'sold', 'get the updated status after update_pet_with_form';
my $upload_file = $api->upload_file(pet_id => $pet_id, additional_metadata => 'testabc', file => 'test.pl');
isa_ok($upload_file, 'WWW::SwaggerClient::Object::ApiResponse'); # WWW::SwaggerClient::Object::Pet
my $upload_pet = $api->upload_file(pet_id => $pet_id, additional_metadata => 'testabc', file => 'test.pl');
is $upload_pet, undef, 'get the null response from upload_pet';
my $delete_pet = $api->delete_pet(pet_id => $pet_id);
is $delete_pet, undef, 'get the null response from delete_pet';