Skip to content

feat: decode XML responses with encoding/xml - #95

Merged
MarkRosemaker merged 2 commits into
mainfrom
feat/xml-responses
Nov 27, 2026
Merged

MarkRosemaker merged 2 commits into
mainfrom
feat/xml-responses

Conversation

@MarkRosemaker

@MarkRosemaker MarkRosemaker commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

This adds XML responses for go-api-libs/ibkr-flex, whose IBKR Flex Web Service answers in text/xml.

An operation's response that is XML (text/xml, application/xml or +xml), has a schema and declares no JSON used to come back as bytes, or not at all. With this PR:

  • Client: decodes the body with encoding/xml into the type its schema describes and returns it as a JSON body would be returned (Response.IsXML, Operation.XMLSuccess). A body that fails to decode is a DecodingError, recorded in debug mode.
  • Types: every field of every type an XML response holds, directly or deeper, gets an xml tag beside its json tag, following the schema's xml objects:
    • name,attr for an attribute;
    • wrapper>item for a wrapped list;
    • the item's name for a list whose items stand side by side;
    • ,omitempty where the member is optional.
  • Server: writes such a body with encoding/xml instead of JSON.
  • Generated tests:
    • A new "decoding error" test checks that a body that isn't XML fails with an *xml.SyntaxError.
    • The replay test checks that XML calls succeed, and leaves out the JSON body comparison.

Golden: GET /statements returns a FlexStatementResponse with an attribute, child elements, a list whose items stand side by side, a wrapped list, and the optional error elements. Two recordings, a success and an error answer, replay against it. A new hand-written xml_test.go checks every field decoded from both. The README lists XML responses.

End to end: I ran openapi-enrich's XML inference (MarkRosemaker/openapi-enrich#25) on ibkr-flex's two real SendRequest recordings, then generated with this branch. SendRequest returns a struct with Timestamp, Status, ReferenceCode and URL tagged for XML, and the generated replay test passes.

openapi and cassette are pinned to their default branches. Those now hold the xml object (MarkRosemaker/openapi#34) and replay a text body as the text it was rather than as a quoted JSON string (MarkRosemaker/cassette#10).

make ready passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y

An operation whose response is XML, text/xml, application/xml or +xml,
with a schema and no JSON declared, was handed back as bytes, or not at
all. It is now decoded with encoding/xml into the type its schema says
and returned as a JSON body would be. The fields of every type an XML
response holds get an xml tag beside their json one, as the schema's xml
objects say: ,attr for an attribute, wrapper>item for a wrapped list,
omitempty where the member is optional. The server writes such a body
with encoding/xml, and the generated tests check a body that is no XML
fails as a decoding error.

Pins openapi to MarkRosemaker/openapi#34, for the xml object, and
cassette to MarkRosemaker/cassette#10, which replays a body of text as
the text it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
… the xml object and text replay

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
@MarkRosemaker
MarkRosemaker merged commit e0184c2 into main Nov 27, 2026
1 check passed
@MarkRosemaker
MarkRosemaker deleted the feat/xml-responses branch November 27, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants