Last active
August 29, 2015 14:24
-
-
Save mrenvoize/e8a5574429cc7f7211b5 to your computer and use it in GitHub Desktop.
SchemaValidator following $ref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"type": "object", | |
"properties": { | |
"published": { | |
"type": "boolean" | |
}, | |
"embeded": { | |
"$ref": "#/definitions/embeded" | |
} | |
}, | |
"additionalProperties": false, | |
"required": [ | |
"published", | |
"embeded" | |
], | |
"definitions": { | |
"embeded": { | |
"type": "object", | |
"properties": { | |
"prop1": { | |
"type": "string" | |
}, | |
"prop2": { | |
"type": "integer" | |
} | |
}, | |
"required": [ | |
"prop1", | |
"prop2" | |
] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"published": false, | |
"embeded": { | |
"prop1": "string", | |
"prop2": 2 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use FindBin; | |
BEGIN { unshift @INC, "$FindBin::Bin/../lib" } | |
use Data::Printer colored => 1; | |
use JSON; | |
use Swagger2::SchemaValidator; | |
use File::Slurp; | |
my $validator = Swagger2::SchemaValidator->new; | |
my $schema = read_file( "list-schema.json" ) or die "cannot open < list-schema.json: $!"; | |
my $schema_ref = from_json( $schema ); | |
my $list = read_file( "list.json") or die "cannot open < list.json: $!"; | |
my $list_json = from_json($list); | |
my @errors = $validator->validate($list_json, $schema_ref); | |
print "Error: " . p( @errors ); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment