File: openapiv2-invalid-ref.t

package info (click to toggle)
libjson-validator-perl 4.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 828 kB
  • sloc: perl: 2,816; makefile: 14
file content (44 lines) | stat: -rw-r--r-- 995 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use Mojo::Base -strict;
use JSON::Validator::Schema::OpenAPIv2;
use Test::Deep;
use Test::More;

my $schema = JSON::Validator::Schema::OpenAPIv2->new;
my $errors;

$errors = $schema->data('data://main/schema.json')->errors;
like "@$errors", qr{Properties not allowed}, 'invalid schema';

$errors = $schema->allow_invalid_ref(1)->errors;
is "@$errors", '', 'allow_invalid_ref after loading schema';

$errors = $schema->allow_invalid_ref(1)->data('data://main/schema.json')->errors;
is "@$errors", '', 'allow_invalid_ref before loading schema';

done_testing;

__DATA__
@@ schema.json
{
  "swagger": "2.0",
  "info": { "version": "1.0.0", "title": "Invalid schema" },
  "paths": {
    "/pets": {
      "post": { "$ref": "#/x-ref/postPets" }
    }
  },
  "x-ref": {
    "postPets": {
      "responses": {
        "200": {
          "description": "An paged array of pets",
          "schema": { "$ref": "#/definitions/Pet" }
        }
      }
    }
  },
  "definitions": {
    "Pet": {
    }
  }
}