From 67f7eaa65bcbd8c46ef5875d2145f47efbc043e7 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Tue, 21 Jul 2026 20:26:17 +0200 Subject: [PATCH] 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 --- .../Panel/Controller/API/CFBNumberSetsItem.pm | 9 ++++ lib/NGCP/Panel/Controller/API/CFSourceSets.pm | 9 ++++ .../Panel/Controller/API/CFSourceSetsItem.pm | 11 ++++- .../Panel/Controller/API/CFTimeSetsItem.pm | 9 ++++ lib/NGCP/Panel/Utils/API.pm | 45 +++++++++++++++++-- 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/CFBNumberSetsItem.pm b/lib/NGCP/Panel/Controller/API/CFBNumberSetsItem.pm index 0bc6bf0b33..136169a775 100644 --- a/lib/NGCP/Panel/Controller/API/CFBNumberSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/CFBNumberSetsItem.pm @@ -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{ diff --git a/lib/NGCP/Panel/Controller/API/CFSourceSets.pm b/lib/NGCP/Panel/Controller/API/CFSourceSets.pm index 8fead877e2..82f1fbca5f 100644 --- a/lib/NGCP/Panel/Controller/API/CFSourceSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFSourceSets.pm @@ -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 { diff --git a/lib/NGCP/Panel/Controller/API/CFSourceSetsItem.pm b/lib/NGCP/Panel/Controller/API/CFSourceSetsItem.pm index 72436ede50..ae545e8dae 100644 --- a/lib/NGCP/Panel/Controller/API/CFSourceSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/CFSourceSetsItem.pm @@ -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 { diff --git a/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm b/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm index 42956f496b..5d7aa00b32 100644 --- a/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/CFTimeSetsItem.pm @@ -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 { diff --git a/lib/NGCP/Panel/Utils/API.pm b/lib/NGCP/Panel/Utils/API.pm index 7fbe6edd0c..d9d79d0537 100644 --- a/lib/NGCP/Panel/Utils/API.pm +++ b/lib/NGCP/Panel/Utils/API.pm @@ -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; }