Skip to content

Commit

Permalink
Merge branch 'feature/v3' into customPage3386
Browse files Browse the repository at this point in the history
  • Loading branch information
pshao25 authored May 12, 2023
2 parents 265c0bb + 79a6291 commit e8dc44d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private ModelFactoryTypeProvider(IEnumerable<SerializableObjectType> objectTypes
DefaultAccessibility = "public";
}

public static ModelFactoryTypeProvider? TryCreate(string defaultClientName, string rootNamespaceName, IEnumerable<TypeProvider> models, SourceInputModel? sourceInputModel)
public static ModelFactoryTypeProvider? TryCreate(string defaultClientName, string rootNamespaceName, IEnumerable<TypeProvider> models, SourceInputModel? sourceInputModel, string? namespaceOverride = null)
{
if (!Configuration.GenerateModelFactory)
return null;
Expand All @@ -56,7 +56,7 @@ private ModelFactoryTypeProvider(IEnumerable<SerializableObjectType> objectTypes
return null;
}

var defaultNamespace = GetDefaultModelNamespace(null, rootNamespaceName);
var defaultNamespace = namespaceOverride ?? GetDefaultModelNamespace(null, rootNamespaceName);

return new ModelFactoryTypeProvider(objectTypes, defaultClientName, defaultNamespace, sourceInputModel);
}
Expand Down
6 changes: 4 additions & 2 deletions src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,19 @@ private Dictionary<Operation, RestClientMethod> EnsureRestClientMethods()
}

private ModelFactoryTypeProvider? _modelFactory;
public ModelFactoryTypeProvider? ModelFactory => _modelFactory ??= ModelFactoryTypeProvider.TryCreate(GetModelFactoryName(), MgmtContext.Context.DefaultNamespace, AllSchemaMap.Values.Where(ShouldIncludeModel), MgmtContext.Context.SourceInputModel);
public ModelFactoryTypeProvider? ModelFactory => _modelFactory ??= ModelFactoryTypeProvider.TryCreate(GetModelFactoryName(), MgmtContext.Context.DefaultNamespace, AllSchemaMap.Values.Where(ShouldIncludeModel), MgmtContext.Context.SourceInputModel, GetModelFactoryNamespaceOverride());

private static string GetModelFactoryName()
{
var baseName = MgmtContext.Context.DefaultNamespace.Split('.').Last();
if (Configuration.MgmtConfiguration.IsArmCore)
return baseName;
return "ResourceManager";

return $"Arm{baseName}";
}

private static string? GetModelFactoryNamespaceOverride() => Configuration.MgmtConfiguration.IsArmCore ? "Azure.ResourceManager.Models" : null;

private bool ShouldIncludeModel(TypeProvider model)
{
if (model is MgmtReferenceType)
Expand Down
2 changes: 1 addition & 1 deletion src/AutoRest.CSharp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Configuration
```yaml
use-extension:
"@autorest/modelerfour": "4.25.0"
"@autorest/modelerfour": "4.26.0"
modelerfour:
always-create-content-type-parameter: true
pipeline:
Expand Down

0 comments on commit e8dc44d

Please sign in to comment.