Closed christopherraa closed 3 years ago
I think the test below illustrates the same issue, which is that all refs in an OpenAPIv2 schema is placed under "definitions" instead of both "definitions" and "responses".
use Mojo::Base -strict;
use JSON::Validator::Schema::OpenAPIv2;
use Test::More;
my $schema = JSON::Validator::Schema::OpenAPIv2->new('data://main/spec.yaml');
is_deeply $schema->errors, [], 'valid spec' or diag explain($schema->errors);
my $bundled = $schema->bundle;
is_deeply $bundled->errors, [], 'valid bundled spec' or diag explain($bundled->errors);
ok $bundled->get('/definitions/error_response'), 'error_response in definitions';
ok $bundled->get('/parameters/error_response'), 'error_response in parameters';
ok $bundled->get('/responses/bad_request'), 'bad_request in responses';
done_testing;
__DATA__
@@ spec.yaml
---
swagger: "2.0"
info:
title: Silly API
version: 0.0.1
basePath: /v1/api
paths:
/silly:
post:
summary: Create a new silly thing
description: Create a new kind of silly thing. Don't know how.
parameters:
- $ref: "#/parameters/silly_body"
responses:
400:
$ref: "#/responses/bad_request"
definitions:
error_response:
type: object
required:
- status
- message
properties:
status:
type: integer
format: int32
message:
type: string
parameters:
silly_body:
in: body
name: body
description: Payload with some silly stuff
required: true
schema:
$ref: "#/definitions/error_response"
responses:
bad_request:
description: Doing bad things.
schema:
$ref: "#/definitions/error_response"
This a JSON::Validator bug, but I'll keep this issue open as reference.
I think this has been fixed in https://github.com/jhthorsen/json-validator/commit/8b451ba4adc4420fb80d77709163649f7b451d61
Going to make a new release shortly that depend on JSON::Validator 4.16.
What is happening?
If you give a valid specification to
Mojolicious::Plugin::OpenAPI
it loads it just fine. Something is also rendered on/$basePath
, but neither is it the same spec nor is it a valid spec. When trying to consume that spec with egOpenAPI::Client
the following errors are thrown:What is expected behaviour?
I expect that SpecRenderer will render the specification, or at least some kind of valid specification.
Steps to reproduce
morbo myapp.pl
)./myclient.pl
)Hilarity ensues.
Versions
Mojolicious
9.01OpenAPI::Client
1.00Mojolicious::Plugin::OpenAPI
4.0