diff --git a/eng/Generate.ps1 b/eng/Generate.ps1
index 4ea1498e..d6b0fb8e 100644
--- a/eng/Generate.ps1
+++ b/eng/Generate.ps1
@@ -1,4 +1,4 @@
-param($name, [switch]$NoDebug)
+param($name, [switch]$noDebug)
$ErrorActionPreference = 'Stop'
function Invoke-Block([scriptblock]$cmd) {
@@ -17,28 +17,45 @@ function Invoke-Block([scriptblock]$cmd) {
}
}
-$repoRoot = Resolve-Path "$PSScriptRoot\.."
-$testServerTestProject = "$repoRoot\test\AutoRest.TestServer.Tests"
-$testConfiguration = "$testServerTestProject\readme.md"
-$testServerSwaggerPath = "$repoRoot\node_modules\@microsoft.azure\autorest.testserver\swagger"
-$paths = 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options'
-if ($name)
-{
- $paths = $name
-}
-$debugFlags = if (!$NoDebug) { '--debug','--verbose' }
+function Invoke-AutoRest($debugFlags, $testConfiguration, $outputFolder, $inputFile, $name, $namespace, $repoRoot) {
+ Invoke-Block {
+ $outputFlag = if($outputFolder) { "--output-folder=$outputFolder" } else { '' }
+ $inputFlag = if($inputFile) { "--input-file=$inputFile" } else { '' }
+ $titleFlag = if($name) { "--title=$name" } else { '' }
+ $namespaceFlag = if($namespace) { "--namespace=$namespace" } else { '' }
+ $command = "npx autorest-beta $debugFlags $testConfiguration $outputFlag $inputFlag $titleFlag $namespaceFlag"
+ $commandText = $command.Replace($repoRoot, "`$(SolutionDir)")
-foreach ($path in $paths)
-{
- $outputFolder = "$testServerTestProject\$path";
- $inputFile = "$testServerSwaggerPath\$path.json"
- $namespace = $path.Replace('-', '_')
- Invoke-Block {
- $command = "npx autorest-beta $debugFlags $testConfiguration --output-folder=$outputFolder --input-file=$inputFile --title=$path --namespace=$namespace"
- $command = $command.Replace($repoRoot, "`$(SolutionDir)")
-
- Write-Host ">" $command
-
- npx autorest-beta @debugFlags $testConfiguration --output-folder=$outputFolder --input-file=$inputFile --title=$path --namespace=$namespace
+ Write-Host ">" $commandText
+ Invoke-Expression $command
}
+}
+
+# General configuration
+$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..')
+$debugFlags = if (-not $noDebug) { '--debug', '--verbose' }
+
+# Test server test configuration
+$testServerTestProject = Join-Path $repoRoot 'test' 'AutoRest.TestServer.Tests'
+$testConfiguration = Join-Path $testServerTestProject 'readme.md'
+$testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger'
+$testNames = if ($name) { $name } else { 'url', 'body-string', 'body-complex', 'custom-baseUrl', 'custom-baseUrl-more-options' }
+
+foreach ($testName in $testNames)
+{
+ $outputFolder = Join-Path $testServerTestProject $testName
+ $inputFile = Join-Path $testServerSwaggerPath "$testName.json"
+ $namespace = $testName.Replace('-', '_')
+ Invoke-AutoRest $debugFlags $testConfiguration $outputFolder $inputFile $testName $namespace $repoRoot
+}
+
+# Sample configuration
+$sampleDirectory = Join-Path $repoRoot 'samples'
+$projectNames = 'AppConfiguration'
+
+foreach ($projectName in $projectNames)
+{
+ $projectDirectory = Join-Path $sampleDirectory $projectName
+ $configurationPath = Join-Path $projectDirectory 'readme.md'
+ Invoke-AutoRest $debugFlags $configurationPath -repoRoot $repoRoot
}
\ No newline at end of file
diff --git a/src/AutoRest.CSharp.V3/ClientModels/CollectionTypeReference.cs b/src/AutoRest.CSharp.V3/ClientModels/CollectionTypeReference.cs
index 1d94888c..6c9f2fe7 100644
--- a/src/AutoRest.CSharp.V3/ClientModels/CollectionTypeReference.cs
+++ b/src/AutoRest.CSharp.V3/ClientModels/CollectionTypeReference.cs
@@ -12,6 +12,7 @@ namespace AutoRest.CSharp.V3.ClientModels
ItemType = itemType;
}
+ //TODO: This should not be defaulted to nullable false
public override bool IsNullable => false;
}
}
diff --git a/src/AutoRest.CSharp.V3/CodeGen/CsProjWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/CsProjWriter.cs
index 7ea582bf..1773f93a 100644
--- a/src/AutoRest.CSharp.V3/CodeGen/CsProjWriter.cs
+++ b/src/AutoRest.CSharp.V3/CodeGen/CsProjWriter.cs
@@ -17,8 +17,7 @@ namespace AutoRest.CSharp.V3.CodeGen
false
bin
$(OutputPath)
-
- 1998
+ SA1649
true
enable
diff --git a/src/AutoRest.CSharp.V3/Plugins/Modeler.cs b/src/AutoRest.CSharp.V3/Plugins/Modeler.cs
index 1690d536..d1708d1b 100644
--- a/src/AutoRest.CSharp.V3/Plugins/Modeler.cs
+++ b/src/AutoRest.CSharp.V3/Plugins/Modeler.cs
@@ -56,6 +56,9 @@ namespace AutoRest.CSharp.V3.Plugins
private static ServiceClient BuildClient(OperationGroup arg) =>
new ServiceClient(arg.CSharpName(), arg.Operations.Select(BuildMethod).Where(method => method != null).ToArray()!);
+ private static ClientConstant? CreateDefaultValueConstant(Parameter requestParameter) =>
+ requestParameter.ClientDefaultValue != null ? new ClientConstant(requestParameter.ClientDefaultValue, new FrameworkTypeReference(typeof(object))) : (ClientConstant?)null;
+
private static ClientMethod? BuildMethod(Operation operation)
{
var httpRequest = operation.Request.Protocol.Http as HttpRequest;
@@ -81,17 +84,27 @@ namespace AutoRest.CSharp.V3.Plugins
switch (requestParameter.Schema)
{
case ConstantSchema constant:
- constantOrParameter = new ClientConstant(constant.Value.Value, (FrameworkTypeReference) CreateType(constant.ValueType, false));
+ constantOrParameter = new ClientConstant(constant.Value.Value, (FrameworkTypeReference)CreateType(constant.ValueType, false));
break;
case BinarySchema _:
// skip
continue;
+ //TODO: Workaround for https://github.com/Azure/autorest.csharp/pull/275
+ case ArraySchema arraySchema when arraySchema.ElementType is ConstantSchema constantInnerType:
+ constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(),
+ new CollectionTypeReference(CreateType(constantInnerType.ValueType, false)),
+ CreateDefaultValueConstant(requestParameter));
+ break;
+ //TODO: Workaround for https://github.com/Azure/autorest.csharp/pull/275
+ case DictionarySchema dictionarySchema when dictionarySchema.ElementType is ConstantSchema constantInnerType:
+ constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(),
+ new CollectionTypeReference(CreateType(constantInnerType.ValueType, false)),
+ CreateDefaultValueConstant(requestParameter));
+ break;
default:
constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(),
CreateType(requestParameter.Schema, requestParameter.IsNullable()),
- requestParameter.ClientDefaultValue != null ?
- new ClientConstant(requestParameter.ClientDefaultValue, new FrameworkTypeReference(typeof(object))) :
- (ClientConstant?)null);
+ CreateDefaultValueConstant(requestParameter));
break;
}
@@ -210,6 +223,7 @@ namespace AutoRest.CSharp.V3.Plugins
private static ClientObjectProperty CreateProperty(Property property) =>
new ClientObjectProperty(property.CSharpName(), CreateType(property.Schema, property.IsNullable()), property.Schema.IsLazy(), property.SerializedName);
+ //TODO: Handle nullability properly
private static ClientTypeReference CreateType(Schema schema, bool isNullable) => schema switch
{
BinarySchema _ => (ClientTypeReference)new BinaryTypeReference(false),