Make class and method documentation available

Documentation from the swagger spec is available via methods
class_documentation() and method_documentation() on object and API
classes.
This commit is contained in:
Dave Baird
2015-11-09 17:04:19 +01:00
parent f0f43f5fdf
commit 49034946a0
15 changed files with 406 additions and 16 deletions

View File

@@ -20,8 +20,10 @@ use base ("Class::Accessor", "Class::Data::Inheritable");
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
__PACKAGE__->mk_classdata('attribute_map');
__PACKAGE__->mk_classdata('swagger_types');
__PACKAGE__->mk_classdata('attribute_map' => {});
__PACKAGE__->mk_classdata('swagger_types' => {});
__PACKAGE__->mk_classdata('method_documentation' => {}); # TODO
__PACKAGE__->mk_classdata('class_documentation' => {});
# new object
sub new {

View File

@@ -19,6 +19,8 @@ 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__->class_documentation({description => ''});
__PACKAGE__->swagger_types( {
'id' => 'int',
'name' => 'string'

View File

@@ -19,6 +19,8 @@ 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__->class_documentation({description => ''});
__PACKAGE__->swagger_types( {
'id' => 'int',
'pet_id' => 'int',

View File

@@ -19,6 +19,8 @@ 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__->class_documentation({description => ''});
__PACKAGE__->swagger_types( {
'id' => 'int',
'category' => 'Category',

View File

@@ -19,6 +19,8 @@ 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__->class_documentation({description => ''});
__PACKAGE__->swagger_types( {
'id' => 'int',
'name' => 'string'

View File

@@ -19,6 +19,8 @@ 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__->class_documentation({description => ''});
__PACKAGE__->swagger_types( {
'id' => 'int',
'username' => 'string',

View File

@@ -30,6 +30,12 @@ use Log::Any qw($log);
use WWW::SwaggerClient::ApiClient;
use WWW::SwaggerClient::Configuration;
use base "Class::Data::Inheritable";
__PACKAGE__->mk_classdata('method_documentation' => {});
__PACKAGE__->mk_classdata('class_documentation' => {}); # TODO
sub new {
my $class = shift;
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
@@ -47,12 +53,26 @@ sub new {
}
#
# update_pet
#
# Update an existing pet
#
# @param Pet $body Pet object that needs to be added to the store (optional)
{
my $params = {
'body' => {
data_type => 'Pet',
description => 'Pet object that needs to be added to the store',
required => '0',
},
};
__PACKAGE__->method_documentation->{ update_pet } = { summary => 'Update an existing pet',
params => $params,
returns => undef,
};
}
# @return void
#
sub update_pet {
@@ -97,12 +117,26 @@ sub update_pet {
return;
}
#
# add_pet
#
# Add a new pet to the store
#
# @param Pet $body Pet object that needs to be added to the store (optional)
{
my $params = {
'body' => {
data_type => 'Pet',
description => 'Pet object that needs to be added to the store',
required => '0',
},
};
__PACKAGE__->method_documentation->{ add_pet } = { summary => 'Add a new pet to the store',
params => $params,
returns => undef,
};
}
# @return void
#
sub add_pet {
@@ -147,12 +181,26 @@ sub add_pet {
return;
}
#
# find_pets_by_status
#
# Finds Pets by status
#
# @param ARRAY[string] $status Status values that need to be considered for filter (optional)
{
my $params = {
'status' => {
data_type => 'ARRAY[string]',
description => 'Status values that need to be considered for filter',
required => '0',
},
};
__PACKAGE__->method_documentation->{ find_pets_by_status } = { summary => 'Finds Pets by status',
params => $params,
returns => 'ARRAY[Pet]',
};
}
# @return ARRAY[Pet]
#
sub find_pets_by_status {
@@ -200,12 +248,26 @@ sub find_pets_by_status {
return $_response_object;
}
#
# find_pets_by_tags
#
# Finds Pets by tags
#
# @param ARRAY[string] $tags Tags to filter by (optional)
{
my $params = {
'tags' => {
data_type => 'ARRAY[string]',
description => 'Tags to filter by',
required => '0',
},
};
__PACKAGE__->method_documentation->{ find_pets_by_tags } = { summary => 'Finds Pets by tags',
params => $params,
returns => 'ARRAY[Pet]',
};
}
# @return ARRAY[Pet]
#
sub find_pets_by_tags {
@@ -253,12 +315,26 @@ sub find_pets_by_tags {
return $_response_object;
}
#
# get_pet_by_id
#
# Find pet by ID
#
# @param int $pet_id ID of pet that needs to be fetched (required)
{
my $params = {
'pet_id' => {
data_type => 'int',
description => 'ID of pet that needs to be fetched',
required => '1',
},
};
__PACKAGE__->method_documentation->{ get_pet_by_id } = { summary => 'Find pet by ID',
params => $params,
returns => 'Pet',
};
}
# @return Pet
#
sub get_pet_by_id {
@@ -313,6 +389,7 @@ sub get_pet_by_id {
return $_response_object;
}
#
# update_pet_with_form
#
@@ -321,6 +398,29 @@ sub get_pet_by_id {
# @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)
{
my $params = {
'pet_id' => {
data_type => 'string',
description => 'ID of pet that needs to be updated',
required => '1',
},
'name' => {
data_type => 'string',
description => 'Updated name of the pet',
required => '0',
},
'status' => {
data_type => 'string',
description => 'Updated status of the pet',
required => '0',
},
};
__PACKAGE__->method_documentation->{ update_pet_with_form } = { summary => 'Updates a pet in the store with form data',
params => $params,
returns => undef,
};
}
# @return void
#
sub update_pet_with_form {
@@ -382,6 +482,7 @@ sub update_pet_with_form {
return;
}
#
# delete_pet
#
@@ -389,6 +490,24 @@ sub update_pet_with_form {
#
# @param int $pet_id Pet id to delete (required)
# @param string $api_key (optional)
{
my $params = {
'pet_id' => {
data_type => 'int',
description => 'Pet id to delete',
required => '1',
},
'api_key' => {
data_type => 'string',
description => '',
required => '0',
},
};
__PACKAGE__->method_documentation->{ delete_pet } = { summary => 'Deletes a pet',
params => $params,
returns => undef,
};
}
# @return void
#
sub delete_pet {
@@ -443,6 +562,7 @@ sub delete_pet {
return;
}
#
# upload_file
#
@@ -451,6 +571,29 @@ 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)
{
my $params = {
'pet_id' => {
data_type => 'int',
description => 'ID of pet to update',
required => '1',
},
'additional_metadata' => {
data_type => 'string',
description => 'Additional data to pass to server',
required => '0',
},
'file' => {
data_type => 'file',
description => 'file to upload',
required => '0',
},
};
__PACKAGE__->method_documentation->{ upload_file } = { summary => 'uploads an image',
params => $params,
returns => undef,
};
}
# @return void
#
sub upload_file {

View File

@@ -24,7 +24,7 @@ sub BUILD {
my $self = shift;
# ignore these symbols imported into API namespaces
my %outsiders = map {$_ => 1} qw( new croak );
my %outsiders = map {$_ => 1} qw( croak );
my %delegates;
@@ -32,7 +32,7 @@ sub BUILD {
foreach my $api_name ($self->api_factory->apis_available) {
my $api_class = $self->api_factory->classname_for($api_name);
my $methods = Class::Inspector->methods($api_class, 'expanded');
my @local_methods = grep {! $outsiders{$_}} map {$_->[2]} grep {$_->[1] eq $api_class} @$methods;
my @local_methods = grep {! /^_/} grep {! $outsiders{$_}} map {$_->[2]} grep {$_->[1] eq $api_class} @$methods;
push( @{$delegates{$_}}, {api_name => $api_name, api_class => $api_class} ) for @local_methods;
}

View File

@@ -30,6 +30,12 @@ use Log::Any qw($log);
use WWW::SwaggerClient::ApiClient;
use WWW::SwaggerClient::Configuration;
use base "Class::Data::Inheritable";
__PACKAGE__->mk_classdata('method_documentation' => {});
__PACKAGE__->mk_classdata('class_documentation' => {}); # TODO
sub new {
my $class = shift;
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
@@ -47,11 +53,20 @@ sub new {
}
#
# get_inventory
#
# Returns pet inventories by status
#
{
my $params = {
};
__PACKAGE__->method_documentation->{ get_inventory } = { summary => 'Returns pet inventories by status',
params => $params,
returns => 'HASH[string,int]',
};
}
# @return HASH[string,int]
#
sub get_inventory {
@@ -96,12 +111,26 @@ sub get_inventory {
return $_response_object;
}
#
# place_order
#
# Place an order for a pet
#
# @param Order $body order placed for purchasing the pet (optional)
{
my $params = {
'body' => {
data_type => 'Order',
description => 'order placed for purchasing the pet',
required => '0',
},
};
__PACKAGE__->method_documentation->{ place_order } = { summary => 'Place an order for a pet',
params => $params,
returns => 'Order',
};
}
# @return Order
#
sub place_order {
@@ -149,12 +178,26 @@ sub place_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)
{
my $params = {
'order_id' => {
data_type => 'string',
description => 'ID of pet that needs to be fetched',
required => '1',
},
};
__PACKAGE__->method_documentation->{ get_order_by_id } = { summary => 'Find purchase order by ID',
params => $params,
returns => 'Order',
};
}
# @return Order
#
sub get_order_by_id {
@@ -209,12 +252,26 @@ sub get_order_by_id {
return $_response_object;
}
#
# delete_order
#
# Delete purchase order by ID
#
# @param string $order_id ID of the order that needs to be deleted (required)
{
my $params = {
'order_id' => {
data_type => 'string',
description => 'ID of the order that needs to be deleted',
required => '1',
},
};
__PACKAGE__->method_documentation->{ delete_order } = { summary => 'Delete purchase order by ID',
params => $params,
returns => undef,
};
}
# @return void
#
sub delete_order {

View File

@@ -30,6 +30,12 @@ use Log::Any qw($log);
use WWW::SwaggerClient::ApiClient;
use WWW::SwaggerClient::Configuration;
use base "Class::Data::Inheritable";
__PACKAGE__->mk_classdata('method_documentation' => {});
__PACKAGE__->mk_classdata('class_documentation' => {}); # TODO
sub new {
my $class = shift;
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
@@ -47,12 +53,26 @@ sub new {
}
#
# create_user
#
# Create user
#
# @param User $body Created user object (optional)
{
my $params = {
'body' => {
data_type => 'User',
description => 'Created user object',
required => '0',
},
};
__PACKAGE__->method_documentation->{ create_user } = { summary => 'Create user',
params => $params,
returns => undef,
};
}
# @return void
#
sub create_user {
@@ -97,12 +117,26 @@ sub create_user {
return;
}
#
# create_users_with_array_input
#
# Creates list of users with given input array
#
# @param ARRAY[User] $body List of user object (optional)
{
my $params = {
'body' => {
data_type => 'ARRAY[User]',
description => 'List of user object',
required => '0',
},
};
__PACKAGE__->method_documentation->{ create_users_with_array_input } = { summary => 'Creates list of users with given input array',
params => $params,
returns => undef,
};
}
# @return void
#
sub create_users_with_array_input {
@@ -147,12 +181,26 @@ sub create_users_with_array_input {
return;
}
#
# create_users_with_list_input
#
# Creates list of users with given input array
#
# @param ARRAY[User] $body List of user object (optional)
{
my $params = {
'body' => {
data_type => 'ARRAY[User]',
description => 'List of user object',
required => '0',
},
};
__PACKAGE__->method_documentation->{ create_users_with_list_input } = { summary => 'Creates list of users with given input array',
params => $params,
returns => undef,
};
}
# @return void
#
sub create_users_with_list_input {
@@ -197,6 +245,7 @@ sub create_users_with_list_input {
return;
}
#
# login_user
#
@@ -204,6 +253,24 @@ sub create_users_with_list_input {
#
# @param string $username The user name for login (optional)
# @param string $password The password for login in clear text (optional)
{
my $params = {
'username' => {
data_type => 'string',
description => 'The user name for login',
required => '0',
},
'password' => {
data_type => 'string',
description => 'The password for login in clear text',
required => '0',
},
};
__PACKAGE__->method_documentation->{ login_user } = { summary => 'Logs user into the system',
params => $params,
returns => 'string',
};
}
# @return string
#
sub login_user {
@@ -254,11 +321,20 @@ sub login_user {
return $_response_object;
}
#
# logout_user
#
# Logs out current logged in user session
#
{
my $params = {
};
__PACKAGE__->method_documentation->{ logout_user } = { summary => 'Logs out current logged in user session',
params => $params,
returns => undef,
};
}
# @return void
#
sub logout_user {
@@ -300,12 +376,26 @@ sub logout_user {
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)
{
my $params = {
'username' => {
data_type => 'string',
description => 'The name that needs to be fetched. Use user1 for testing.',
required => '1',
},
};
__PACKAGE__->method_documentation->{ get_user_by_name } = { summary => 'Get user by user name',
params => $params,
returns => 'User',
};
}
# @return User
#
sub get_user_by_name {
@@ -360,6 +450,7 @@ sub get_user_by_name {
return $_response_object;
}
#
# update_user
#
@@ -367,6 +458,24 @@ sub get_user_by_name {
#
# @param string $username name that need to be deleted (required)
# @param User $body Updated user object (optional)
{
my $params = {
'username' => {
data_type => 'string',
description => 'name that need to be deleted',
required => '1',
},
'body' => {
data_type => 'User',
description => 'Updated user object',
required => '0',
},
};
__PACKAGE__->method_documentation->{ update_user } = { summary => 'Updated user',
params => $params,
returns => undef,
};
}
# @return void
#
sub update_user {
@@ -421,12 +530,26 @@ sub update_user {
return;
}
#
# delete_user
#
# Delete user
#
# @param string $username The name that needs to be deleted (required)
{
my $params = {
'username' => {
data_type => 'string',
description => 'The name that needs to be deleted',
required => '1',
},
};
__PACKAGE__->method_documentation->{ delete_user } = { summary => 'Delete user',
params => $params,
returns => undef,
};
}
# @return void
#
sub delete_user {