diff options
author | franck cuny <franck@lumberjaph.net> | 2010-10-14 13:30:27 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-10-14 13:30:27 +0200 |
commit | 273c039aa982f2b147f0b9a3eca06bf13801a2d0 (patch) | |
tree | 771d25f83481979609a47722d6d8ce7610446c9e | |
parent | no repo in list_all_repos (diff) | |
download | api-description-273c039aa982f2b147f0b9a3eca06bf13801a2d0.tar.gz |
add perl script to validate a specification
-rw-r--r-- | utils/validator.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/utils/validator.pl b/utils/validator.pl new file mode 100644 index 0000000..732de05 --- /dev/null +++ b/utils/validator.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use JSON; +use IO::All; +use Data::Rx; +use Getopt::Long; + +GetOptions( + 'schema=s' => \my $schema, + 'description=s' => \my $desc, +); + +my $rx = Data::Rx->new; + +my $schema_val = $rx->make_schema( read_from_json($schema) ); +my $res = $schema_val->check(read_from_json($desc)); + +if ($res) { + print "ok - $desc is a valide description\n;" +}else{ + print "nok - $desc is not a valide description\n"; +} + +sub read_from_json { + my ($file) = @_; + + my $schema < io $file; + my $schema_json = JSON::decode_json($schema); + $schema_json; +} |