Skip to content

Commit e11a233

Browse files
Copilotlive1206Copilot
authored
Fix unexpected additional parameter validation in model factory (Azure#53465)
* Initial plan * Fix ArgumentNullException in model factory methods Remove incorrect ArgumentNullException XML documentation from model factory methods. Model factory methods are designed for mocking and should allow all parameters to be null. The implementation handles null parameters gracefully using ternary operators. Co-authored-by: live1206 <[email protected]> * Update eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Visitors/ModelFactoryVisitor.cs Co-authored-by: Copilot <[email protected]> * Use Array.Empty instead of Enumerable.Empty to fix build issue Co-authored-by: live1206 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: live1206 <[email protected]> Co-authored-by: Wei Hu <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 756cbdd commit e11a233

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Visitors/ModelFactoryVisitor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
using Microsoft.TypeSpec.Generator.ClientModel;
55
using Microsoft.TypeSpec.Generator.Providers;
6+
using Microsoft.TypeSpec.Generator.Statements;
7+
using System;
68
using System.Collections.Generic;
9+
using System.Linq;
710

811
namespace Azure.Generator.Management.Visitors
912
{
@@ -19,6 +22,9 @@ internal class ModelFactoryVisitor : ScmLibraryVisitor
1922
var returnType = method.Signature.ReturnType;
2023
if (returnType is not null && ManagementClientGenerator.Instance.OutputLibrary.IsModelFactoryModelType(returnType))
2124
{
25+
// Fix ArgumentNullException XML documentation for parameters that are nullable
26+
// Model factory methods should allow all parameters to be null for mocking purposes
27+
FixArgumentNullExceptionXmlDoc(method);
2228
updatedMethods.Add(method);
2329
}
2430
}
@@ -27,5 +33,17 @@ internal class ModelFactoryVisitor : ScmLibraryVisitor
2733
}
2834
return base.VisitType(type);
2935
}
36+
37+
private void FixArgumentNullExceptionXmlDoc(MethodProvider method)
38+
{
39+
// Model factory methods are for mocking and should not have ArgumentNullException validation
40+
// The method implementation uses ternary operators to handle null values gracefully
41+
// Remove any ArgumentNullException documentation by clearing the exceptions list
42+
if (method.XmlDocs != null)
43+
{
44+
// Clear exceptions to remove ArgumentNullException documentation
45+
method.XmlDocs.Update(exceptions: Array.Empty<XmlDocExceptionStatement>());
46+
}
47+
}
3048
}
3149
}

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecTestsModelFactory.cs

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)