Skip to content

Commit c86e6a0

Browse files
joewizclaude
authored andcommitted
fix: look up OpenAPI response definition by string status code
router:get-content-type-for-code indexed the string-keyed responses map (parsed from the OpenAPI JSON, so keys are "200", "404", "default") with the integer status $code. That only ever matched because of eXist's pre-conformance map-key coercion, which cast the integer lookup key to the map's string keyType. eXist-db/exist#6491 makes map keys compare by op:same-key per XQuery 3.1 section 17.1 (no cross-family coercion), so an integer key no longer matches a string key: the lookup misses, falls back to the "application/xml" content type, and a JSON response is serialized as XML (SENR0001) on the forward-dispatch path. Look up by string($code) instead. This is correct independent of #6491 - the OpenAPI keys are strings - and works on both current and pre-#6491 eXist (string-to-string always matched). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c9ef86b commit c86e6a0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

content/router.xql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ declare %private function router:execute-handler ($base-request as map(*), $use,
329329
(: content types :)
330330

331331
declare function router:get-content-type-for-code ($config as map(*), $code as xs:integer, $fallback as xs:string) as xs:string {
332-
let $response-definition := head(($config?responses?($code), $config?responses?default))
332+
(: OpenAPI response keys are strings ("200", "default"); look up the integer status code by its
333+
: string form. (Indexing the string-keyed responses map with the integer $code only ever matched
334+
: because of eXist's pre-conformance map-key coercion, removed in eXist-db/exist#6491.) :)
335+
let $response-definition := head(($config?responses?(string($code)), $config?responses?default))
333336
let $content :=
334337
if (exists($response-definition) and $response-definition instance of map(*))
335338
then $response-definition?content

0 commit comments

Comments
 (0)