Gitlab Community Edition Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openapi4restxq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mark Rainbird
openapi4restxq
Commits
be960a48
Commit
be960a48
authored
6 years ago
by
Mathias Goebel
Browse files
Options
Downloads
Patches
Plain Diff
restructure parameter maps, make most functinos %private
parent
676ebcec
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
content/openapi.xqm
+74
-50
74 additions, 50 deletions
content/openapi.xqm
with
74 additions
and
50 deletions
content/openapi.xqm
+
74
−
50
View file @
be960a48
...
...
@@ -14,7 +14,7 @@ declare namespace rest="http://exquery.org/ns/restxq";
declare
namespace
pkg
=
"http://expath.org/ns/pkg"
;
declare
namespace
repo
=
"http://exist-db.org/xquery/repo"
;
declare
variable
$openapi:supported-methods
:=
(
"rest:GET"
,
"rest:HEAD"
,
"rest:POST"
,
"rest:PUT"
,
"rest:DELETE"
);
declare
%private
variable
$openapi:supported-methods
:=
(
"rest:GET"
,
"rest:HEAD"
,
"rest:POST"
,
"rest:PUT"
,
"rest:DELETE"
);
(:~
: Prepares a JSON document usually to be stored as "openapi.json".
...
...
@@ -90,7 +90,7 @@ as map(*) {
: Prepare a OAS License Object
: @see https://swagger.io/specification/#licenseObject
:)
declare
function
openapi:license-object
(
$repo
as
element
(
repo:meta
))
declare
%private
function
openapi:license-object
(
$repo
as
element
(
repo:meta
))
as
map
(
*
)
{
let
$licenseId
:=
string
(
$repo
/
repo:license
)
let
$url
:=
(
map
:
get
(
openapi:spdx
(
$licenseId
)
,
"seeAlso"
)?
*
)[
1
]
...
...
@@ -106,7 +106,7 @@ as map(*) {
: Prepares a OAS3 Servers Object
: @see https://swagger.io/specification/#serverObject
:)
declare
function
openapi:servers-object
(
$config
as
element
(
openapi:servers
))
declare
%private
function
openapi:servers-object
(
$config
as
element
(
openapi:servers
))
as
map
(
*
)
{
map
{
"servers"
:
[
...
...
@@ -138,7 +138,7 @@ as map(*) {
: Prepare OAS3 Operation Object.
: @see https://swagger.io/specification/#operationObject
:)
declare
function
openapi:operation-object
(
$function
as
element
(
function
))
declare
%private
function
openapi:operation-object
(
$function
as
element
(
function
))
as
map
(
*
)
{
let
$desc
:=
normalize-space
(
$function
/
description
)
let
$see
:=
normalize-space
(
$function
/
see
)
...
...
@@ -169,7 +169,7 @@ as map(*) {
: Prepare OAS3 Response Object.
: @see https://swagger.io/specification/#responsesObject
: :)
declare
function
openapi:responses-object
(
$function
as
element
(
function
))
declare
%private
function
openapi:responses-object
(
$function
as
element
(
function
))
as
map
(
*
){
map
{
"responses"
:
...
...
@@ -186,8 +186,22 @@ as map(*){
: Prepare OAS3 Parameter Object.
: @see https://swagger.io/specification/#mediaTypeObject
: :)
declare
function
openapi:parameter-object
(
$function
as
element
(
function
))
declare
%private
function
openapi:parameter-object
(
$function
as
element
(
function
))
as
map
(
*
)
{
map
{
"parameters"
:
array
{
openapi:parameters-path
(
$function
)
,
openapi:parameters-query
(
$function
)
}
}
};
(:~
: Prepares all PATH parameters for a given function
: @param $function A function element from the inspect module
: :)
declare
%private
function
openapi:parameters-path
(
$function
as
element
(
function
))
as
map
(
*
)
*
{
let
$pathParameters
:=
$function
/
annotation
[
@name
=
"rest:path"
][
1
]
/
tokenize
(
value
,
"\{"
)
...
...
@@ -196,56 +210,56 @@ as map(*) {
=>
substring-after
(
"$"
)
=>
substring-before
(
"}"
)
)
let
$pathParametersMap
:=
for
$parameter
in
$pathParameters
let
$name
:=
replace
(
$parameter
,
"\{|\$|\}"
,
""
)
let
$argument
:=
$function
/
argument
[
@var
eq
$name
]
let
$basics
:=
map
:
merge
((
map
{
"name"
:
$name
,
"in"
:
"path"
,
"required"
:
true
()}
,
openapi:schema-object
(
$argument
)
))
let
$description
:=
$function
/
argument
[
@var
=
$name
]
/
text
()
!
map
{
"description"
:
.
}
let
$example
:=
string
(
$function
/
annotation
[
@name
=
"test:arg"
][
value
[
1
]
=
$name
]
/
value
[
2
])
!
map
{
"example"
:
.
}
return
map
:
merge
((
$basics
,
$description
,
$example
))
for
$parameter
in
$pathParameters
let
$name
:=
replace
(
$parameter
,
"\{|\$|\}"
,
""
)
let
$argument
:=
$function
/
argument
[
@var
eq
$name
]
let
$basics
:=
map
:
merge
((
map
{
"name"
:
$name
,
"in"
:
"path"
,
"required"
:
true
()}
,
openapi:schema-object
(
$argument
)
))
let
$description
:=
$function
/
argument
[
@var
=
$name
]
/
text
()
!
map
{
"description"
:
.
}
let
$example
:=
openapi:example
(
$function
,
$name
)
return
map
:
merge
((
$basics
,
$description
,
$example
))
};
(:~
: Prepares all QUERY parameters for a given function
: @param $function A function element from the inspect module
: :)
declare
%private
function
openapi:parameters-query
(
$function
as
element
(
function
))
as
map
(
*
)
*
{
let
$queryParameters
:=
$function
/
annotation
[
@name
=
"rest:query-param"
]
let
$queryParametersMap
:=
for
$parameter
in
$queryParameters
let
$name
:=
string
(
$parameter
/
value
[
2
])
=>
replace
(
"\{|\$|\}"
,
""
)
let
$argument
:=
$function
/
argument
[
@var
eq
$name
]
let
$required
:=
exists
(
$parameter
/
value
[
3
]
and
not
(
contains
(
$argument
/
@cardinality
,
"zero"
)))
let
$basics
:=
map
:
merge
((
map
{
"name"
:
$name
,
"in"
:
"query"
,
"required"
:
$required
}
,
openapi:schema-object
(
$argument
)
))
let
$description
:=
$function
/
argument
[
@var
=
$name
]
/
text
()
!
map
{
"description"
:
.
}
let
$pos
:=
index-of
((
$function
/
argument
/
string
(
@var
))
,
$name
)
let
$example
:=
$function
/
annotation
[
@name
=
"test:args"
][
1
]
/
value
[
$pos
]
/
text
()
!
map
{
"example"
:
.
}
return
map
:
merge
((
$basics
,
$description
,
$example
))
for
$parameter
in
$queryParameters
let
$name
:=
string
(
$parameter
/
value
[
2
])
=>
replace
(
"\{|\$|\}"
,
""
)
let
$argument
:=
$function
/
argument
[
@var
eq
$name
]
let
$required
:=
exists
(
$parameter
/
value
[
3
]
and
not
(
contains
(
$argument
/
@cardinality
,
"zero"
)))
let
$basics
:=
map
:
merge
((
map
{
"name"
:
$name
,
"in"
:
"query"
,
"required"
:
$required
}
,
openapi:schema-object
(
$argument
)
))
let
$description
:=
$function
/
argument
[
@var
=
$name
]
/
text
()
!
map
{
"description"
:
.
}
let
$pos
:=
index-of
((
$function
/
argument
/
string
(
@var
))
,
$name
)
let
$example
:=
openapi:example
(
$function
,
$name
)
return
map
{
"parameters"
:
array
{
$pathParametersMap
,
$queryParametersMap
}
}
map
:
merge
((
$basics
,
$description
,
$example
))
};
(:~
: Prepare OAS3 Media Type Object.
: @see https://swagger.io/specification/#mediaTypeObject
: :)
declare
function
openapi:mediaType-object
(
$function
)
declare
%private
function
openapi:mediaType-object
(
$function
)
as
map
(
*
)
{
let
$produces
:=
(
string
(
$function
/
annotation
[
@name
=
"rest:produces"
])
,
...
...
@@ -265,7 +279,7 @@ as map(*) {
: either *:returns or *:argument
: @see https://swagger.io/specification/#mediaTypeObject
: :)
declare
function
openapi:schema-object
(
$returns
as
element
(
*
))
declare
%private
function
openapi:schema-object
(
$returns
as
element
(
*
))
as
map
(
*
)
{
map
{
"schema"
:
map
:
merge
((
...
...
@@ -278,7 +292,7 @@ as map(*) {
}
};
declare
function
openapi:tags-object
(
$modules
as
element
(
module
)
+
)
declare
%private
function
openapi:tags-object
(
$modules
as
element
(
module
)
+
)
as
map
(
*
)
{
map
{
"tags"
:
array
{
...
...
@@ -313,7 +327,7 @@ return
: @param $method One of the specified methods
: @see https://www.w3.org/TR/xslt-xquery-serialization/
: :)
declare
function
openapi:method-mediaType
(
$method
as
xs:string
?
)
declare
%private
function
openapi:method-mediaType
(
$method
as
xs:string
?
)
as
xs:string
?
{
switch
(
$method
)
case
"html"
return
"text/html"
...
...
@@ -324,3 +338,13 @@ as xs:string?{
(: case "adaptive" return () :)
default
return
()
};
(:~
: Prepare an example value based on XQSuite annotation
: @param $function A function element from inspect module
: @param $name The name of the argument to prepare an example for :)
declare
%private
function
openapi:example
(
$function
as
element
(
function
)
,
$name
as
xs:string
)
as
map
(
*
)
*
{
string
(
$function
/
annotation
[
@name
=
"test:arg"
][
value
[
1
]
=
$name
]
/
value
[
2
])
!
map
{
"example"
:
.
}
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment