File: openapiv2-file.t

package info (click to toggle)
libjson-validator-perl 5.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,160 kB
  • sloc: perl: 3,015; makefile: 14
file content (39 lines) | stat: -rw-r--r-- 996 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
use Mojo::Base -strict;
use JSON::Validator;
use Test::More;

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

for my $image (undef, '') {
  $form   = {image => '', id => 'i1'};
  @errors = $schema->validate_request([post => '/pets'], {formData => $form});
  is "@errors", '/image: Missing property.', 'missing image';
}

$form   = {image => '0', id => 'i1'};
@errors = $schema->validate_request([post => '/pets'], {formData => $form});
is "@errors", '', 'valid input';

done_testing;

__DATA__
@@ spec.json
{
  "swagger": "2.0",
  "info": {"version": "0.8", "title": "Test body"},
  "basePath": "/api",
  "paths": {
    "/pets": {
      "post": {
        "parameters": [
          {"name": "image", "in": "formData", "type": "file", "required": true},
          {"name": "id", "in": "formData", "type": "string"}
        ],
        "responses": {
          "200": {"description": "ok", "schema": {"type": "object"}}
        }
      }
    }
  }
}