forked from loafle/openapi-generator-original
146 lines
4.8 KiB
Plaintext
146 lines
4.8 KiB
Plaintext
#
|
|
# 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::{{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}}
|
|
|
|
use WWW::{{invokerPackage}}::APIClient;
|
|
|
|
our @EXPORT_OK = qw(
|
|
{{#operation}}{{{nickname}}}
|
|
{{/operation}}
|
|
);
|
|
|
|
sub new {
|
|
my $class = 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};
|
|
|
|
my $self = {
|
|
#api_client => $options->{api_client}
|
|
api_client => $default_api_client
|
|
};
|
|
|
|
bless $self, $class;
|
|
|
|
}
|
|
|
|
{{#operation}}
|
|
#
|
|
# {{{nickname}}}
|
|
#
|
|
# {{{summary}}}
|
|
#
|
|
{{#allParams}} # @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
|
{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
|
#
|
|
sub {{nickname}} {
|
|
my ($self, $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/; # default format to json
|
|
|
|
my $_method = '{{httpMethod}}';
|
|
my $query_params = {};
|
|
my $header_params = {};
|
|
my $form_params = {};
|
|
|
|
my $_header_accept = '{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}';
|
|
if ($_header_accept ne '') {
|
|
$header_params->{'Accept'} = $_header_accept;
|
|
}
|
|
my @_header_content_type = ({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}});
|
|
$header_params->{'Content-Type'} = scalar(@_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
|
|
{{#queryParams}} # query params
|
|
if ( exists $args->{'{{paramName}}'}) {
|
|
$query_params->{'{{baseName}}'} = WWW::{{invokerPacakge}}::APIClient::to_query_value($args->{'{{paramName}}'});
|
|
}{{/queryParams}}
|
|
{{#headerParams}} # header params
|
|
if ( exists $args->{'{{paramName}}'}) {
|
|
$header_params->{'{{baseName}}'} = WWW::{{invokerPackage}}::APIClient::to_header_value($args->{'{{paramName}}'});
|
|
}{{/headerParams}}
|
|
{{#pathParams}} # path params
|
|
if ( exists $args->{'{{paramName}}'}) {
|
|
my $_base_variable = "{" . "{{baseName}}" . "}";
|
|
my $_base_value = WWW::{{invokerPackage}}::APIClient::to_path_value($args->{'{{paramName}}'});
|
|
$_resource_path =~ s/$_base_variable/$_base_value/g;
|
|
}{{/pathParams}}
|
|
{{#formParams}} # form params
|
|
if ( exists $args->{'{{paramName}}'} ) {
|
|
$form_params->{'{{baseName}}'} = {{#isFile}}'@' . {{/isFile}}WWW::{{invokerPackage}}::APIClient::to_form_value($args->{'{{paramName}}'});
|
|
}{{/formParams}}
|
|
my $_body_data;
|
|
{{#bodyParams}} # body params
|
|
if ( exists $args->{'{{paramName}}'}) {
|
|
$_body_data = $args->{'{{paramName}}'};
|
|
}{{/bodyParams}}
|
|
|
|
# for HTTP post (form)
|
|
#$_body_data = $_body ? undef : $form_params;
|
|
|
|
# make the API Call
|
|
{{#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('{{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}}
|
|
{{/operations}}
|
|
|
|
1;
|