Skip to content

Commit

Permalink
global /parameters/$* for smaller spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 authored and preaction committed Nov 21, 2018
1 parent d50b241 commit c4b18e5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 76 deletions.
44 changes: 25 additions & 19 deletions lib/Mojolicious/Plugin/Yancy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,27 @@ sub _openapi_spec_add_mojo {
sub _openapi_spec_from_schema {
my ( $self, $config ) = @_;
my ( %definitions, %paths );
my %parameters = (
'$limit' => {
name => '$limit',
type => 'integer',
in => 'query',
description => 'The number of items to return',
},
'$offset' => {
name => '$offset',
type => 'integer',
in => 'query',
description => 'The index (0-based) to start returning items',
},
'$order_by' => {
name => '$order_by',
type => 'string',
in => 'query',
pattern => '^(?:asc|desc):[^:,]+$',
description => 'How to sort the list. A string containing one of "asc" (to sort in ascending order) or "desc" (to sort in descending order), followed by a ":", followed by the field name to sort by.',
},
);
for my $name ( keys %{ $config->{collections} } ) {
# Set some defaults so users don't have to type as much
my $collection = $config->{collections}{ $name };
Expand All @@ -537,25 +558,9 @@ sub _openapi_spec_from_schema {
$paths{ '/' . $name } = {
get => {
parameters => [
{
name => '$limit',
type => 'integer',
in => 'query',
description => 'The number of items to return',
},
{
name => '$offset',
type => 'integer',
in => 'query',
description => 'The index (0-based) to start returning items',
},
{
name => '$order_by',
type => 'string',
in => 'query',
pattern => '^(?:asc|desc):[^:,]+$',
description => 'How to sort the list. A string containing one of "asc" (to sort in ascending order) or "desc" (to sort in descending order), followed by a ":", followed by the field name to sort by.',
},
{ '$ref' => '#/parameters/$limit' },
{ '$ref' => '#/parameters/$offset' },
{ '$ref' => '#/parameters/$order_by' },
map {; {
name => $_,
in => 'query',
Expand Down Expand Up @@ -708,6 +713,7 @@ sub _openapi_spec_from_schema {
%definitions,
},
paths => \%paths,
parameters => \%parameters,
};
}

Expand Down
87 changes: 30 additions & 57 deletions t/share/openapi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@
"title" : "OpenAPI Error Object"
}
},
"parameters" : {
"$limit" : {
"description" : "The number of items to return",
"type" : "integer",
"name" : "$limit",
"in" : "query"
},
"$offset" : {
"name" : "$offset",
"in" : "query",
"description" : "The index (0-based) to start returning items",
"type" : "integer"
},
"$order_by" : {
"name" : "$order_by",
"in" : "query",
"pattern" : "^(?:asc|desc):[^:,]+$",
"type" : "string",
"description" : "How to sort the list. A string containing one of \"asc\" (to sort in ascending order) or \"desc\" (to sort in descending order), followed by a \":\", followed by the field name to sort by."
}
},
"info" : {
"version" : 1,
"title" : "Yancy"
Expand All @@ -128,25 +149,9 @@
"/people" : {
"get" : {
"parameters" : [
{
"description" : "The number of items to return",
"type" : "integer",
"name" : "$limit",
"in" : "query"
},
{
"name" : "$offset",
"in" : "query",
"description" : "The index (0-based) to start returning items",
"type" : "integer"
},
{
"name" : "$order_by",
"in" : "query",
"pattern" : "^(?:asc|desc):[^:,]+$",
"type" : "string",
"description" : "How to sort the list. A string containing one of \"asc\" (to sort in ascending order) or \"desc\" (to sort in descending order), followed by a \":\", followed by the field name to sort by."
},
{ "$ref" : "#/parameters/$limit" },
{ "$ref" : "#/parameters/$offset" },
{ "$ref" : "#/parameters/$order_by" },
{
"type" : "integer",
"description" : "Filter the list by the id field. By default, looks for rows containing the value anywhere in the column. Use '*' anywhere in the value to anchor the match.",
Expand Down Expand Up @@ -227,25 +232,9 @@
"/user" : {
"get" : {
"parameters" : [
{
"description" : "The number of items to return",
"type" : "integer",
"name" : "$limit",
"in" : "query"
},
{
"type" : "integer",
"description" : "The index (0-based) to start returning items",
"in" : "query",
"name" : "$offset"
},
{
"in" : "query",
"name" : "$order_by",
"pattern" : "^(?:asc|desc):[^:,]+$",
"type" : "string",
"description" : "How to sort the list. A string containing one of \"asc\" (to sort in ascending order) or \"desc\" (to sort in descending order), followed by a \":\", followed by the field name to sort by."
},
{ "$ref" : "#/parameters/$limit" },
{ "$ref" : "#/parameters/$offset" },
{ "$ref" : "#/parameters/$order_by" },
{
"type" : "string",
"description" : "Filter the list by the username field. By default, looks for rows containing the value anywhere in the column. Use '*' anywhere in the value to anchor the match.",
Expand Down Expand Up @@ -372,25 +361,9 @@
}
},
"parameters" : [
{
"description" : "The number of items to return",
"type" : "integer",
"in" : "query",
"name" : "$limit"
},
{
"name" : "$offset",
"in" : "query",
"description" : "The index (0-based) to start returning items",
"type" : "integer"
},
{
"name" : "$order_by",
"in" : "query",
"description" : "How to sort the list. A string containing one of \"asc\" (to sort in ascending order) or \"desc\" (to sort in descending order), followed by a \":\", followed by the field name to sort by.",
"pattern" : "^(?:asc|desc):[^:,]+$",
"type" : "string"
},
{ "$ref" : "#/parameters/$limit" },
{ "$ref" : "#/parameters/$offset" },
{ "$ref" : "#/parameters/$order_by" },
{
"type" : "string",
"description" : "Filter the list by the markdown field. By default, looks for rows containing the value anywhere in the column. Use '*' anywhere in the value to anchor the match.",
Expand Down

0 comments on commit c4b18e5

Please sign in to comment.