shipped ThaiSchema 0.03

ThaiSchema is yet another data validation library, especially JSON.

This is a test code from Ukigumo. You can check a types in JSON, easily.

use ThaiSchema;
use ThaiSchema::JSON;
use LWP::UserAgent;
use Test::More;

my $ua = LWP::UserAgent->new();
    my $res = $ua->get(
        'http://localhost/api/v1/branch/list?project=TestingProject',
    );
	is $res->code, 200;
	note $res->content;
    my ($ok, $errors) = ThaiSchema::JSON->new()->validate($res->content, type_hash({
        branches => type_array({
            branch    => type_str(),
            ctime     => type_int,
            revision  => type_str(),
            project   => type_str(),
            status    => type_int(),
            report_id => type_int(),
        })
    }));
    ok $ok;
    diag $_ for @$errors;

my $dat = decode_json($res->content);
    is $dat->{branches}->[0]->{branch}, 'master';

done_testing;

Normally, Perl5 does not cares types. It makes ugly JSON APIs. It makes unexpected type change in API response. You can use typester's JSON::Types module to specify the types. And you can validate types by ThaiSchema.

Thanks,

Published: 2012-11-19(Mon) 01:31