MT#65550 add PUT,PATCH,DELETE swagger query_params support

* with a snippet as:
 __PACKAGE__->set_config({
...
        DELETE => {
            query_params => [
                {
                    param => 'foo',
                    description => 'Description',
                    query_type => 'integer',
                },
            ],
        },
 });
  it renders the query parameter on the API swagger documentation.
* query_type must be according to the swagger API, of ommitted it
  falls back to 'string'.

Change-Id: I9345a97ad9a4c674e757cd032fb719f51c25f5b6
master
Kirill Solomko 2 weeks ago
parent 0c9f3e5ed0
commit 67f7eaa65b

@ -31,6 +31,15 @@ __PACKAGE__->set_config({
Journal => [qw/admin reseller ccareadmin ccare/],
},
PATCH => { ops => [qw/add replace remove copy/] },
DELETE => {
query_params => [
{
param => 'unassign_first',
description => 'When provided, the set is unassigned from the places where it is used and only then deleted',
query_type => 'integer',
},
],
},
});
sub get_journal_methods{

@ -66,6 +66,15 @@ sub relation{
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller ccareadmin ccare subscriberadmin subscriber/],
DELETE => {
query_params => [
{
param => 'unassign_first',
description => 'When provided, the set is unassigned from the places where it is used first and only then deleted',
query_type => 'integer',
},
],
},
});
sub GET :Allow {

@ -41,7 +41,16 @@ __PACKAGE__->set_config({
allowed_roles => {
Default => [qw/admin reseller ccareadmin ccare subscriberadmin subscriber/],
Journal => [qw/admin reseller ccareadmin ccare/],
}
},
DELETE => {
query_params => [
{
param => 'unassign_first',
description => 'When provided, the set is unassigned from the places where it is used and only then deleted',
query_type => 'integer',
},
],
},
});
sub GET :Allow {

@ -43,6 +43,15 @@ __PACKAGE__->set_config({
Journal => [qw/admin reseller ccareadmin ccare/],
},
PATCH => { ops => [qw/add replace remove copy/] },
DELETE => {
query_params => [
{
param => 'unassign_first',
description => 'When provided, the set is unassigned from the places where it is used and only then deleted',
query_type => 'integer',
},
],
},
});
sub delete_item {

@ -348,6 +348,20 @@ sub generate_swagger_datastructure {
},
}
};
my $query_params = $col->{item_config}->{action}->{PUT}->{query_params};
push @{$item_p->{put}{parameters}},
{ '$ref' => '#/components/parameters/ItemIdParameter' };
for my $query_param (@{ $query_params // [] }) {
push @{$item_p->{put}{parameters}}, {
name => $query_param->{param},
description => $query_param->{description},
in => 'query',
schema => {type => $query_param->{query_type} // 'string'},
};
}
}
if (grep {m/^PATCH$/} @{ $col->{item_actions} }) {
@ -374,6 +388,20 @@ sub generate_swagger_datastructure {
},
}
};
my $query_params = $col->{item_config}->{action}->{PATCH}->{query_params};
push @{$item_p->{patch}{parameters}},
{ '$ref' => '#/components/parameters/ItemIdParameter' };
for my $query_param (@{ $query_params // [] }) {
push @{$item_p->{patch}{parameters}}, {
name => $query_param->{param},
description => $query_param->{description},
in => 'query',
schema => {type => $query_param->{query_type} // 'string'},
};
}
}
if (grep {m/^DELETE$/} @{ $col->{item_actions} }) {
@ -387,15 +415,26 @@ sub generate_swagger_datastructure {
},
}
};
my $query_params = $col->{item_config}->{action}->{DELETE}->{query_params};
push @{$item_p->{delete}{parameters}},
{ '$ref' => '#/components/parameters/ItemIdParameter' };
for my $query_param (@{ $query_params // [] }) {
push @{$item_p->{delete}{parameters}}, {
name => $query_param->{param},
description => $query_param->{description},
in => 'query',
schema => {type => $query_param->{query_type} // 'string'},
};
}
}
#push @paths, $p;
$paths{'/'.$chapter.'/'} = $p;
if (keys %{ $item_p }) {
$item_p->{description} = $col->{description};
$item_p->{parameters} = [
{ '$ref' => '#/components/parameters/ItemIdParameter' },
];
$paths{'/'.$chapter.'/{id}'} = $item_p;
}

Loading…
Cancel
Save