
[![Windows](https://github.com/Corion/OpenAPI-PerlGenerator/workflows/windows/badge.svg)](https://github.com/Corion/OpenAPI-PerlGenerator/actions?query=workflow%3Awindows)
[![MacOS](https://github.com/Corion/OpenAPI-PerlGenerator/workflows/macos/badge.svg)](https://github.com/Corion/OpenAPI-PerlGenerator/actions?query=workflow%3Amacos)
[![Linux](https://github.com/Corion/OpenAPI-PerlGenerator/workflows/linux/badge.svg)](https://github.com/Corion/OpenAPI-PerlGenerator/actions?query=workflow%3Alinux)

# 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](https://metacpan.org/pod/Perl%3A%3ATidy).

    Default is true.

- **typemap**

    Hashref with the mapping of OpenAPI types to [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny) 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](https://github.com/Corion/OpenAPI-PerlGenerator).

# SUPPORT

The public support forum of this module is [https://perlmonks.org/](https://perlmonks.org/).

# BUG TRACKER

Please report bugs in this module via the Github bug queue at
[https://github.com/Corion/OpenAPI-PerlGenerator/issues](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.
