Fix malformed namespace generation for unresolved types in customization code#9578
Fix malformed namespace generation for unresolved types in customization code#9578JoshLove-msft merged 10 commits intomainfrom
Conversation
…erated types Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
...p-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/TypeSymbolExtensions.cs
Outdated
Show resolved
Hide resolved
… review Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
...p-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/CSharpTypeExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
…ulated Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
|
@copilot please add tests to ModelCustomizationTests that validates the case where a custom partial type adds a new property that references a generated type. The generated constructor for this model should represent the property as a parameter correctly, i.e. the namespace should match the generated type namespace. Add a similar test case where the generated type referenced in the custom property is customized to use a different name using CodeGenType. |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Added two test cases to ModelCustomizationTests:
Both tests confirm the namespace is correctly resolved as "Sample.Models" instead of being empty or malformed. Changes in commit 649f0d2. |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
...p-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/CSharpTypeExtensions.cs
Outdated
Show resolved
Hide resolved
...p-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/CSharpTypeExtensions.cs
Show resolved
Hide resolved
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/TypeFactory.cs
Show resolved
Hide resolved
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Fix for Malformed Namespace Generation in Customization Code
Changes Made
Modified:
TypeFactory.csTypeProvidersByNamedictionary mapping C# type names to TypeProviders for efficient O(1) lookupModified:
CSharpTypeExtensions.csEnsureNamespacemethod to handle custom properties without corresponding spec propertiesTryFindCSharpTypeByNamewith inline TypeFactory access for cleaner codeAdded Tests:
ModelCustomizationTests.csCanAddPropertyReferencingGeneratedType: Validates custom propertyIList<Bar>gets proper namespace "Sample.Models"CanAddPropertyReferencingRenamedGeneratedType: Validates custom property referencing CodeGenType renamed type gets proper namespaceTesting
All tests pass, confirming the fix resolves malformed namespace generation for customization code.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.