The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Whelk::OpenAPI - Whelk's default OpenAPI generator class

SYNOPSIS

        # whelk_config.pl
        ###################
        {
                openapi => {
                        path => '/openapi',
                        class => 'MyOpenAPI',
                }
        }

        # MyOpenAPI.pm
        ################
        package MyOpenAPI;

        use Kelp::Base 'Whelk::OpenAPI';

        sub parse {
                my ($self, %data) = @_;

                # do the parsing differently
                ...
        }

        1;

DESCRIPTION

This class generates an OpenAPI document based on the API definition gathered by Whelk. It requires pretty specific setup and should probably not be manipulated by hand. It can be subclassed to change how the document looks.

This documentation page describes just the methods which are called from outside of the class. The rest of methods and all attributes are just implementation details.

METHODS

parse

        $openapi->parse(%data);

It's called at build time, after Whelk is finalized. It gets passed a hash %data with a couple of keys containing full data Whelk gathered. It should build most of the parts of the OpenAPI document, so that it will not be terribly slow to generate the document at runtime.

location_for_schema

        my $location = $openapi->location_for_schema($schema_name);

This helper should just return a string which will be put into '$ref' keys of the OpenAPI document to reference named schemas.

generate

        my $openapi_document_data = $openapi->generate;

This method should take all the data prepared by "parse" and return a hash reference with all the data of the OpenAPI document. This data will be then serialized using formatter declared in openapi configuration.