forked from loafle/openapi-generator-original
test post body (model), fix to_hash attribute mapping
This commit is contained in:
parent
f69fb40c71
commit
48844442fc
@ -75,15 +75,24 @@ sub call_api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# body data
|
# body data
|
||||||
my $_body_data = $post_params ? $post_params : $body_data;
|
my $_body_data = %$post_params ? $post_params : to_json($body_data->to_hash);
|
||||||
|
|
||||||
# Make the HTTP request
|
# Make the HTTP request
|
||||||
my $_request;
|
my $_request;
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 'POST' {
|
case 'POST' {
|
||||||
#TODO: multipart
|
# multipart
|
||||||
|
my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ?
|
||||||
|
'form-data' : $header_params->{'Content-Type'};
|
||||||
$_request = POST($_url, Accept => $header_params->{Accept},
|
$_request = POST($_url, Accept => $header_params->{Accept},
|
||||||
Content_Type => $header_params->{'Content-Type'}, Content => $_body_data);
|
Content_Type => $_content_type, Content => $_body_data);
|
||||||
|
}
|
||||||
|
case 'PUT' {
|
||||||
|
# multipart
|
||||||
|
my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ?
|
||||||
|
'form-data' : $header_params->{'Content-Type'};
|
||||||
|
$_request = PUT($_url, Accept => $header_params->{Accept},
|
||||||
|
Content_Type => $_content_type, Content => $_body_data);
|
||||||
}
|
}
|
||||||
case 'GET' {
|
case 'GET' {
|
||||||
$_request = GET($_url, Accept => $header_params->{'Accept'},
|
$_request = GET($_url, Accept => $header_params->{'Accept'},
|
||||||
|
@ -29,7 +29,7 @@ sub TO_JSON {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $_data = {};
|
my $_data = {};
|
||||||
foreach my $_key (keys $self->get_attribute_map) {
|
foreach my $_key (keys $self->get_attribute_map) {
|
||||||
if (defined $self->{$self->get_attribute_map->{$_key}}) {
|
if (defined $self->{$_key}) {
|
||||||
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
|
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,15 +75,24 @@ sub call_api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# body data
|
# body data
|
||||||
my $_body_data = $post_params ? $post_params : $body_data;
|
my $_body_data = %$post_params ? $post_params : to_json($body_data->to_hash);
|
||||||
|
|
||||||
# Make the HTTP request
|
# Make the HTTP request
|
||||||
my $_request;
|
my $_request;
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 'POST' {
|
case 'POST' {
|
||||||
#TODO: multipart
|
# multipart
|
||||||
|
my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ?
|
||||||
|
'form-data' : $header_params->{'Content-Type'};
|
||||||
$_request = POST($_url, Accept => $header_params->{Accept},
|
$_request = POST($_url, Accept => $header_params->{Accept},
|
||||||
Content_Type => $header_params->{'Content-Type'}, Content => $_body_data);
|
Content_Type => $_content_type, Content => $_body_data);
|
||||||
|
}
|
||||||
|
case 'PUT' {
|
||||||
|
# multipart
|
||||||
|
my $_content_type = lc $header_params->{'Content-Type'} eq 'multipart/form' ?
|
||||||
|
'form-data' : $header_params->{'Content-Type'};
|
||||||
|
$_request = PUT($_url, Accept => $header_params->{Accept},
|
||||||
|
Content_Type => $_content_type, Content => $_body_data);
|
||||||
}
|
}
|
||||||
case 'GET' {
|
case 'GET' {
|
||||||
$_request = GET($_url, Accept => $header_params->{'Accept'},
|
$_request = GET($_url, Accept => $header_params->{'Accept'},
|
||||||
|
@ -29,7 +29,7 @@ sub TO_JSON {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $_data = {};
|
my $_data = {};
|
||||||
foreach my $_key (keys $self->get_attribute_map) {
|
foreach my $_key (keys $self->get_attribute_map) {
|
||||||
if (defined $self->{$self->get_attribute_map->{$_key}}) {
|
if (defined $self->{$_key}) {
|
||||||
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
|
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ my $api = WWW::SwaggerClient::PetApi->new();
|
|||||||
|
|
||||||
#print WWW::SwaggerClient::APIClient::to_form_value('testing 123');
|
#print WWW::SwaggerClient::APIClient::to_form_value('testing 123');
|
||||||
|
|
||||||
my $pet_id = 5;
|
my $pet_id = 88;
|
||||||
my $dt = DateTime->new(
|
my $dt = DateTime->new(
|
||||||
year => 1972,
|
year => 1972,
|
||||||
month => 12,
|
month => 12,
|
||||||
@ -32,14 +32,13 @@ print "dt = $dt\n";
|
|||||||
print "dt = ".$dt->datetime()."\n";
|
print "dt = ".$dt->datetime()."\n";
|
||||||
|
|
||||||
|
|
||||||
my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => 'tag1', 'name' => 'just kidding',
|
my $category = WWW::SwaggerClient::Object::Category->new({'id' => '2', 'name' => 'pending'});
|
||||||
|
my $tag = WWW::SwaggerClient::Object::Tag->new({'id' => '1', 'name' => 'just kidding',
|
||||||
"photoUrls" => ['123', 'oop']});
|
"photoUrls" => ['123', 'oop']});
|
||||||
my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => 5, 'name' => 'haha',
|
my $pet = WWW::SwaggerClient::Object::Pet->new({'id' => $pet_id, 'name' => 'perl test',
|
||||||
"photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'created' => $dt});
|
"photoUrls" => ['123', 'oop'], 'tags' => [$tag], 'status' => 'pending'});
|
||||||
|
|
||||||
##print Dumper $pet;
|
print Dumper $pet;
|
||||||
print "pet ref=".ref($pet)."\n";
|
|
||||||
print "tag ref=".ref($tag)."\n";
|
|
||||||
my $json = JSON->new->convert_blessed;
|
my $json = JSON->new->convert_blessed;
|
||||||
|
|
||||||
#print $json->convert_blessed->encode($pet);
|
#print $json->convert_blessed->encode($pet);
|
||||||
@ -52,5 +51,11 @@ $pet2 = $pet2->from_hash($pet->to_hash);
|
|||||||
print Dumper($pet2->to_hash);
|
print Dumper($pet2->to_hash);
|
||||||
#exit;
|
#exit;
|
||||||
print "============================\n";
|
print "============================\n";
|
||||||
print Dumper $api->get_pet_by_id({pet_id => $pet_id});
|
print Dumper $api->add_pet({body => $pet});
|
||||||
print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'});
|
#print Dumper $api->get_pet_by_id({pet_id => $pet_id});
|
||||||
|
#print Dumper $api->update_pet_with_form({pet_id => $pet_id, name => 'test_name', status => 'test status'});
|
||||||
|
#print Dumper $api->delete_pet({pet_id => $pet_id});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user