Skip to content

Commit

Permalink
reading $api:max-limit from swagger.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Aug 6, 2017
1 parent 7b34841 commit 315f8e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/v1/controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ let $validate-params := function($params as map()?) as map()? {
for $param in map:keys($params)
let $lookup := function-lookup(xs:QName($local:api-module-prefix || ':validate-' || $param), 1)
return
if(exists($lookup)) then $lookup(map:entry($param, $params($param)))
else if(exists($validate-unknown-param)) then $validate-unknown-param(map:entry($param, $params($param)))
if(exists($lookup)) then $lookup(map {$param := $params($param), 'swagger:config' := $local:swagger-config })
else if(exists($validate-unknown-param)) then $validate-unknown-param(map {$param := $params($param), 'swagger:config' := $local:swagger-config })
else (
util:log-system-out('It seems you did not provide a validate-unknown-param function'),
error($local:INVALID_PARAMETER, 'Unknown parameter "' || $param || '". Details should be provided in the system log.')
Expand Down
12 changes: 7 additions & 5 deletions modules/api.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import module namespace wega-util="http://xquery.weber-gesamtausgabe.de/modules/
declare variable $api:INVALID_PARAMETER := QName("http://xquery.weber-gesamtausgabe.de/modules/api", "ParameterError");
declare variable $api:UNSUPPORTED_ID_SCHEMA := QName("http://xquery.weber-gesamtausgabe.de/modules/api", "UnsupportedIDSchema");

declare variable $api:max-limit as xs:integer := 200;
declare variable $api:max-limit := function($swagger-conf as map(*)) as xs:integer {
$swagger-conf?parameters?limitParam?maximum
};

declare function api:documents($model as map()) {
let $ids :=
Expand Down Expand Up @@ -150,9 +152,9 @@ declare %private function api:subsequence($seq as item()*, $model as map()) {
let $limit := if($model('limit') castable as xs:integer) then $model('limit') cast as xs:integer else 0
return
if($offset gt 0 and $limit gt 0) then subsequence($seq, $offset, $limit)
else if($offset gt 0) then subsequence($seq, $offset, $api:max-limit)
else if($offset gt 0) then subsequence($seq, $offset, $api:max-limit($model('swagger:config')))
else if($limit gt 0) then subsequence($seq, 1, $limit)
else subsequence($seq, 1, $api:max-limit)
else subsequence($seq, 1, $api:max-limit($model('swagger:config')))
};

(:~
Expand Down Expand Up @@ -255,8 +257,8 @@ declare function api:validate-offset($model as map()) as map()? {
: Check parameter limit
~:)
declare function api:validate-limit($model as map()) as map()? {
if($model('limit') castable as xs:positiveInteger and xs:integer($model('limit')) le $api:max-limit) then $model
else error($api:INVALID_PARAMETER, 'Unsupported value for parameter "limit". It should be a positive integer less or equal to ' || $api:max-limit || '.')
if($model('limit') castable as xs:positiveInteger and xs:integer($model('limit')) le $api:max-limit($model('swagger:config'))) then $model
else error($api:INVALID_PARAMETER, 'Unsupported value for parameter "limit". It should be a positive integer less or equal to ' || $api:max-limit($model('swagger:config')) || '.')
};

(:~
Expand Down

0 comments on commit 315f8e4

Please sign in to comment.