diff --git a/content/openapi-tests-simple.xqm b/content/openapi-tests-simple.xqm index 2bbb59be9a0896aeb750fbcd6d5e37d597d026ab..7bcf5078a77812ddbbdcfbf485901d1c992e0ab9 100644 --- a/content/openapi-tests-simple.xqm +++ b/content/openapi-tests-simple.xqm @@ -210,7 +210,7 @@ as element(test) { declare %rest:POST("{$body}") %rest:path("/openapi-test/simple/multi-function") -function openapi-test-simple:multi-post($body) +function openapi-test-simple:multi-post-function($body) as element(test) { <test> <parameters n="0"/> @@ -226,7 +226,7 @@ as element(test) { declare %rest:POST("{$body}") %rest:path("/openapi-test/simple/multi-module") -function openapi-test-simple:multi-post($body) +function openapi-test-simple:multi-post-module($body) as element(test) { <test> <parameters n="0"/> diff --git a/content/openapi.xqm b/content/openapi.xqm index 00e7fb6b6e721175e32d4881375092ff5bebaaaa..4484a47c2cbf4c162e9f8037d304d1ebac8b2ec2 100644 --- a/content/openapi.xqm +++ b/content/openapi.xqm @@ -34,7 +34,7 @@ as xs:string { :) declare function openapi:main($target as xs:string) as map(*) { - let $modules-uris := collection($target)[openapi:xquery-resource(string(base-uri()))]/base-uri() + let $modules-uris := openapi:files($target, ())[openapi:xquery-resource(.)] let $module := for $module in $modules-uris let $test4rest := contains(util:binary-doc($module) => util:base64-decode(), "%rest:") @@ -420,4 +420,42 @@ as xs:boolean { ends-with($baseuri, ".xqm") or ends-with($baseuri, ".xql") or ends-with($baseuri, ".xq") + or ends-with($baseuri, ".xquery") + or ends-with($baseuri, ".xqy") +}; + +(:~ + : Returns the names of the child resources in collection URI supplied + : @param $target URI under which child resources are to be returned :) +declare function openapi:files-uris($target as xs:string) { + let $new-uris as xs:string* := xmldb:get-child-resources($target) + let $new-uris as xs:string* := + for $n in $new-uris return fn:concat($target, '/', $n) + return $new-uris +}; + +(:~ + : Returns the names of the child collections in collection URI supplied + : @param $target URI under which collections are to be returned :) +declare function openapi:collections-uris($target as xs:string) { + let $collections as xs:string* := xmldb:get-child-collections($target) + return $collections +}; + +(:~ + : Recursive function to use instead of collection as implementation of this function + : varies between Fusion and eXist so in Fusion XQuery files are not found. + : @param $target URI under which file listing is required + : @param $uris Existing URIs to be retained and added to until completion :) +declare function openapi:files($target as xs:string, $uris as xs:string*) { + let $current-uris as xs:string* := openapi:files-uris($target) + let $current-collections as xs:string* := openapi:collections-uris($target) + let $new-uris as xs:string* := + if (fn:empty($current-collections)) then () + else + for $c in $current-collections + let $target := fn:concat($target, '/', $c) + return (openapi:files($target, $uris)) + let $uris as xs:string* := ($current-uris, $new-uris, $uris) + return ($uris) };