File: update-schemas

package info (click to toggle)
libjson-schema-modern-perl 0.611-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,352 kB
  • sloc: perl: 3,935; makefile: 9
file content (78 lines) | stat: -rwxr-xr-x 3,864 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env perl
# vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et :
use strict;
use warnings;

use 5.020;
no autovivification warn => qw(fetch store exists delete);
use if "$]" >= 5.022, experimental => 're_strict';
no if "$]" >= 5.031009, feature => 'indirect';
no if "$]" >= 5.033001, feature => 'multidimensional';
no if "$]" >= 5.033006, feature => 'bareword_filehandles';
use Path::Tiny;
use HTTP::Tiny;
use Digest::MD5 'md5_hex';
use Test::File::ShareDir -share => { -dist => { 'JSON-Schema-Modern' => 'share' } };
use lib 'lib';
use JSON::Schema::Modern 0.578;

# ATTENTION DISTRO REPACKAGERS: do NOT use fresh copies of these files
# from their source; it is important to include the original versions
# of the files as they were packaged with this cpan distribution, or
# surprising behaviour may occur.

my %files = (
  'draft2020-12/meta/applicator.json'     => 'https://json-schema.org/draft/2020-12/meta/applicator',
  'draft2020-12/meta/content.json'        => 'https://json-schema.org/draft/2020-12/meta/content',
  'draft2020-12/meta/core.json'           => 'https://json-schema.org/draft/2020-12/meta/core',
  'draft2020-12/meta/format-annotation.json' => 'https://json-schema.org/draft/2020-12/meta/format-annotation',
  'draft2020-12/meta/format-assertion.json' => 'https://json-schema.org/draft/2020-12/meta/format-assertion',
  'draft2020-12/meta/meta-data.json'      => 'https://json-schema.org/draft/2020-12/meta/meta-data',
  'draft2020-12/meta/unevaluated.json'    => 'https://json-schema.org/draft/2020-12/meta/unevaluated',
  'draft2020-12/meta/validation.json'     => 'https://json-schema.org/draft/2020-12/meta/validation',
  'draft2020-12/output/schema.json'       => 'https://json-schema.org/draft/2020-12/output/schema',
  'draft2020-12/schema.json'              => 'https://json-schema.org/draft/2020-12/schema',

  'draft2019-09/meta/applicator.json'     => 'https://json-schema.org/draft/2019-09/meta/applicator',
  'draft2019-09/meta/content.json'        => 'https://json-schema.org/draft/2019-09/meta/content',
  'draft2019-09/meta/core.json'           => 'https://json-schema.org/draft/2019-09/meta/core',
  'draft2019-09/meta/format.json'         => 'https://json-schema.org/draft/2019-09/meta/format',
  'draft2019-09/meta/meta-data.json'      => 'https://json-schema.org/draft/2019-09/meta/meta-data',
  'draft2019-09/meta/validation.json'     => 'https://json-schema.org/draft/2019-09/meta/validation',
  'draft2019-09/output/schema.json'       => 'https://json-schema.org/draft/2019-09/output/schema',
  'draft2019-09/schema.json'              => 'https://json-schema.org/draft/2019-09/schema',

  'draft7/schema.json' => 'http://json-schema.org/draft-07/schema',
  'draft6/schema.json' => 'http://json-schema.org/draft-06/schema',
  'draft4/schema.json' => 'http://json-schema.org/draft-04/schema',

  'LICENSE' => 'https://raw.githubusercontent.com/json-schema-org/json-schema-spec/main/LICENSE',
);

my $js = JSON::Schema::Modern->new(validate_formats => 1);
my %checksums;

foreach my $target (keys %files) {
  my $source_uri = $files{$target};
  $target = path('share', $target);
  $target->parent->mkpath;

  my $response = HTTP::Tiny->new->get($source_uri);
  die "Failed to fetch $source_uri: $response->{status} $response->{reason}" if not $response->{success};

  $target->spew_raw($response->{content});
  $checksums{$target} = md5_hex($response->{content});

  next if $target->basename eq 'LICENSE';

  my $document = $js->get_document($source_uri);
  print '# validating ', $document->canonical_uri, "\n" if $ENV{DEBUG};
  my $result = $document->validate;
  die $result->dump if not $result->valid;
}

# compute checksums and record them in the test
path('t/checksums.t')->edit_raw(sub {
  m/^__DATA__$/mg;
  $_ = substr($_, 0, pos()+1).join("\n", map $_.' '.$checksums{$_}, sort keys %checksums)."\n";
});