about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-10-14 13:30:27 +0200
committerfranck cuny <franck@lumberjaph.net>2010-10-14 13:30:27 +0200
commit273c039aa982f2b147f0b9a3eca06bf13801a2d0 (patch)
tree771d25f83481979609a47722d6d8ce7610446c9e
parentno repo in list_all_repos (diff)
downloadapi-description-273c039aa982f2b147f0b9a3eca06bf13801a2d0.tar.gz
add perl script to validate a specification
-rw-r--r--utils/validator.pl33
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;
+}