Skip to content

Commit

Permalink
updated openapi, some error messages in dts
Browse files Browse the repository at this point in the history
  • Loading branch information
ingoboerner committed May 2, 2024
1 parent 60e0109 commit f836b49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
4 changes: 3 additions & 1 deletion api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1143,11 +1143,13 @@ paths:
- "4"
responses:
'200':
description: Navigation.
description: Successful.
content:
application/ld+json:
schema:
type: object
'400':
description: Bad request. Check error message in the response.

/dts/document:
get:
Expand Down
35 changes: 29 additions & 6 deletions modules/dts.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1511,23 +1511,23 @@ declare function local:link-header-of-fragment($tei as element(tei:TEI), $ref as
<rest:response>
<http:response status="400"/>
</rest:response>,
"Mandatory parameter 'id' is missing."
"Mandatory parameter 'resource' is missing."
)
(: both ref and either start or end is specified should return an error :)
else if ( $ref and ($start or $end) ) then
(
<rest:response>
<http:response status="400"/>
</rest:response>,
"Use of both param 'ref' and 'start' or 'end' is not allowed."
"Bad Request: Use of both parameters 'ref' and 'start' or 'end' is not allowed."
)
(: should not use start without end or vice versa :)
else if ( ($start and not($end)) or ($end and not($start)) ) then
(
<rest:response>
<http:response status="400"/>
</rest:response>,
"Must provide both start and end."
"Bad Request: Must provide both parameters 'start' and 'end'."
)
(: down=absent, ref=absent, start/end=absent --> 400 Bad Request Error :)
else if ( not($down) and not($ref) and ( not($start) and not($end) ) ) then
Expand All @@ -1537,7 +1537,6 @@ declare function local:link-header-of-fragment($tei as element(tei:TEI), $ref as
</rest:response>,
"Bad Request: Must provide at least one of the parameters 'down','ref' or both 'start' and 'end'. E.g. use parameter 'down=1' to retrieve the top-level citationStructures of this resource."
)

else
(: check, if there is a resource with this identifier :)
let $tei := if ( matches($resource, concat("^", $ddts:base-uri, "/id/","[a-z]+[0-9]{6}$" ) ) ) then
Expand All @@ -1552,7 +1551,20 @@ declare function local:link-header-of-fragment($tei as element(tei:TEI), $ref as

(: down = absent ref= present start/end = absent --> Information about the CitableUnit identified by ref. No member property in the Navigation object. :)
if ( not($down) and ( not($start) and not($end) ) and $ref ) then
(: what happens if ref is not valid? must not return 500! :)
(: TODO: validate here :)
local:citeable-unit-by-ref($tei, $ref)
(:
if ( local:validate-ref($ref, $tei) == true) then
local:citeable-unit-by-ref($tei, $ref)
else
(
<rest:response>
<http:response status="404"/>
</rest:response>,
"Not found: The identifier provided as parameter 'ref' does not match a citeable unit."
)
:)

(: down = absent ref = absent start/end = present --> Information about the CitableUnits identified by start and by end. No member property in the Navigation object. :)
else if ( not($down) and not($ref) and ($start and $end) ) then
Expand Down Expand Up @@ -1670,6 +1682,13 @@ declare function local:link-header-of-fragment($tei as element(tei:TEI), $ref as
)
};

(:TODO: add this function
declare function local:validate-ref($ref as xs:string, $tei as element(tei:TEI)) {
()
};
:)


(:~
: Navigate a resource on level 1
: TODO: refactor this to use local:navigation-basic-response and just add the member field
Expand Down Expand Up @@ -2112,8 +2131,12 @@ declare function local:navigation-basic-response($tei as element(tei:TEI), $requ
let $parent := if ($parent-string eq "") then () else $parent-string
let $ref-object := local:citable-unit($ref, $level, $parent, $cite-type, $tei-fragment, $doc-uri )

(: this is not the best idea eval is evil.. :)
(: maybe should filter for some characters like (), @ ... :)
(: Be careful, as Wolfgang Meier once said: eval() is evil..
to make eval less evil, check if ref conforms to a certain xpath and does not contain some bad code
This should be done before calling this function
Generally speaking this is a good way of retrieving segments identified by the xPath-ish ID
:)

let $self-elem := util:eval("$tei/tei:text/tei:" || replace($ref, "/", "/tei:"))
let $pre-elems := util:eval("$tei/tei:text/tei:" || replace($ref, "/", "/tei:"))/preceding-sibling::element()
let $post-elems := util:eval("$tei/tei:text/tei:" || replace($ref, "/", "/tei:"))/following-sibling::element()
Expand Down

0 comments on commit f836b49

Please sign in to comment.