SQL-Translator-Parser-OpenAPI
view release on metacpan or search on metacpan
t/00-compile.t
t/00-report-prereqs.t
t/01-corpus.json
t/01-schema.t
t/02-bigint.t
t/03-corpus.json
t/03-schema.t
t/04-corpus.json
t/04-schema.t
t/06-corpus.json
t/06-corpus.json.overlay
t/06-schema.t
t/07-corpus.json
t/07-schema.t
t/lib/JTTest.pm
t/snapshots/01-schema_t/schema
t/snapshots/03-schema_t/schema
t/snapshots/04-schema_t/schema
t/snapshots/06-schema_t/schema
t/snapshots/06-schema_t/schema_camel
t/snapshots/07-schema_t/schema
use SQL::Translator::Parser::OpenAPI;
my $translator = SQL::Translator->new;
$translator->parser("OpenAPI");
$translator->producer("YAML");
$translator->translate($file);
# or...
$ sqlt -f OpenAPI -t MySQL <my-openapi.json >my-mysqlschema.sql
# or, applying an overlay:
$ perl -MHash::Merge=merge -Mojo \
-e 'print j merge map j(f($_)->slurp), @ARGV' \
t/06-corpus.json t/06-corpus.json.overlay |
sqlt -f OpenAPI -t MySQL >my-mysqlschema.sql
# DESCRIPTION
This module implements a [SQL::Translator::Parser](https://metacpan.org/pod/SQL%3A%3ATranslator%3A%3AParser) to convert
a [JSON::Validator::OpenAPI::Mojolicious](https://metacpan.org/pod/JSON%3A%3AValidator%3A%3AOpenAPI%3A%3AMojolicious) specification to a [SQL::Translator::Schema](https://metacpan.org/pod/SQL%3A%3ATranslator%3A%3ASchema).
It uses, from the given API spec, the given "definitions" to generate
tables in an RDBMS with suitable columns and types.
lib/SQL/Translator/Parser/OpenAPI.pm view on Meta::CPAN
use SQL::Translator::Parser::OpenAPI;
my $translator = SQL::Translator->new;
$translator->parser("OpenAPI");
$translator->producer("YAML");
$translator->translate($file);
# or...
$ sqlt -f OpenAPI -t MySQL <my-openapi.json >my-mysqlschema.sql
# or, applying an overlay:
$ perl -MHash::Merge=merge -Mojo \
-e 'print j merge map j(f($_)->slurp), @ARGV' \
t/06-corpus.json t/06-corpus.json.overlay |
sqlt -f OpenAPI -t MySQL >my-mysqlschema.sql
=head1 DESCRIPTION
This module implements a L<SQL::Translator::Parser> to convert
a L<JSON::Validator::OpenAPI::Mojolicious> specification to a L<SQL::Translator::Schema>.
It uses, from the given API spec, the given "definitions" to generate
tables in an RDBMS with suitable columns and types.
t/lib/JTTest.pm view on Meta::CPAN
sub run_test {
my ($snake_case) = @_;
(my $file = $0) =~ s#schema\.t$#corpus.json#;
$file =~ s#json$#yml# if !-f $file;
die "$file: $!" if !-f $file;
require JSON::Validator::OpenAPI::Mojolicious; # loads JSON and YAML loaders
my $openapi_schema = JSON::Validator::OpenAPI::Mojolicious->new->schema($file)->schema->data;
my $overlay = "$file.overlay";
if (-f $overlay) {
my $data = do { open my $fh, $overlay or die "$overlay: $!"; local $/; <$fh> };
my $overlay_data = $file =~ /json$/
? Mojo::JSON::decode_json($data)
: YAML::XS::Load($data);
require Hash::Merge;
$openapi_schema = Hash::Merge::merge($openapi_schema, $overlay_data);
}
my $translator = SQL::Translator->new;
$translator->parser("OpenAPI");
$translator->parser_args(snake_case => $snake_case);
$translator->producer("SQLite");
my $got = $translator->translate(data => $openapi_schema);
if ($got) {
my @lines = split /\n/, $got;
( run in 1.497 second using v1.01-cache-2.11-cpan-49f99fa48dc )