Эх сурвалжийг харах

Write the document's booleans as perl's own true

tPSGI now takes the true that use 5.040 imports, so the routes no longer
need Mojo::JSON::true or the Mojo::JSON prerequisite.  t/TCMS.t checks the
document as JSON reads it, because a native true does not pass
JSON::Validator's own enum check and tPSGI is not a prerequisite of tCMS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot 6 өдөр өмнө
parent
commit
9afc30aabf
4 өөрчлөгдсөн 10 нэмэгдсэн , 9 устгасан
  1. 0 1
      Makefile.PL
  2. 1 2
      lib/TCMS.pm
  3. 1 3
      lib/Trog/Routes/JSON.pm
  4. 8 3
      t/TCMS.t

+ 0 - 1
Makefile.PL

@@ -123,7 +123,6 @@ WriteMakefile(
         'Sys::Hostname::FQDN'                 => '0',
         'List::Util'                          => '0',
         'Mojo::File'                          => '0',
-        'Mojo::JSON'                          => '0',
         'POSIX'                               => '0',
         'Ref::Util'                           => '0',
         'Pod::Html'                           => '0',

+ 1 - 2
lib/TCMS.pm

@@ -9,7 +9,6 @@ use Clone qw{clone};
 
 use CGI::Cookie ();
 use URI();
-use Mojo::JSON ();
 
 #Grab our custom routes
 use FindBin::libs;
@@ -213,7 +212,7 @@ sub build_routes {
         my @parameters = @{ $v->{parameters} // [] };
         foreach my $variable ( $k =~ m/\{([^{}]+)\}/g ) {
             next if grep { $_->{in} eq 'path' && $_->{name} eq $variable } @parameters;
-            push( @parameters, { name => $variable, in => 'path', required => Mojo::JSON::true, schema => { type => 'string' } } );
+            push( @parameters, { name => $variable, in => 'path', required => true, schema => { type => 'string' } } );
         }
 
         $paths{$k}{$method} = {

+ 1 - 3
lib/Trog/Routes/JSON.pm

@@ -6,8 +6,6 @@ use warnings FATAL => 'all';
 
 use Clone qw{clone};
 
-use Mojo::JSON ();
-
 use Trog::Utils();
 use Trog::Auth();
 use Trog::Routes::HTML();
@@ -36,7 +34,7 @@ our %routes = (
             {
                 name     => 'token',
                 in       => 'path',
-                required => Mojo::JSON::true,
+                required => true,
 
                 # What Trog::Utils::uuid() makes, ended by \z because perl's $ allows a final newline.
                 schema => { type => 'string', pattern => '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z' },

+ 8 - 3
t/TCMS.t

@@ -11,6 +11,7 @@ use lib "$FindBin::Bin/../lib";
 
 use Test::More;
 use Test::MockModule                   qw{strict};
+use JSON::MaybeXS                      ();
 use JSON::Validator::Schema::OpenAPIv3 ();
 
 our ( $REPO, $ROOT, $OLDCWD );
@@ -63,8 +64,12 @@ $html->redefine( posts => sub { return [ 200, [], ['the post'] ] } );
 require_ok('TCMS') or BAIL_OUT("Can't load the dispatcher");
 
 my %openapi = %TCMS::openapi;
-my $schema  = JSON::Validator::Schema::OpenAPIv3->new( \%openapi );
-my $paths   = $openapi{paths};
+
+# Checked as JSON reads it, since tPSGI is not a prerequisite of tCMS: perl's
+# booleans become JSON's, and a callback becomes null.
+my $json   = JSON::MaybeXS->new( allow_unknown => 1, canonical => 1 );
+my $schema = JSON::Validator::Schema::OpenAPIv3->new( $json->decode( $json->encode( \%openapi ) ) );
+my $paths  = $openapi{paths};
 
 subtest 'the document' => sub {
     is_deeply( $schema->errors, [], 'is valid OpenAPI 3' ) or diag explain $schema->errors;
@@ -79,7 +84,7 @@ subtest 'an operation' => sub {
     is( $manual->{'x-tcms-auth'},          1,      'and its auth as x-tcms-auth' );
     is_deeply(
         $manual->{parameters},
-        [ { name => 'module+', in => 'path', required => Mojo::JSON::true, schema => { type => 'string' } } ],
+        [ { name => 'module+', in => 'path', required => true, schema => { type => 'string' } } ],
         'and each variable of the template as a required path parameter'
     );