[tpm] Tonight's meeting is online and starting at 7 pm
Yanick Champoux
yanick at babyl.ca
Thu May 28 17:09:52 PDT 2026
To follow-up on the naive schema creator:
#!/usr/bin/env perl
use 5.42.0;
use warnings;
use Ref::Util qw/ is_plain_arrayref is_plain_hashref /;
use List::Util qw/ pairmap /;
use builtin 'created_as_number';
use YAML;
use File::Serialize;
my $example = deserialize_file shift;
say YAML::Dump( schematize($example) );
sub schematize($example) {
my %schema;
if ( is_plain_hashref $example ) {
$schema{type} = 'object';
$schema{properties} = +{ pairmap { $a => schematize($b) } %$example };
}
elsif ( is_plain_arrayref $example ) {
$schema{type} = 'array';
$schema{items} = { anyOf => [ map { schematize($_) } @$example ] };
}
else {
$schema{type} = created_as_number $example ? 'number' : 'string';
}
return \%schema;
}
__END__
It's not clever, but it'll provide you with a starting skeleton. And something to think about with those super-complex documents is those { $ref: .. } links to keep things small and manageable.
Joy,
`/anick
On Thu, 28 May 2026, at 6:17 PM, Olaf Alders wrote:
>
> https://luma.com/k73djcf1
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> https://mail.pm.org/mailman/listinfo/toronto-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20260528/cfa94433/attachment.html>
More information about the toronto-pm
mailing list