File: openapiv2-default-values.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 (43 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (3)
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
use Mojo::Base -strict;
use JSON::Validator;
use Test::More;

my $schema = JSON::Validator->new->schema('data://main/spec.json')->schema;
my @errors;

@errors = $schema->validate_request([get => '/pets/{id}'], {path => {id => 'a'}});
is "@errors", "/id: String is too short: 1/3.", 'invalid id';

@errors = $schema->validate_request([get => '/pets/{id}'], {path => {}});
is "@errors", "", 'default id';

my $id  = {};
my %req = (path => sub {$id});
@errors = $schema->validate_request([get => '/pets/{id}'], \%req);
is_deeply $id, {exists => 1, in => 'path', name => 'id', valid => 1, value => 'foo'}, 'input was mutated';
is "@errors", "", 'default id';

done_testing;

__DATA__
@@ spec.json
{
  "swagger": "2.0",
  "info": {"version": "", "title": "Test default values"},
  "basePath": "/api",
  "paths": {
    "/pets/{id}": {
      "get": {
        "parameters": [
          {"name": "id", "in": "path", "type": "string", "default": "foo", "required": true, "minLength": 3}
        ],
        "responses" : {
          "200": {
            "description": "pet response",
            "schema": {"type": "object"}
          }
        }
      }
    }
  }
}