Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/AutoRest.CSharp/Common/Utilities/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using AutoRest.CSharp.Input;
using AutoRest.CSharp.Mgmt.Models;
using Humanizer;
Expand Down Expand Up @@ -56,6 +55,9 @@ public static string ToCleanName(this string name, bool isCamelCase = true)
var c = name[i];
if (IsWordSeparator(c))
{
// keep following _ if there are multiple _ in a row, so that we can have a way to customize name with _
if (name[i] == '_' && i > 0 && name[i - 1] == '_')
nameBuilder.Append(c);
upperCase = true;
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ public override TypeProvider FindTypeProviderForSchema(Schema schema)
public override CSharpType? FindTypeByName(string originalName)
{
_schemaOrNameToModels.TryGetValue(originalName, out TypeProvider? provider);

if (provider == null)
{
// Try to search declaration name too if no key matches. i.e. Resource Data Type will be appended a 'Data' in the name and won't be found through key
provider = _schemaOrNameToModels.FirstOrDefault(s => s.Value is MgmtObjectType mot && mot.Declaration.Name == originalName).Value;
Comment thread
RodgeFu marked this conversation as resolved.
Outdated
}

provider ??= ResourceSchemaMap.Values.FirstOrDefault(m => m.Type.Name == originalName);
return provider?.Type;
}
Expand Down
15 changes: 13 additions & 2 deletions src/AutoRest.CSharp/MgmtTest/Extensions/CodeWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Transactions;
using System.Xml;
using AutoRest.CSharp.Generation.Types;
using AutoRest.CSharp.Generation.Writers;
Expand Down Expand Up @@ -151,8 +152,18 @@ private static CodeWriter AppendComplexFrameworkTypeValue(this CodeWriter writer
writer.Append($"new {type}(");
foreach (var parameter in publicCtor.GetParameters())
{
// we here assume the parameter name is the same as the serialized name of the property. This is not 100% solid
var value = exampleValue.Properties[parameter.Name!];
ExampleValue value;
if (exampleValue.Properties.ContainsKey(parameter.Name!))
// we here assume the parameter name is the same as the serialized name of the property. This is not 100% solid
value = exampleValue.Properties[parameter.Name!];
else
{
// if we can't find it directly, try to figure out the serailizedName form propertyMetadataDict
string? serializedName = propertyMetadataDict.FirstOrDefault(p => string.Equals(p.Key, parameter.Name!, StringComparison.OrdinalIgnoreCase)).Value?.SerializedName;
if (string.IsNullOrEmpty(serializedName) || !exampleValue.Properties.ContainsKey(serializedName))
throw new InvalidOperationException($"Unabled to find example value for ctor parameter, type={type.FullName}, param={parameter.Name ?? "<null>"}");
value = exampleValue.Properties[serializedName];
}
Comment thread
RodgeFu marked this conversation as resolved.
Outdated
writer.AppendExampleValue(value, parameter.ParameterType);
writer.AppendRaw(",");
}
Expand Down