Conversation
…ation When UseSchemaTypeNames=true and a Schema is provided, elements sharing the same XSD complexType are mapped to a single F# type (named after the XSD type) instead of generating a separate per-element type. For example, with po.xsd, shipTo and billTo (both of type USAddress) previously generated XmlProvider+ShipTo and XmlProvider+BillTo as separate identical F# types. With UseSchemaTypeNames=true, both map to a single XmlProvider+USAddress type. Closes #1488 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/repo-assist Fix this on Windows: |
…pe-names-59f5ef198df83e08
|
/repo-assist We need more testing. The file "tests/FSharp.Data.Tests/Data/shared-types.xsd" doesn't actually seem to be used. Add more tests |
- InferenceTests: add unit tests for XsdInference.inferElements with useSchemaTypeNames=true/false, verifying that shared XSD complex types produce correctly named InferedType.Record entries and that anonymous types still use element names - XmlProvider.fs: add integration tests using inline schema and shared-types.xsd with UseSchemaTypeNames=true, verifying that shipTo and billTo (both AddressType) produce the same .NET type and that field values are parsed correctly Closes the gap identified in #1663: shared-types.xsd was added as test data but not actually referenced in any test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
|
🤖 This is an automated response from Repo Assist. Thanks for the feedback! I've added the missing tests that exercise New tests added (5 tests total, all passing ✅):
|
…pe-names-59f5ef198df83e08
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Implements the fix requested in #1488 — a new
UseSchemaTypeNamesstatic parameter forXmlProviderthat deduplicates F# types when multiple elements share the same XSD complex type.Problem
When a schema defines a shared complex type (e.g.
USAddress) referenced by multiple elements (e.g.shipToandbillTo), the XmlProvider generates separate F# types for each element —XmlProvider+ShipToandXmlProvider+BillTo— even though they have identical structure. This forces users to write duplicate mapping code for each element.What this adds
A new
UseSchemaTypeNamesstatic parameter (defaultfalsefor backward compatibility):Implementation
The change is minimal and surgical:
XsdModel.XsdComplexType— AddedName: XmlQualifiedName optionfield to capture the XSD type name.XsdParsing.parseComplexType— PopulatesNamefromXmlSchemaComplexType.QualifiedName(non-empty for named types, None for anonymous inline types).XsdInference.inferElementType— WhenuseSchemaTypeNames=true, uses the XSD type name instead of the element name for theInferedType.Record. This causes elements sharing the same XSD type to generate the sameInferedType.Recordname, which the type provider infrastructure then naturally deduplicates into a single F# type.XmlProvider.fs— AddsUseSchemaTypeNamesas arg[14]and threads it through toXsdInference.inferElements.TypeProviderInstantiation.fsandInferenceTests.fs— Updated to include the new parameter.shared-types.xsd— Added test XSD demonstrating shared complex types.Design decisions
false: Preserves backward compatibility — existing code using XSD schemas continues to work unchanged.xs:complexType name="...") continue to use element names, since they don't have a meaningful XSD type name.Test Status
dotnet build src/FSharp.Data.Xml.Core/FSharp.Data.Xml.Core.fsproj— ✅ Build succeeded (0 errors)dotnet build src/FSharp.Data.DesignTime/FSharp.Data.DesignTime.fsproj— ✅ Build succeeded (0 errors, 7 pre-existing warnings)dotnet test tests/FSharp.Data.DesignTime.Tests/— Same 436 pre-existing failures as onmain(50 pass, 1 skip, 436 fail due to pre-existing test infrastructure cross-context issue unrelated to this change)