NAME
OpenAPI::PerlGenerator - create Perl client SDKs from OpenAPI specs
SYNOPSIS
my $api_file = slurp( 'petshop.json' );
my $schema = JSON::PP->new()->decode( $api_file );
my @files = $gen->generate(
schema => $schema,
prefix => "My::API",
);
This module generates Perl clients for an OpenAPI spec. It generates a class for each item in the components/schemas
section. It generates $prefix::Client::Impl
as the implementation class of the client and a stub $prefix::Client
class for overriding or refining the autogenerated class.
METHODS
new
Options
schema
A data structure for the OpenAPI schema
templates
A hashref of templates to use
prefix
The prefix for the modules to use
tidy
Run the resulting code through Perl::Tidy.
Default is true.
typemap
Hashref with the mapping of OpenAPI types to Type::Tiny constraints.
METHODS
->render( $name, $args )
my $str = $gen->render('template_body', { prefix => 'My::API' } );
Render a template
<< ->generate( %options ) >>
my @output = $gen->generate();
for my $package (@output) {
say "Generating " . $package->{package};
say $package->{source};
}
Generate the packages from the templates.
->load_schema( %options )
my $res = $gen->load_schema(
schema => $schema,
prefix => 'My::Schema',
);
Compiles the packages and installs them in the current process with the namespace given.
REPOSITORY
The public repository of this module is https://github.com/Corion/OpenAPI-PerlGenerator.
SUPPORT
The public support forum of this module is https://perlmonks.org/.
BUG TRACKER
Please report bugs in this module via the Github bug queue at https://github.com/Corion/OpenAPI-PerlGenerator/issues
AUTHOR
Max Maischein corion@cpan.org
COPYRIGHT (c)
Copyright 2024- by Max Maischein corion@cpan.org
.
LICENSE
This module is released under the Artistic License 2.0.