Repository navigation
feat: decode XML responses with encoding/xml - #95
Merged
Merged
Conversation
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
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 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/xmlor+xml), has a schema and declares no JSON used to come back as bytes, or not at all. With this PR:encoding/xmlinto 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 aDecodingError, recorded in debug mode.xmltag beside itsjsontag, following the schema'sxmlobjects:name,attrfor an attribute;wrapper>itemfor a wrapped list;,omitemptywhere the member is optional.encoding/xmlinstead of JSON.*xml.SyntaxError.Golden:
GET /statementsreturns aFlexStatementResponsewith 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-writtenxml_test.gochecks 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
SendRequestrecordings, then generated with this branch.SendRequestreturns a struct withTimestamp,Status,ReferenceCodeandURLtagged for XML, and the generated replay test passes.openapi and cassette are pinned to their default branches. Those now hold the
xmlobject (MarkRosemaker/openapi#34) and replay a text body as the text it was rather than as a quoted JSON string (MarkRosemaker/cassette#10).make readypasses.🤖 Generated with Claude Code
https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y