* [pdm-devel] [PATCH proxmox-api-types 1/1] generator: support methods with no parameters
@ 2025-02-04 13:14 Stefan Hanreich
2025-02-05 13:03 ` Wolfgang Bumiller
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hanreich @ 2025-02-04 13:14 UTC (permalink / raw)
To: pdm-devel
Some methods (e.g. 'PUT cluster/sdn') do not take any input
parameters. Support those methods by generating them with unit type as
type for the input parameters.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
pve-api-types/generator-lib/Schema2Rust.pm | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pve-api-types/generator-lib/Schema2Rust.pm b/pve-api-types/generator-lib/Schema2Rust.pm
index 068517e..554341d 100644
--- a/pve-api-types/generator-lib/Schema2Rust.pm
+++ b/pve-api-types/generator-lib/Schema2Rust.pm
@@ -535,7 +535,8 @@ my sub print_method_with_body : prototype($$$$$) {
my ($arg, $def) = @$url_arg;
print {$out} " $arg: $def->{type},\n";
}
- print {$out} " params: $def->{input_type},\n";
+ my $input = $def->{input_type} // '()';
+ print {$out} " params: $input,\n";
my $output = $def->{output_type} // '()';
print {$out} ") -> Result<$output, Error> {\n";
if ($trait) {
--
2.39.5
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pdm-devel] [PATCH proxmox-api-types 1/1] generator: support methods with no parameters
2025-02-04 13:14 [pdm-devel] [PATCH proxmox-api-types 1/1] generator: support methods with no parameters Stefan Hanreich
@ 2025-02-05 13:03 ` Wolfgang Bumiller
2025-02-05 13:39 ` Stefan Hanreich
0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Bumiller @ 2025-02-05 13:03 UTC (permalink / raw)
To: Stefan Hanreich; +Cc: pdm-devel
On Tue, Feb 04, 2025 at 02:14:49PM +0100, Stefan Hanreich wrote:
> Some methods (e.g. 'PUT cluster/sdn') do not take any input
> parameters. Support those methods by generating them with unit type as
> type for the input parameters.
>
> Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
> ---
> pve-api-types/generator-lib/Schema2Rust.pm | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/pve-api-types/generator-lib/Schema2Rust.pm b/pve-api-types/generator-lib/Schema2Rust.pm
> index 068517e..554341d 100644
> --- a/pve-api-types/generator-lib/Schema2Rust.pm
> +++ b/pve-api-types/generator-lib/Schema2Rust.pm
> @@ -535,7 +535,8 @@ my sub print_method_with_body : prototype($$$$$) {
> my ($arg, $def) = @$url_arg;
> print {$out} " $arg: $def->{type},\n";
> }
> - print {$out} " params: $def->{input_type},\n";
> + my $input = $def->{input_type} // '()';
> + print {$out} " params: $input,\n";
This would produce an explicit parameter of type `()` - why not just
drop `params` when we have none?
> my $output = $def->{output_type} // '()';
> print {$out} ") -> Result<$output, Error> {\n";
> if ($trait) {
> --
> 2.39.5
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pdm-devel] [PATCH proxmox-api-types 1/1] generator: support methods with no parameters
2025-02-05 13:03 ` Wolfgang Bumiller
@ 2025-02-05 13:39 ` Stefan Hanreich
2025-02-05 14:01 ` Wolfgang Bumiller
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hanreich @ 2025-02-05 13:39 UTC (permalink / raw)
To: Wolfgang Bumiller; +Cc: pdm-devel
On 2/5/25 14:03, Wolfgang Bumiller wrote:
> This would produce an explicit parameter of type `()` - why not just
> drop `params` when we have none?
I did it, because the http client's post method required a 'param'
parameter for post calls, I didn't see that there's post_without_body
available.
We could try to catch this by checking if there is an input-type and, if
not, generate the method with the `post_without_body` method of the http
client instead?
Alternatively, we could check in the print_implementation call and use
`print_method_without_body` depending on the input-type / input defs?
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pdm-devel] [PATCH proxmox-api-types 1/1] generator: support methods with no parameters
2025-02-05 13:39 ` Stefan Hanreich
@ 2025-02-05 14:01 ` Wolfgang Bumiller
0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2025-02-05 14:01 UTC (permalink / raw)
To: Stefan Hanreich; +Cc: pdm-devel
On Wed, Feb 05, 2025 at 02:39:12PM +0100, Stefan Hanreich wrote:
> On 2/5/25 14:03, Wolfgang Bumiller wrote:
> > This would produce an explicit parameter of type `()` - why not just
> > drop `params` when we have none?
>
> I did it, because the http client's post method required a 'param'
> parameter for post calls, I didn't see that there's post_without_body
> available.
>
> We could try to catch this by checking if there is an input-type and, if
> not, generate the method with the `post_without_body` method of the http
> client instead?
>
> Alternatively, we could check in the print_implementation call and use
> `print_method_without_body` depending on the input-type / input defs?
I think making this distinction in `print_implementation` (and
`print_trait`) makes sense.
The client's methods are all now wrapping `.request()` - it *may* be
nicer to distinguish the cases *only* this way and use the
`$http_method` as the method parameter to the client's `.request()`
instead of mapping http methods to client wrapper methods... (But this
can be done later...)
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-05 14:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-04 13:14 [pdm-devel] [PATCH proxmox-api-types 1/1] generator: support methods with no parameters Stefan Hanreich
2025-02-05 13:03 ` Wolfgang Bumiller
2025-02-05 13:39 ` Stefan Hanreich
2025-02-05 14:01 ` Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox