Gitlab Community Edition Instance

Skip to content
Snippets Groups Projects
openapi.xq 1 KiB
Newer Older
Mathias Goebel's avatar
Mathias Goebel committed
xquery version "3.1";

(: when using the library in other module the location part («at») SHOULD be
ommited as the library registers its namespace to eXist. :)
import module namespace openapi="https://lab.sub.uni-goettingen.de/restxqopenapi"
  at "content/openapi.xqm";

(: prepare a json document on HTTP requests :)
Mathias Goebel's avatar
Mathias Goebel committed
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
Mathias Goebel's avatar
Mathias Goebel committed
declare option output:method "json";
declare option output:media-type "application/json";

Mathias Goebel's avatar
Mathias Goebel committed
let $thisPath := replace(system:get-module-load-path(),
'^(xmldb:exist://)?(embedded-eXist-server)?(.+)$', '$3')

Mathias Goebel's avatar
Mathias Goebel committed
(: we register the REST interface :)
let $prepare :=
  if(xs:boolean(request:get-parameter("register", "false")))
  then
Mathias Goebel's avatar
Mathias Goebel committed
    xmldb:get-child-resources($thisPath || "/content")[. != "openapi.xqm"]
    ! exrest:register-module(xs:anyURI($thisPath || "/content/" || .))
  else ()
Mathias Goebel's avatar
Mathias Goebel committed

(: locate the target path :)
let $target := request:get-parameter("target", $thisPath)
Mathias Goebel's avatar
Mathias Goebel committed
return

(: prepare OpenAPI as map(*) :)
openapi:main($target)