]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/RESTHandler.pm
rest: register method: allow minus in path template parameter names
[pve-common.git] / src / PVE / RESTHandler.pm
index 5e8278e9a016c2f447443e535995125c0c381f35..1eea32ac57bef2701e54d3b53ef61396f16f145f 100644 (file)
@@ -242,6 +242,9 @@ sub register_method {
        $errprefix = "register method ${self}/$info->{path} -";
        $info->{method} = 'GET' if !$info->{method};
        $method = $info->{method};
+
+       # apply default value
+       $info->{allowtoken} = 1 if !defined($info->{allowtoken});
     }
 
     $method_path_lookup->{$self} = {} if !defined($method_path_lookup->{$self});
@@ -252,9 +255,9 @@ sub register_method {
     foreach my $comp (split(/\/+/, $info->{path})) {
        die "$errprefix path compoment has zero length\n" if $comp eq '';
        my ($name, $regex);
-       if ($comp =~ m/^\{(\w+)(:(.*))?\}$/) {
+       if ($comp =~ m/^\{([\w-]+)(?::(.*))?\}$/) {
            $name = $1;
-           $regex = $3 ? $3 : '\S+';
+           $regex = $2 ? $2 : '\S+';
            push @$match_re, $regex;
            push @$match_name, $name;
        } else {
@@ -618,7 +621,10 @@ sub getopt_usage {
 
     my $schema = $info->{parameters};
     my $name = $info->{name};
-    my $prop = { %{$schema->{properties}} }; # copy
+    my $prop =  {};
+    if ($schema->{properties}) {
+       $prop = { %{$schema->{properties}} }; # copy
+    }
 
     my $has_output_format_option = $formatter_properties->{'output-format'} ? 1 : 0;