feat(db): serialization parameters on GET /api/db/resource#48
Open
joewiz wants to merge 1 commit into
Open
Conversation
From the existdb-oxygen-plugin (oxex) tasking. GET /api/db/resource did a bare serialize($doc) with no caller control, so XML output was dictated entirely by the instance conf.xml serializer defaults. Add optional W3C serialization parameters — method, indent, omit-xml-declaration, encoding, media-type, item-separator — passed through to serialize() via an output:serialization-parameters element built from only the keys the caller supplied. Backward compatible: with no serialization params the handler still does a bare serialize($doc), so output is byte-for-byte identical to before (the conf.xml defaults). Binary resources are unaffected. Boolean params accept yes/no (the cursor query-results vocabulary) and tolerate true/false. expand-xincludes deliberately NOT included. The tasking's centerpiece — expand-xincludes=no for safe open/edit/save round-trips — turns out to be unachievable in eXist 7.0.0-beta3: fn:serialize always expands, util:serialize was removed, util:declare-option+serialize(element) (eXide's pattern) expands anyway, and the REST layer hard-codes expand-xincludes=yes. Advertising the param while silently expanding would give clients a false guarantee and risk destroying <xi:include> on save, so it is omitted pending an eXist-core fix. Full write-up: the finding doc accompanying this work. (Same latent data-loss exposure affects eXide on eXist 7 — its Open-with-expand-xincludes-off does not actually work either.) api.json documents the new query params and the expand-xincludes caveat. Cypress: 5 new tests — default (backward compat), indent yes/no, true/false tolerance, omit-xml-declaration, and binary-unaffected. Refs oxex serialization tasking (2026-06-06).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[This PR was co-authored with Claude Code. -Joe]
From the existdb-oxygen-plugin (oxex) serialization tasking.
GET /api/db/resourcedid a bareserialize($doc)with no caller control, so XML output was dictated entirely by the instance'sconf.xmlserializer defaults.What this adds
Optional W3C serialization parameters on
GET /api/db/resource, passed through toserialize()via anoutput:serialization-parameterselement built from only the keys the caller supplies:method(xml | xhtml | html5 | text | json | adaptive)indent(yes/no, tolerates true/false)omit-xml-declaration(yes/no, tolerates true/false)encoding,media-type,item-separatorBackward compatible: with no serialization params, the handler still does a bare
serialize($doc)— byte-for-byte identical to before (theconf.xmldefaults). Binary resources are unaffected.expand-xincludesis intentionally NOT included — and here's the important partThe tasking's centerpiece was
expand-xincludes=noon read, so an open→edit→save round-trip wouldn't silently destroy<xi:include>. That turns out to be unachievable in eXist 7.0.0-beta3. I verified every mechanism expands the include:fn:serialize($doc, map{"expand-xincludes":"no"})and the eXist-namespaced map key → expandutil:declare-option("exist:serialize","expand-xincludes=no")+serialize($doc, <output:serialization-parameters/>)— eXide's exact pattern → expandsGETdefault,?_xinclude=no,?_expand-xincludes=no→ expand (RESTServer hard-codesEXPAND_XINCLUDES=yes;RESTServerParameterhas no override)util:serialize(the eXist-6 node→string function that honored eXist serializer options) was removed in eXist 7 with no replacementOnly static
declare option exist:serialize "expand-xincludes=no"on a query result works — unusable for a per-request string embedded in a JSON envelope.Advertising
expand-xincludes=nowhile silently expanding would hand clients a false guarantee and risk destroying includes on save, so it's omitted pending an eXist-core fix.Two things for follow-up (tracked separately):
expand-xincludescontrollable for node→string serialization.Verification
db.cy.js: 5 new tests (default = backward-compat, indent yes/no, true/false tolerance, omit-xml-declaration, binary-unaffected). Fulldb.cy.jsgreen.indent=yespretty-prints,indent=nocompact,omit-xml-declaration=noincludes the declaration, no-params output identical to pre-change.api.json documents the new params and the
expand-xincludescaveat.