jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 57 forks source link

$ref are not resolved with get method #262

Closed elcamlost closed 2 years ago

elcamlost commented 2 years ago

Steps to reproduce the behavior

use 5.026;
use JSON::Validator;
use Data::Dumper;

my $jv = JSON::Validator->new;
$jv->schema({x => {'$ref' => '#/y'}, y => {'type' => 'string'}});

say Dumper($jv->schema->get('/x'));
say Dumper($jv->get('/x'));

Expected behavior

$jv->get('/x') prints

$VAR1 = {
          'type' => 'string'
        };

Actual behavior

$jv->get('/x') prints

$VAR1 = {
          '$ref' => '#/y'
        };
elcamlost commented 2 years ago

My real goal is to get resolved specification with $c->openapi->spec

jhthorsen commented 2 years ago

The title is not correct, but I can see that the current behavior is confusing so I will change it to do what you expect.

This is the behavior right now, but will be changed in 5.01: $jv->get('/x') returns {"$ref":"..."} $jv->get('/x/type') returns "string"

jhthorsen commented 2 years ago

This is now changed/fixed in d367eb8e3c22a27e4c5bfaea21faf12db8349e88.