Skip to content

Commit

Permalink
fix url metacharacters in JSON $ref URLs
Browse files Browse the repository at this point in the history
This should silence some warnings from the OpenAPI spec validator on
swagger.io: http://editor.swagger.io

Refs #38
  • Loading branch information
preaction committed Dec 31, 2018
1 parent 594d55b commit 42d5079
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/Mojolicious/Plugin/Yancy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ use Mojo::JSON qw( true false );
use Mojo::File qw( path );
use Mojo::JSON qw( decode_json );
use Mojo::Loader qw( load_class );
use Mojo::Util qw( url_escape );
use Sys::Hostname qw( hostname );
use Yancy::Util qw( load_backend curry );
use JSON::Validator::OpenAPI;
Expand Down Expand Up @@ -617,9 +618,9 @@ sub _openapi_spec_from_schema {
$paths{ '/' . $name } = {
get => {
parameters => [
{ '$ref' => '#/parameters/$limit' },
{ '$ref' => '#/parameters/$offset' },
{ '$ref' => '#/parameters/$order_by' },
{ '$ref' => '#/parameters/%24limit' },
{ '$ref' => '#/parameters/%24offset' },
{ '$ref' => '#/parameters/%24order_by' },
map {; {
name => $_,
in => 'query',
Expand All @@ -642,7 +643,7 @@ sub _openapi_spec_from_schema {
items => {
type => 'array',
description => 'This page of items',
items => { '$ref' => "#/definitions/${name}" },
items => { '$ref' => "#/definitions/" . url_escape $name },
},
},
},
Expand All @@ -659,13 +660,16 @@ sub _openapi_spec_from_schema {
name => "newItem",
in => "body",
required => true,
schema => { '$ref' => "#/definitions/${name}" },
schema => { '$ref' => "#/definitions/" . url_escape $name },
},
],
responses => {
201 => {
description => "Entry was created",
schema => { '$ref' => "#/definitions/${name}/properties/${id_field}" },
schema => {
'$ref' => sprintf "#/definitions/%s/properties/%s",
map { url_escape $_ } $name, $id_field,
},
},
default => {
description => "Unexpected error",
Expand All @@ -692,7 +696,7 @@ sub _openapi_spec_from_schema {
responses => {
200 => {
description => "Item details",
schema => { '$ref' => "#/definitions/${name}" },
schema => { '$ref' => "#/definitions/" . url_escape $name },
},
default => {
description => "Unexpected error",
Expand All @@ -708,13 +712,13 @@ sub _openapi_spec_from_schema {
name => "newItem",
in => "body",
required => true,
schema => { '$ref' => "#/definitions/${name}" },
schema => { '$ref' => "#/definitions/" . url_escape $name },
}
],
responses => {
200 => {
description => "Item was updated",
schema => { '$ref' => "#/definitions/${name}" },
schema => { '$ref' => "#/definitions/" . url_escape $name },
},
default => {
description => "Unexpected error",
Expand Down

0 comments on commit 42d5079

Please sign in to comment.