View | Details | Raw Unified | Return to bug 30194
Collapse All | Expand All

(-)a/Koha/REST/V1.pm (-19 / +4 lines)
Lines 22-28 use Mojo::Base 'Mojolicious'; Link Here
22
use C4::Context;
22
use C4::Context;
23
use Koha::Logger;
23
use Koha::Logger;
24
24
25
use JSON::Validator::OpenAPI::Mojolicious;
25
use JSON::Validator::Schema;
26
use Try::Tiny qw( catch try );
26
use Try::Tiny qw( catch try );
27
27
28
=head1 NAME
28
=head1 NAME
Lines 68-74 sub startup { Link Here
68
        $self->secrets([$secret_passphrase]);
68
        $self->secrets([$secret_passphrase]);
69
    }
69
    }
70
70
71
    my $validator = JSON::Validator::OpenAPI::Mojolicious->new;
71
    my $validator = JSON::Validator::Schema->new( $self->home->rel_file("api/v1/swagger/swagger.yaml") );
72
72
73
    push @{$self->routes->namespaces}, 'Koha::Plugin';
73
    push @{$self->routes->namespaces}, 'Koha::Plugin';
74
74
Lines 76-87 sub startup { Link Here
76
    my $spec;
76
    my $spec;
77
    my $swagger_schema = $self->home->rel_file("api/swagger-v2-schema.json");
77
    my $swagger_schema = $self->home->rel_file("api/swagger-v2-schema.json");
78
    try {
78
    try {
79
        $spec = $validator->bundle(
79
        my $spec = $validator->bundle->data;
80
            {
81
                replace => 1,
82
                schema => $self->home->rel_file("api/v1/swagger/swagger.yaml")
83
            }
84
        );
85
80
86
        $self->plugin(
81
        $self->plugin(
87
            'Koha::REST::Plugin::PluginRoutes' => {
82
            'Koha::REST::Plugin::PluginRoutes' => {
Lines 95-104 sub startup { Link Here
95
                spec  => $spec,
90
                spec  => $spec,
96
                route => $self->routes->under('/api/v1')->to('Auth#under'),
91
                route => $self->routes->under('/api/v1')->to('Auth#under'),
97
                schema => ( $swagger_schema ) ? $swagger_schema : undef,
92
                schema => ( $swagger_schema ) ? $swagger_schema : undef,
98
                allow_invalid_ref =>
99
                1,    # required by our spec because $ref directly under
100
                        # Paths-, Parameters-, Definitions- & Info-object
101
                        # is not allowed by the OpenAPI specification.
102
            }
93
            }
103
        );
94
        );
104
    }
95
    }
Lines 111-120 sub startup { Link Here
111
        $logger->error("Warning: Could not load REST API spec bundle: " . $_);
102
        $logger->error("Warning: Could not load REST API spec bundle: " . $_);
112
103
113
        try {
104
        try {
114
            $validator->load_and_validate_schema(
105
            $validator->schema(
115
                $self->home->rel_file("api/v1/swagger/swagger.yaml"),
106
                $self->home->rel_file("api/v1/swagger/swagger.yaml"),
116
                {
107
                {
117
                    allow_invalid_ref  => 1,
118
                    schema => ( $swagger_schema ) ? $swagger_schema : undef,
108
                    schema => ( $swagger_schema ) ? $swagger_schema : undef,
119
                }
109
                }
120
            );
110
            );
Lines 131-140 sub startup { Link Here
131
                OpenAPI => {
121
                OpenAPI => {
132
                    spec  => $spec,
122
                    spec  => $spec,
133
                    route => $self->routes->under('/api/v1')->to('Auth#under'),
123
                    route => $self->routes->under('/api/v1')->to('Auth#under'),
134
                    allow_invalid_ref =>
135
                    1,    # required by our spec because $ref directly under
136
                            # Paths-, Parameters-, Definitions- & Info-object
137
                            # is not allowed by the OpenAPI specification.
138
                }
124
                }
139
            );
125
            );
140
        }
126
        }
141
- 

Return to bug 30194