feat(csharp): generate ToXml()/FromXml()/builders for xml-encoded object types (TwiML) - #17787
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
…ect types (TwiML) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Devin Review found 3 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
…eject non-xml object children at generation Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Docs Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on
Docs generation runs |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Description
Linear ticket: Refs (none)
C# counterpart of #17734 (Python), #17755 (Java) and #17785 (TypeScript): object types carrying IR
encoding.xmlmetadata (from #17732, e.g. Twilio TwiML) now generate XML serialization, parsing and fluent child builders. Types without XML metadata are untouched; the XML runtime files are only emitted when the IR contains at least one xml-encoded type.Generated shape (from the
csharp-xml-twimlfixture):Design notes (hard to see from the diff):
System.Xml/System.Xml.Linqonly, no new dependencies.XmlUtilsisinternal(core);IXmlNodeandXmlElementare public (public core).AdditionalAttributes/AdditionalChildrenand re-emitted byToXElement()(typed children first, unknown after); unknown children inside a wrapped list (<Numbers><Extension/></Numbers>) are kept without duplicating known items.OneOf<Say, Dial, ...>(default) and generated undiscriminated-union classes (use-undiscriminated-unions: true) — the fixture runs both.FromXElementuses an object initializer, so the 256-attributeWidetype parses without a giant constructor.Set/Listattributes withlistSeparator, namespaces/prefixes andxml:-prefixed attributes round-trip. FixedXmlElement.ToXElement()to route attributes throughXmlUtils.SetAttributesoxml:langdoesn't throw.67.21.0→67.25.0in the four C# packages.Changes Made
generators/csharp/base/src/asIs/{IXmlNode,XmlElement,XmlUtils}.Template.cs+test/Xml/XmlElementTests.Template.cs(runtime + shipped unit tests), registered inAsIs.ts; emitted conditionally viaGeneratorContext.hasXmlTypes()in model + sdk contextsgenerators/csharp/model/src/object/XmlObjectGenerator.ts: generates the interface impl,ToXElement/ToXml/FromXml/FromXElement, child-union parsers and builder methods; wired fromObjectGeneratoronly whentypeDeclaration.encoding.xml != nullcodegen:System.Xml.Linq.XElementextern +XmlUtils/XmlElement/IXmlNodereferencescsharp-xml-twimltest definition (Response/Say/Dial/Number/Client/Pause/Hangup/Wide/PlainObject: attrs, text,tw:namespace, wrappedNumbers, space-separated lists, empty elements, 256-attr type, non-xml type) with two seed configs; seed output + ir-to-jsonschema snapshots committedgenerators/csharp/sdk/changes/unreleased/feat-xml-encoded-types.ymlTesting
XmlElementTestsships into every generated SDK that has xml types (rendering/parsing, namespaces, declarations/comments, malformed XML, DTD rejection, wrong root, scalar/list parsing, wrapper unknown-child preservation)pnpm seed test --generator csharp-sdk --fixture csharp-xml-twiml --skip-scripts→ 2/2 passeddotnet teston generatedno-custom-configoutput with a temporary TwiML round-trip suite (attrs/text/escaping,tw:namespace, wrapped lists, list attrs, enums, unknown attrs+children incl.xml:lang,Wide,FromXml(ToXml(x))equality, error cases):Passed: 186, Failed: 0;use-undiscriminated-unionsoutput:Passed: 186, Failed: 0(round-trip suite adapted toResponseChildrenItem)net462;net8.0;net9.0;netstandard2.0pnpm seed test --generator csharp-sdk --fixture exhaustive→ 8/8, zero xml-related output diff (no regression for non-xml types)pnpm turbo run compile --filter @fern-api/fern-csharp-sdk --filter @fern-api/fern-csharp-model→ 16/16 tasksLink to Devin session: https://app.devin.ai/sessions/311fe13ae5434245ada665a9b824809b
Open in Devin Desktop: https://app.devin.ai/desktop/session/311fe13ae5434245ada665a9b824809b?variant=devin