Skip to content

[Perl] add "Getting Started" section for Perl documentation #2400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions modules/swagger-codegen/src/main/resources/perl/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,47 @@ To load the models:
{{/model}}{{/models}}
````

# GETTING STARTED
Put the Perl SDK under the 'lib' folder in your project directory, then run the following
```perl
#!/usr/bin/perl
use lib 'lib';
use strict;
use warnings;
# load the API package
{{#apiInfo}}{{#apis}}use {{moduleName}}::{{classname}};
{{/apis}}{{/apiInfo}}
# load the models
{{#models}}{{#model}}use {{moduleName}}::Object::{{classname}};
{{/model}}{{/models}}
# for displaying the API response data
use Data::Dumper;
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
{{{moduleName}}}::Configuration::username = 'YOUR_USERNAME';
{{{moduleName}}}::Configuration::password = 'YOUR_PASSWORD';{{/isBasic}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
{{{moduleName}}}::Configuration::api_key->{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
# uncomment below to setup prefix (e.g. BEARER) for API key, if needed
#{{{moduleName}}}::Configuration::api_key_prefix->{'{{{keyParamName}}}'} = 'BEARER';{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
{{{moduleName}}}::Configuration::access_token = 'YOUR_ACCESS_TOKEN';{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}

my $api_instance = {{moduleName}}::{{classname}}->new();
{{#allParams}}my ${{paramName}} = {{#isListContainer}}({{/isListContainer}}{{#isBodyParam}}{{{moduleName}}}::Object::{{dataType}}->new(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}){{/isListContainer}}; # {{{dataType}}} | {{{description}}}
{{/allParams}}

eval {
{{#returnType}}my $result = {{/returnType}}$api_instance->{{{operationId}}}({{#allParams}}{{paramName}} => ${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
print Dumper($result);{{/returnType}}
};
if ($@) {
warn "Exception when calling {{classname}}->{{operationId}}: $@\n";
}
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```

# DOCUMENTATION FOR API ENDPOINTS

All URIs are relative to *{{basePath}}*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ use Data::Dumper;
{{{moduleName}}}::Configuration::access_token = 'YOUR_ACCESS_TOKEN';{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}

my $api = {{moduleName}}::{{classname}}->new();
{{#allParams}}my ${{paramName}} = {{#isListContainer}}({{/isListContainer}}{{#isBodyParam}}{{{moduleName}}}::Object::{{dataType}}->new(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}){{/isListContainer}}; # [{{{dataType}}}] {{description}}
my $api_instance = {{moduleName}}::{{classname}}->new();
{{#allParams}}my ${{paramName}} = {{#isListContainer}}({{/isListContainer}}{{#isBodyParam}}{{{moduleName}}}::Object::{{dataType}}->new(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}){{/isListContainer}}; # {{{dataType}}} | {{{description}}}
{{/allParams}}

eval {
{{#returnType}}my $result = {{/returnType}}$api->{{{operationId}}}({{#allParams}}{{paramName}} => ${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
{{#returnType}}my $result = {{/returnType}}$api_instance->{{{operationId}}}({{#allParams}}{{paramName}} => ${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
print Dumper($result);{{/returnType}}
};
if ($@) {
Expand Down
44 changes: 43 additions & 1 deletion samples/client/petstore/perl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WWW::SwaggerClient::Role - a Moose role for the Swagger Petstore

Automatically generated by the Perl Swagger Codegen project:

- Build date: 2016-03-17T14:27:04.268+08:00
- Build date: 2016-03-17T15:41:15.325+08:00
- Build package: class io.swagger.codegen.languages.PerlClientCodegen
- Codegen version:

Expand Down Expand Up @@ -243,6 +243,48 @@ use WWW::SwaggerClient::Object::User;

````

# GETTING STARTED
Put the Perl SDK under the 'lib' folder in your project directory, then run the following
```perl
#!/usr/bin/perl
use lib 'lib';
use strict;
use warnings;
# load the API package
use WWW::SwaggerClient::PetApi;
use WWW::SwaggerClient::StoreApi;
use WWW::SwaggerClient::UserApi;

# load the models
use WWW::SwaggerClient::Object::Category;
use WWW::SwaggerClient::Object::InlineResponse200;
use WWW::SwaggerClient::Object::Model200Response;
use WWW::SwaggerClient::Object::ModelReturn;
use WWW::SwaggerClient::Object::Name;
use WWW::SwaggerClient::Object::Order;
use WWW::SwaggerClient::Object::Pet;
use WWW::SwaggerClient::Object::SpecialModelName;
use WWW::SwaggerClient::Object::Tag;
use WWW::SwaggerClient::Object::User;

# for displaying the API response data
use Data::Dumper;

# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api_instance = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::Pet->new(); # Pet | Pet object that needs to be added to the store

eval {
$api_instance->add_pet(body => $body);
};
if ($@) {
warn "Exception when calling PetApi->add_pet: $@\n";
}

```

# DOCUMENTATION FOR API ENDPOINTS

All URIs are relative to *http://petstore.swagger.io/v2*
Expand Down
76 changes: 38 additions & 38 deletions samples/client/petstore/perl/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::Pet->new(); # [Pet] Pet object that needs to be added to the store
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::Pet->new(); # Pet | Pet object that needs to be added to the store

eval {
$api->add_pet(body => $body);
$api_instance->add_pet(body => $body);
};
if ($@) {
warn "Exception when calling PetApi->add_pet: $@\n";
Expand Down Expand Up @@ -82,11 +82,11 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::string->new(); # [string] Pet object in the form of byte array
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::string->new(); # string | Pet object in the form of byte array

eval {
$api->add_pet_using_byte_array(body => $body);
$api_instance->add_pet_using_byte_array(body => $body);
};
if ($@) {
warn "Exception when calling PetApi->add_pet_using_byte_array: $@\n";
Expand Down Expand Up @@ -128,12 +128,12 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # [int] Pet id to delete
my $api_key = 'api_key_example'; # [string]
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # int | Pet id to delete
my $api_key = 'api_key_example'; # string |

eval {
$api->delete_pet(pet_id => $pet_id, api_key => $api_key);
$api_instance->delete_pet(pet_id => $pet_id, api_key => $api_key);
};
if ($@) {
warn "Exception when calling PetApi->delete_pet: $@\n";
Expand Down Expand Up @@ -176,11 +176,11 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $status = (); # [ARRAY[string]] Status values that need to be considered for query
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $status = (); # ARRAY[string] | Status values that need to be considered for query

eval {
my $result = $api->find_pets_by_status(status => $status);
my $result = $api_instance->find_pets_by_status(status => $status);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -223,11 +223,11 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $tags = (); # [ARRAY[string]] Tags to filter by
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $tags = (); # ARRAY[string] | Tags to filter by

eval {
my $result = $api->find_pets_by_tags(tags => $tags);
my $result = $api_instance->find_pets_by_tags(tags => $tags);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -274,11 +274,11 @@ WWW::SwaggerClient::Configuration::api_key->{'api_key'} = 'YOUR_API_KEY';
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # [int] ID of pet that needs to be fetched
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # int | ID of pet that needs to be fetched

eval {
my $result = $api->get_pet_by_id(pet_id => $pet_id);
my $result = $api_instance->get_pet_by_id(pet_id => $pet_id);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -325,11 +325,11 @@ WWW::SwaggerClient::Configuration::api_key->{'api_key'} = 'YOUR_API_KEY';
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # [int] ID of pet that needs to be fetched
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # int | ID of pet that needs to be fetched

eval {
my $result = $api->get_pet_by_id_in_object(pet_id => $pet_id);
my $result = $api_instance->get_pet_by_id_in_object(pet_id => $pet_id);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -376,11 +376,11 @@ WWW::SwaggerClient::Configuration::api_key->{'api_key'} = 'YOUR_API_KEY';
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # [int] ID of pet that needs to be fetched
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # int | ID of pet that needs to be fetched

eval {
my $result = $api->pet_pet_idtesting_byte_arraytrue_get(pet_id => $pet_id);
my $result = $api_instance->pet_pet_idtesting_byte_arraytrue_get(pet_id => $pet_id);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -423,11 +423,11 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::Pet->new(); # [Pet] Pet object that needs to be added to the store
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $body = WWW::SwaggerClient::Object::Pet->new(); # Pet | Pet object that needs to be added to the store

eval {
$api->update_pet(body => $body);
$api_instance->update_pet(body => $body);
};
if ($@) {
warn "Exception when calling PetApi->update_pet: $@\n";
Expand Down Expand Up @@ -469,13 +469,13 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 'pet_id_example'; # [string] ID of pet that needs to be updated
my $name = 'name_example'; # [string] Updated name of the pet
my $status = 'status_example'; # [string] Updated status of the pet
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $pet_id = 'pet_id_example'; # string | ID of pet that needs to be updated
my $name = 'name_example'; # string | Updated name of the pet
my $status = 'status_example'; # string | Updated status of the pet

eval {
$api->update_pet_with_form(pet_id => $pet_id, name => $name, status => $status);
$api_instance->update_pet_with_form(pet_id => $pet_id, name => $name, status => $status);
};
if ($@) {
warn "Exception when calling PetApi->update_pet_with_form: $@\n";
Expand Down Expand Up @@ -519,13 +519,13 @@ use Data::Dumper;
# Configure OAuth2 access token for authorization: petstore_auth
WWW::SwaggerClient::Configuration::access_token = 'YOUR_ACCESS_TOKEN';

my $api = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # [int] ID of pet to update
my $additional_metadata = 'additional_metadata_example'; # [string] Additional data to pass to server
my $file = '/path/to/file.txt'; # [File] file to upload
my $api_instance = WWW::SwaggerClient::PetApi->new();
my $pet_id = 789; # int | ID of pet to update
my $additional_metadata = 'additional_metadata_example'; # string | Additional data to pass to server
my $file = '/path/to/file.txt'; # File | file to upload

eval {
$api->upload_file(pet_id => $pet_id, additional_metadata => $additional_metadata, file => $file);
$api_instance->upload_file(pet_id => $pet_id, additional_metadata => $additional_metadata, file => $file);
};
if ($@) {
warn "Exception when calling PetApi->upload_file: $@\n";
Expand Down
32 changes: 16 additions & 16 deletions samples/client/petstore/perl/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non
```perl
use Data::Dumper;

my $api = WWW::SwaggerClient::StoreApi->new();
my $order_id = 'order_id_example'; # [string] ID of the order that needs to be deleted
my $api_instance = WWW::SwaggerClient::StoreApi->new();
my $order_id = 'order_id_example'; # string | ID of the order that needs to be deleted

eval {
$api->delete_order(order_id => $order_id);
$api_instance->delete_order(order_id => $order_id);
};
if ($@) {
warn "Exception when calling StoreApi->delete_order: $@\n";
Expand Down Expand Up @@ -80,11 +80,11 @@ WWW::SwaggerClient::Configuration::api_key->{'x-test_api_client_secret'} = 'YOUR
# uncomment below to setup prefix (e.g. BEARER) for API key, if needed
#WWW::SwaggerClient::Configuration::api_key_prefix->{'x-test_api_client_secret'} = "BEARER";

my $api = WWW::SwaggerClient::StoreApi->new();
my $status = 'status_example'; # [string] Status value that needs to be considered for query
my $api_instance = WWW::SwaggerClient::StoreApi->new();
my $status = 'status_example'; # string | Status value that needs to be considered for query

eval {
my $result = $api->find_orders_by_status(status => $status);
my $result = $api_instance->find_orders_by_status(status => $status);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -129,10 +129,10 @@ WWW::SwaggerClient::Configuration::api_key->{'api_key'} = 'YOUR_API_KEY';
# uncomment below to setup prefix (e.g. BEARER) for API key, if needed
#WWW::SwaggerClient::Configuration::api_key_prefix->{'api_key'} = "BEARER";

my $api = WWW::SwaggerClient::StoreApi->new();
my $api_instance = WWW::SwaggerClient::StoreApi->new();

eval {
my $result = $api->get_inventory();
my $result = $api_instance->get_inventory();
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -174,10 +174,10 @@ WWW::SwaggerClient::Configuration::api_key->{'api_key'} = 'YOUR_API_KEY';
# uncomment below to setup prefix (e.g. BEARER) for API key, if needed
#WWW::SwaggerClient::Configuration::api_key_prefix->{'api_key'} = "BEARER";

my $api = WWW::SwaggerClient::StoreApi->new();
my $api_instance = WWW::SwaggerClient::StoreApi->new();

eval {
my $result = $api->get_inventory_in_object();
my $result = $api_instance->get_inventory_in_object();
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -223,11 +223,11 @@ WWW::SwaggerClient::Configuration::api_key->{'test_api_key_query'} = 'YOUR_API_K
# uncomment below to setup prefix (e.g. BEARER) for API key, if needed
#WWW::SwaggerClient::Configuration::api_key_prefix->{'test_api_key_query'} = "BEARER";

my $api = WWW::SwaggerClient::StoreApi->new();
my $order_id = 'order_id_example'; # [string] ID of pet that needs to be fetched
my $api_instance = WWW::SwaggerClient::StoreApi->new();
my $order_id = 'order_id_example'; # string | ID of pet that needs to be fetched

eval {
my $result = $api->get_order_by_id(order_id => $order_id);
my $result = $api_instance->get_order_by_id(order_id => $order_id);
print Dumper($result);
};
if ($@) {
Expand Down Expand Up @@ -276,11 +276,11 @@ WWW::SwaggerClient::Configuration::api_key->{'x-test_api_client_secret'} = 'YOUR
# uncomment below to setup prefix (e.g. BEARER) for API key, if needed
#WWW::SwaggerClient::Configuration::api_key_prefix->{'x-test_api_client_secret'} = "BEARER";

my $api = WWW::SwaggerClient::StoreApi->new();
my $body = WWW::SwaggerClient::Object::Order->new(); # [Order] order placed for purchasing the pet
my $api_instance = WWW::SwaggerClient::StoreApi->new();
my $body = WWW::SwaggerClient::Object::Order->new(); # Order | order placed for purchasing the pet

eval {
my $result = $api->place_order(body => $body);
my $result = $api_instance->place_order(body => $body);
print Dumper($result);
};
if ($@) {
Expand Down
Loading