Gitlab Community Edition Instance

Skip to content
Snippets Groups Projects
Commit 68bf4f06 authored by Mathias Goebel's avatar Mathias Goebel
Browse files

allow customized tags

parent d68b165d
No related branches found
No related tags found
No related merge requests found
...@@ -51,10 +51,10 @@ as map(*) { ...@@ -51,10 +51,10 @@ as map(*) {
return return
map:merge(( map:merge((
map{"openapi": "3.0.2"}, map{"openapi": "3.0.2"},
openapi:paths-object($module), openapi:paths-object($module, $config),
openapi:servers-object($config/openapi:servers), openapi:servers-object($config/openapi:servers),
openapi:info-object($expath, $repo, $config/openapi:info), openapi:info-object($expath, $repo, $config/openapi:info),
openapi:tags-object($module) openapi:tags-object($module, $config)
)) ))
}; };
...@@ -127,7 +127,7 @@ as map(*) { ...@@ -127,7 +127,7 @@ as map(*) {
: Prepare OAS3 Paths Object. : Prepare OAS3 Paths Object.
: @see https://swagger.io/specification/#pathsObject : @see https://swagger.io/specification/#pathsObject
:) :)
declare %private function openapi:paths-object($module as element(module)+) declare %private function openapi:paths-object($module as element(module)+, $config as element(openapi:config))
as map(*) { as map(*) {
let $paths := $module/function/annotation[@name = "rest:path"]/value => distinct-values() let $paths := $module/function/annotation[@name = "rest:path"]/value => distinct-values()
return return
...@@ -139,7 +139,7 @@ as map(*) { ...@@ -139,7 +139,7 @@ as map(*) {
return return
map{ map{
$path => replace("\{\$", "{"): $path => replace("\{\$", "{"):
map:merge(($functions ! openapi:operation-object(.))) map:merge(($functions ! openapi:operation-object(., $config)))
} }
)) ))
} }
...@@ -149,12 +149,23 @@ as map(*) { ...@@ -149,12 +149,23 @@ as map(*) {
: Prepare OAS3 Operation Object. : Prepare OAS3 Operation Object.
: @see https://swagger.io/specification/#operationObject : @see https://swagger.io/specification/#operationObject
:) :)
declare %private function openapi:operation-object($function as element(function)) declare %private function openapi:operation-object($function as element(function), $config as element(openapi:config))
as map(*) { as map(*) {
let $desc := normalize-space($function/description) let $name := $function/@name
let $desc := tokenize($function/description, "\n\s\n\s") ! normalize-space(.)
let $see := normalize-space($function/see) let $see := normalize-space($function/see)
let $deprecated := $function/deprecated let $deprecated := $function/deprecated
let $tags := array { $function/@name => substring-before(":") } let $tags := array {
if($config/openapi:tags/openapi:tag/openapi:function[@name = $name])
then
if($config/openapi:tags/openapi:tag/openapi:function[@name = $name]/parent::openapi:tag/string(@method) = "exclusive")
then $config/openapi:tags/openapi:tag/openapi:function[@name = $name]/parent::openapi:tag[@method = "exclusive"]/string(@name)
else
($name => substring-before(":"),
$config/openapi:tags/openapi:tag/openapi:function[@name = $name]/parent::openapi:tag/string(@name))
else
$name => substring-before(":")
}
return return
map:merge(( map:merge((
for $method in $function/annotation[@name = $openapi:supported-methods]/substring-after(lower-case(@name), "rest:") for $method in $function/annotation[@name = $openapi:supported-methods]/substring-after(lower-case(@name), "rest:")
...@@ -162,7 +173,8 @@ as map(*) { ...@@ -162,7 +173,8 @@ as map(*) {
map{ map{
$method: $method:
map:merge(( map:merge((
map{ "description": $desc}, map{ "summary": $desc[1]},
map{ "description": $desc[2]},
map{ "tags": $tags}, map{ "tags": $tags},
$see[1] ! map{"externalDocs": $see ! map{ $see[1] ! map{"externalDocs": $see ! map{
"url": ., "url": .,
...@@ -336,7 +348,7 @@ as map(*)? { ...@@ -336,7 +348,7 @@ as map(*)? {
} }
}; };
declare %private function openapi:tags-object($modules as element(module)+) declare %private function openapi:tags-object($modules as element(module)+, $config as element(openapi:config))
as map(*) { as map(*) {
map{ map{
"tags": array{ "tags": array{
...@@ -345,8 +357,14 @@ as map(*) { ...@@ -345,8 +357,14 @@ as map(*) {
map{ map{
"name": string($module/@prefix), "name": string($module/@prefix),
"description": normalize-space($module/description) "description": normalize-space($module/description)
},
for $tag in $config/openapi:tags/openapi:tag
return
map{
"name": string($tag/@name),
"description": normalize-space($tag)
} }
} }
} }
}; };
......
...@@ -10,4 +10,11 @@ ...@@ -10,4 +10,11 @@
<server url="http://localhost:8080/exist/restxq">Local development server</server> <server url="http://localhost:8080/exist/restxq">Local development server</server>
<server url="https://example.com/api/v1">Production server</server> <server url="https://example.com/api/v1">Production server</server>
</servers> </servers>
<tags>
<tag name="public" method="exclusive">
The public part of the API. No authentication. World-readable.
<function name="openapi-test-simple:del"/>
<function name="openapi-test-simple:get"/>
</tag>
</tags>
</config> </config>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment