Repository navigation
feat(renderer): support Serde for large fixed-size arrays - #325
Conversation
Bergmann89
left a comment
There was a problem hiding this comment.
Thanks, nice addition! The use case is real (minOccurs == maxOccurs > 32 plus Serde derives does not compile today), and I like that the default output is unchanged and there is no new production dependency.
The main point is where the option lives: serde_large_arrays does not belong into RendererConfig (or MetaData), it only affects the Serde render steps. Please make it an option of these steps, similar to RenderStep::QuickXmlDeserialize { boxed_deserializer, skip_unknown_elements }, e.g. RenderStep::TypesSerdeQuickXml { large_arrays: bool } and RenderStep::TypesSerdeXmlRs { version, large_arrays }. Then the plain Types step does not need the adapters at all, which also removes the problem that #[serde(...)] attributes are rendered without any Serde derive. Turning TypesSerdeQuickXml into a struct variant is a breaking change of the config, please mention it in the PR description.
The rest is smaller cleanup.
Add an opt-in large_arrays setting to the Serde type render steps. Emit serde_with adapters for arrays longer than 32 elements while preserving field types, aliases, nested containers, custom codecs and defaults. Keep configuration local to the Serde steps so plain Types and direct quick-xml generation never receive automatic Serde attributes. Preserve default generated output and add no production dependency. Represent field default handling with a boolean and immutable override metadata. Cover configured and direct steps, aliases, newtypes, payloads, optional and boxed arrays, custom codecs and XML backend behavior with regression tests and compiled fixtures. Include a 360-element example and document backend limitations there. BREAKING CHANGE: TypesSerdeQuickXml becomes a struct variant and TypesSerdeXmlRs requires a large_arrays field. Set it to false for the previous behavior. Concrete Serde type render steps also become structs; their Default implementations preserve the previous behavior.
efc0b37 to
ce2a9a2
Compare
|
Thanks, for the guidance. I have updated the PR and your comments should be adressed now! |
Serde derives do not support fixed-size arrays longer than 32 elements. This adds opt-in adapters to the Serde render steps while preserving their generated Rust field types.
Changes
large_arraystoRenderStep::TypesSerdeQuickXmlandRenderStep::TypesSerdeXmlRs, disabled by default through the existing Serde configuration helpers.serde_withadapters. Preserve custom codecs and field defaults with shared boolean default metadata.Typesand direct quick-xml generation free of automatic Serde attributes. No settings are added toRendererConfig, rendererMetaData, or theRendererbuilder.Generated-code consumers enabling this option must depend on
serde_withwith itsstdorallocfeature. The generator gains no new production dependency.Breaking changes:
RenderStep::TypesSerdeQuickXmlbecomes a struct variant, andTypesSerdeXmlRsgains a requiredlarge_arraysfield. Initialize it tofalseto preserve existing behavior. The concreteSerdeQuickXmlTypesRenderStep,SerdeXmlRsV7TypesRenderStep, andSerdeXmlRsV8TypesRenderStepalso become structs with this field; callers can use::default()for the previous behavior.Checklist
update-expectationsand reviewedcargo fmt,cargo clippyandcargo testpass (see CONTRIBUTING.md)