File: openapiv2-bundle.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 (53 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
52
53
use Mojo::Base -strict;
use JSON::Validator::Schema::OpenAPIv2;
use JSON::Validator::Util qw(str2data);
use Mojo::Loader qw(data_section);
use Test::Deep;
use Test::More;

my $cwd    = Mojo::File->new(__FILE__)->dirname;
my $schema = JSON::Validator::Schema::OpenAPIv2->new($cwd->child(qw(spec v2-bundle.yaml)));
is_deeply $schema->errors, [], 'schema errors' or diag explain $schema->errors;

my $bundle = $schema->bundle;
is_deeply $bundle->errors, [], 'bundle errors' or diag explain $bundle->errors;

my $from_data = JSON::Validator::Schema::OpenAPIv2->new($bundle->data);
is_deeply $from_data->errors, [], 'from_data errors' or diag explain $from_data->errors;

is_deeply $from_data->data, str2data(data_section(qw(main exp.yaml))), 'from_data schema'
  or diag explain $from_data->data;

done_testing;

__DATA__
@@ exp.yaml
---
swagger: "2.0"
info:
  title: Bundled
  version: "1.0"
basePath: /api
paths:
  /user:
    get:
      parameters:
        - $ref: "#/parameters/paths_yaml-parameters_id"
      responses:
        200:
          description: A user
          schema:
            $ref: "#/x-def/User"

x-def:
  User:
    properties:
      name:
        type: string

parameters:
  paths_yaml-parameters_id:
    in: path
    name: id
    required: true
    type: string