jhthorsen / json-validator

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

heisenbug with openapi 3.1.* schema #272

Open vividsnow opened 7 months ago

vividsnow commented 7 months ago

Steps to reproduce the behavior

Given script:

use strict;
use JSON::Validator::Schema::OpenAPIv3;

my $yaml = <<~\in;
openapi: 3.1.0

info:
  version: 1.0
  title: whatever

components:
  parameters:
    Id:
      in: path
      name: id
      schema:
        $ref: '#/components/schemas/IdType'
      required: true

  schemas:
    IdType:
      type: integer
in

my ($ok, $nok) = (0, 0);
for (1..100) {
    my $js = JSON::Validator::Schema::OpenAPIv3->new(
        $yaml,
        specification => 'https://spec.openapis.org/oas/3.1/schema/2021-05-20'
    );
    $ok++, next unless $js->is_invalid;
    $nok++;
    print "$_\n" for @{$js->errors};
}
print "ok: $ok, nok: $nok\n";

running as perl -E 'system q(perl json-validator.pl) for 1..10'

Expected behavior

Expecting having valid schema every run:

...
ok: 100, nok: 0
...

Actual behavior

Getting random fails:

ok: 100, nok: 0
/components/parameters/Id/$ref: Missing property.
...
ok: 95, nok: 5
/components/parameters/Id/$ref: Missing property.
...
ok: 97, nok: 3
ok: 100, nok: 0
ok: 100, nok: 0
/components/parameters/Id/$ref: Missing property.
...
ok: 97, nok: 3
/components/parameters/Id/$ref: Missing property.
...
ok: 95, nok: 5
/components/parameters/Id/$ref: Missing property.
...
ok: 86, nok: 14
/components/parameters/Id/$ref: Missing property.
...
ok: 97, nok: 3
/components/parameters/Id/$ref: Missing property.
...
ok: 96, nok: 4