diff --git a/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs b/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs index 0016a1fe7bb..0c0394e426f 100644 --- a/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs +++ b/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs @@ -7,11 +7,11 @@ using System.Threading.Tasks; using AutoRest.CSharp.AutoRest.Communication; using AutoRest.CSharp.Common.Input; +using AutoRest.CSharp.Common.Utilities; using AutoRest.CSharp.Input; using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.Utilities; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; namespace AutoRest.CSharp.AutoRest.Plugins { @@ -32,14 +32,17 @@ public async Task ExecuteAsync(CodeModel codeModel) } else if (Configuration.AzureArm) { - if (Configuration.MgmtTestConfiguration is not null) + if (Configuration.MgmtConfiguration.MgmtDebug.SkipCodeGen) { - // we currently do not need this sourceInputModel when generating the test code because it only has information about the "non-generated" test code. - await MgmtTestTarget.ExecuteAsync(project, codeModel); + await AutoRestLogger.Warning("skip generating sdk code because 'mgmt-debug.skip-codegen' is true."); + if (Configuration.MgmtTestConfiguration is not null) + await MgmtTestTarget.ExecuteAsync(project, codeModel, null); } else { await MgmtTarget.ExecuteAsync(project, codeModel, sourceInputModel); + if (Configuration.MgmtTestConfiguration is not null) + await MgmtTestTarget.ExecuteAsync (project, codeModel, sourceInputModel); } } else @@ -60,7 +63,7 @@ public async Task ExecuteAsync(InputNamespace rootNamesp return project; } - private static void ValidateConfiguration () + private static void ValidateConfiguration() { if (Configuration.Generation1ConvenienceClient && Configuration.AzureArm) { @@ -82,7 +85,7 @@ public async Task Execute(IPluginCommunication autoRest) if (!Path.IsPathRooted(Configuration.OutputFolder)) { - await autoRest.Warning("output-folder path should be an absolute path"); + await AutoRestLogger.Warning("output-folder path should be an absolute path"); } if (Configuration.SaveInputs) { @@ -95,12 +98,14 @@ public async Task Execute(IPluginCommunication autoRest) var project = await ExecuteAsync(codeModel); await foreach (var file in project.GetGeneratedFilesAsync()) { - await autoRest.WriteFile(file.Name, file.Text, "source-file-csharp"); + // format all \ to / in filename, otherwise they will be treated as escape char when sending to autorest service + var filename = file.Name.Replace('\\', '/'); + await autoRest.WriteFile(filename, file.Text, "source-file-csharp"); } } catch (ErrorHelpers.ErrorException e) { - await autoRest.Fatal(e.ErrorText); + await AutoRestLogger.Fatal(e.ErrorText); return false; } catch (Exception e) @@ -118,7 +123,7 @@ public async Task Execute(IPluginCommunication autoRest) { // Ignore any errors while trying to output crash information } - await autoRest.Fatal($"Internal error in AutoRest.CSharp{ErrorHelpers.FileIssueText}\nException: {e.Message}\n{e.StackTrace}"); + await AutoRestLogger.Fatal($"Internal error in AutoRest.CSharp{ErrorHelpers.FileIssueText}\nException: {e.Message}\n{e.StackTrace}"); return false; } diff --git a/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs b/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs index 2b5970e2d14..323dbea946a 100644 --- a/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs +++ b/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs @@ -394,7 +394,7 @@ private static T GetRequiredOption(IPluginCommunication autoRest, string name return autoRest.GetValue(name).GetAwaiter().GetResult() ?? throw new InvalidOperationException($"{name} configuration parameter is required"); } - private static string TrimFileSuffix(string path) + internal static string TrimFileSuffix(string path) { if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) { diff --git a/src/AutoRest.CSharp/Common/AutoRest/Plugins/PluginProcessor.cs b/src/AutoRest.CSharp/Common/AutoRest/Plugins/PluginProcessor.cs index 709652be844..d535f89e253 100644 --- a/src/AutoRest.CSharp/Common/AutoRest/Plugins/PluginProcessor.cs +++ b/src/AutoRest.CSharp/Common/AutoRest/Plugins/PluginProcessor.cs @@ -8,6 +8,7 @@ using System.Text.Json; using System.Threading.Tasks; using AutoRest.CSharp.AutoRest.Communication; +using AutoRest.CSharp.Common.Utilities; using AutoRest.CSharp.Input; using AutoRest.CSharp.Utilities; @@ -34,6 +35,7 @@ public static async Task Start(IPluginCommunication autoRest) Console.Error.WriteLine("Attempting to attach debugger."); System.Diagnostics.Debugger.Launch(); } + AutoRestLogger.Initialize(autoRest); return await plugin.Execute(autoRest); } catch (Exception e) diff --git a/src/AutoRest.CSharp/Common/Utilities/AutoRestLogger.cs b/src/AutoRest.CSharp/Common/Utilities/AutoRestLogger.cs new file mode 100644 index 00000000000..a58222103c2 --- /dev/null +++ b/src/AutoRest.CSharp/Common/Utilities/AutoRestLogger.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using AutoRest.CSharp.AutoRest.Communication; + +namespace AutoRest.CSharp.Common.Utilities +{ + internal static class AutoRestLogger + { + private static IPluginCommunication? _autoRest = null; + public static void Initialize(IPluginCommunication autoRest) + { + _autoRest = autoRest; + } + + public static bool IsInitialized => _autoRest != null; + + public static async Task Warning(string message) + { + if (!IsInitialized) + throw new InvalidOperationException("AutoRestLogger.Warning is called before initialized"); + await _autoRest!.Warning(message); + } + + public static async Task Fatal(string message) + { + if (!IsInitialized) + throw new InvalidOperationException("AutoRestLogger.Fatal is called before initialized"); + await _autoRest!.Fatal(message); + } + } +} diff --git a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs index 1610f79293f..03ea5f16069 100644 --- a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs +++ b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs @@ -21,13 +21,17 @@ public class MgmtDebugConfiguration public bool ShowSerializedNames { get; } + public bool SkipCodeGen { get; } + public MgmtDebugConfiguration( JsonElement? suppressListException = default, - JsonElement? showSerializedNames = default + JsonElement? showSerializedNames = default, + JsonElement? skipCodeGen = default ) { SuppressListException = Configuration.DeserializeBoolean(suppressListException, false); ShowSerializedNames = Configuration.DeserializeBoolean(showSerializedNames, false); + SkipCodeGen = Configuration.DeserializeBoolean(skipCodeGen, false); } internal static MgmtDebugConfiguration LoadConfiguration(JsonElement root) @@ -37,10 +41,12 @@ internal static MgmtDebugConfiguration LoadConfiguration(JsonElement root) root.TryGetProperty(nameof(SuppressListException), out var suppressListException); root.TryGetProperty(nameof(ShowSerializedNames), out var showSerializedNames); + root.TryGetProperty(nameof(SkipCodeGen), out var skipCodeGen); return new MgmtDebugConfiguration( suppressListException: suppressListException, - showSerializedNames: showSerializedNames + showSerializedNames: showSerializedNames, + skipCodeGen: skipCodeGen ); } @@ -48,7 +54,8 @@ internal static MgmtDebugConfiguration GetConfiguration(IPluginCommunication aut { return new MgmtDebugConfiguration( suppressListException: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "suppress-list-exception")).GetAwaiter().GetResult(), - showSerializedNames: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "show-serialized-names")).GetAwaiter().GetResult() + showSerializedNames: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "show-serialized-names")).GetAwaiter().GetResult(), + skipCodeGen: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "skip-codegen")).GetAwaiter().GetResult() ); } diff --git a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs index 88d1287857a..5622c002aa0 100644 --- a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs +++ b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs @@ -11,24 +11,30 @@ namespace AutoRest.CSharp.Input { internal class MgmtTestConfiguration { - internal const string TestGenOptionsRoot = "testgen"; + internal const string TestGenOptionsRoot = "sample-gen"; private const string TestGenOptionsFormat = $"{TestGenOptionsRoot}.{{0}}"; public string? SourceCodePath { get; } + public string? OutputFolder { get; } public bool Mock { get; } public bool Sample { get; } public IReadOnlyList SkippedOperations { get; } + public bool ClearOutputFolder { get; } public MgmtTestConfiguration( IReadOnlyList skippedOperations, JsonElement? sourceCodePath = default, JsonElement? mock = default, - JsonElement? sample = default) + JsonElement? sample = default, + JsonElement? outputFolder = default, + JsonElement? clearOutputFolder = default) { SkippedOperations = skippedOperations; SourceCodePath = !Configuration.IsValidJsonElement(sourceCodePath) ? null : sourceCodePath.ToString(); Mock = Configuration.DeserializeBoolean(mock, false); - Sample = Configuration.DeserializeBoolean(sample, false); + Sample = Configuration.DeserializeBoolean(sample, true); + OutputFolder = !Configuration.IsValidJsonElement(outputFolder) ? null : Configuration.TrimFileSuffix(outputFolder.ToString() ?? ""); + ClearOutputFolder = Configuration.DeserializeBoolean(clearOutputFolder, false); } internal static MgmtTestConfiguration? LoadConfiguration(JsonElement root) @@ -42,6 +48,8 @@ public MgmtTestConfiguration( testGenRoot.TryGetProperty(nameof(SourceCodePath), out var sourceCodePath); testGenRoot.TryGetProperty(nameof(Mock), out var mock); testGenRoot.TryGetProperty(nameof(Sample), out var sample); + testGenRoot.TryGetProperty(nameof(OutputFolder), out var testGenOutputFolder); + testGenRoot.TryGetProperty(nameof(ClearOutputFolder), out var testGenClearOutputFolder); var skippedOperations = Configuration.DeserializeArray(skippedOperationsElement); @@ -49,7 +57,9 @@ public MgmtTestConfiguration( skippedOperations, sourceCodePath: sourceCodePath, mock: mock, - sample: sample); + sample: sample, + outputFolder: testGenOutputFolder, + clearOutputFolder: testGenClearOutputFolder); } internal static MgmtTestConfiguration? GetConfiguration(IPluginCommunication autoRest) @@ -61,7 +71,9 @@ public MgmtTestConfiguration( skippedOperations: autoRest.GetValue(string.Format(TestGenOptionsFormat, "skipped-operations")).GetAwaiter().GetResult() ?? Array.Empty(), sourceCodePath: autoRest.GetValue(string.Format(TestGenOptionsFormat, "source-path")).GetAwaiter().GetResult(), mock: autoRest.GetValue(string.Format(TestGenOptionsFormat, "mock")).GetAwaiter().GetResult(), - sample: autoRest.GetValue(string.Format(TestGenOptionsFormat, "sample")).GetAwaiter().GetResult()); + sample: autoRest.GetValue(string.Format(TestGenOptionsFormat, "sample")).GetAwaiter().GetResult(), + outputFolder: autoRest.GetValue(string.Format(TestGenOptionsFormat, "output-folder")).GetAwaiter().GetResult(), + clearOutputFolder: autoRest.GetValue(string.Format(TestGenOptionsFormat, "clear-output-folder")).GetAwaiter().GetResult()); } internal void SaveConfiguration(Utf8JsonWriter writer) diff --git a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs index a32e837f34d..3b4ed1383ca 100644 --- a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs +++ b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs @@ -25,11 +25,14 @@ internal class MgmtTestOutputLibrary private readonly MgmtTestConfiguration _mgmtTestConfiguration; public MgmtTestOutputLibrary(CodeModel codeModel, SourceInputModel sourceInputModel) { - MgmtContext.Initialize(new BuildContext(codeModel, sourceInputModel)); - - // force trigger the model initialization - foreach (var _ in MgmtContext.Library.ResourceSchemaMap) + if (!MgmtContext.IsInitialized) { + MgmtContext.Initialize(new BuildContext(codeModel, sourceInputModel)); + + // force trigger the model initialization + foreach (var _ in MgmtContext.Library.ResourceSchemaMap) + { + } } _mockTestModel = MgmtContext.CodeModel.TestModel!.MockTest; diff --git a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs index 2a40ea978b6..812c42515c9 100644 --- a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs +++ b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs @@ -5,8 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Net.NetworkInformation; using System.Threading.Tasks; -using AutoRest.CSharp.Generation.Writers; using AutoRest.CSharp.Input; using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.MgmtTest.AutoRest; @@ -17,20 +17,29 @@ namespace AutoRest.CSharp.AutoRest.Plugins { internal class MgmtTestTarget { - public static async Task ExecuteAsync(GeneratedCodeWorkspace project, CodeModel codeModel) + private const string SOURCE_DEFAULT_FOLDER_NAME = "src"; + private const string SOURCE_DEFAULT_OUTPUT_PATH = $"/{SOURCE_DEFAULT_FOLDER_NAME}/Generated"; + private const string MOCK_TEST_DEFAULT_OUTPUT_PATH = "/tests/Generated"; + private const string SAMPLE_DEFAULT_OUTPUT_PATH = "/samples/Generated"; + + public static async Task ExecuteAsync(GeneratedCodeWorkspace project, CodeModel codeModel, SourceInputModel? sourceInputModel) { Debug.Assert(codeModel.TestModel is not null); Debug.Assert(Configuration.MgmtTestConfiguration is not null); - var sourceCodePath = GetSourceCodePath(); - var sourceCodeProject = new SourceCodeProject(sourceCodePath, Configuration.SharedSourceFolders); - var sourceInputModel = new SourceInputModel(await sourceCodeProject.GetCompilationAsync()); - - // construct the MgmtTestOutputLibrary - var library = new MgmtTestOutputLibrary(codeModel, sourceInputModel); - - // add the files in the source code project into the GeneratedCodeWorkspace so that our Roslyn could know how to simplify them - project.AddDirectory(sourceCodePath); + MgmtTestOutputLibrary? library = null; + if (sourceInputModel == null) + { + var sourceFolder = GetSourceFolder(); + var sourceCodeProject = new SourceCodeProject(sourceFolder, Configuration.SharedSourceFolders); + sourceInputModel = new SourceInputModel(await sourceCodeProject.GetCompilationAsync()); + library = new MgmtTestOutputLibrary(codeModel, sourceInputModel); + project.AddDirectory(sourceFolder); + } + else + { + library = new MgmtTestOutputLibrary(codeModel, sourceInputModel); + } if (Configuration.MgmtTestConfiguration.Mock) { @@ -44,17 +53,24 @@ public static async Task ExecuteAsync(GeneratedCodeWorkspace project, CodeModel if (_overriddenProjectFilenames.TryGetValue(project, out var overriddenFilenames)) throw new InvalidOperationException($"At least one file was overridden during the generation process. Filenames are: {string.Join(", ", overriddenFilenames)}"); + + if (Configuration.MgmtTestConfiguration.ClearOutputFolder) + { + ClearOutputFolder(); + } } private static void WriteMockTests(GeneratedCodeWorkspace project, MgmtTestOutputLibrary library) { + string outputFolder = GetOutputFolder(MOCK_TEST_DEFAULT_OUTPUT_PATH); + // write the collection mock tests foreach (var collectionTest in library.ResourceCollectionMockTests) { var collectionTestWriter = new ResourceCollectionMockTestWriter(collectionTest); collectionTestWriter.Write(); - AddGeneratedFile(project, $"Mock/{collectionTest.Type.Name}.cs", collectionTestWriter.ToString()); + AddGeneratedFile(project, Path.Combine(outputFolder, $"Mock/{collectionTest.Type.Name}.cs"), collectionTestWriter.ToString()); } foreach (var resourceTest in library.ResourceMockTests) @@ -62,18 +78,20 @@ private static void WriteMockTests(GeneratedCodeWorkspace project, MgmtTestOutpu var resourceTestWriter = new ResourceMockTestWriter(resourceTest); resourceTestWriter.Write(); - AddGeneratedFile(project, $"Mock/{resourceTest.Type.Name}.cs", resourceTestWriter.ToString()); + AddGeneratedFile(project, Path.Combine(outputFolder, $"Mock/{resourceTest.Type.Name}.cs"), resourceTestWriter.ToString()); } var extensionWrapperTest = library.ExtensionWrapperMockTest; var extensionWrapperTestWriter = new ExtensionWrapMockTestWriter(extensionWrapperTest, library.ExtensionMockTests); extensionWrapperTestWriter.Write(); - AddGeneratedFile(project, $"Mock/{extensionWrapperTest.Type.Name}.cs", extensionWrapperTestWriter.ToString()); + AddGeneratedFile(project, Path.Combine(outputFolder, $"Mock/{extensionWrapperTest.Type.Name}.cs"), extensionWrapperTestWriter.ToString()); } private static void WriteSamples(GeneratedCodeWorkspace project, MgmtTestOutputLibrary library) { + string outputFolder = GetOutputFolder(SAMPLE_DEFAULT_OUTPUT_PATH); + var names = new Dictionary(); foreach (var sample in library.Samples) { @@ -81,7 +99,7 @@ private static void WriteSamples(GeneratedCodeWorkspace project, MgmtTestOutputL sampleWriter.Write(); var filename = GetFilename(sample.Type.Name, names); - AddGeneratedFile(project, $"Samples/{filename}.cs", sampleWriter.ToString()); + AddGeneratedFile(project, Path.Combine(outputFolder, $"Samples/{filename}.cs"), sampleWriter.ToString()); } } @@ -97,15 +115,89 @@ private static string GetFilename(string name, Dictionary names) return name; } - private static string GetSourceCodePath() + private static void ClearOutputFolder() { - if (Configuration.MgmtTestConfiguration?.SourceCodePath != null) + if (Configuration.MgmtTestConfiguration == null || + string.IsNullOrEmpty(Configuration.MgmtTestConfiguration.OutputFolder)) + return; + DirectoryInfo di = new DirectoryInfo(Configuration.MgmtTestConfiguration.OutputFolder); + ClearFolder(di); + } + + private static void ClearFolder(DirectoryInfo di) + { + if (di.Exists) + { + foreach (FileInfo fi in di.EnumerateFiles()) + { + try + { + fi.Delete(); + } + // Ignore the error from clearing folder + catch { } + } + foreach (DirectoryInfo subFolder in di.EnumerateDirectories()) + { + ClearFolder(subFolder); + try + { + subFolder.Delete(); + } + // Ignore the error from clearing folder + catch { } + } + } + } + + private static string GetOutputFolder(string defaultOutputPath) + { + if (!string.IsNullOrEmpty(Configuration.MgmtTestConfiguration?.OutputFolder)) + return Configuration.MgmtTestConfiguration.OutputFolder; + + string folder = FormatPath(Configuration.OutputFolder); + // if the output folder is not given explicitly, try to figure it out from general output folder if possible according to default folder structure: + // Azure.ResourceManager.XXX \ src \ Generated <- default sdk source output folder + // \ samples(or tests) \ Generated <- default sample output folder defined in msbuild + if (folder.EndsWith(SOURCE_DEFAULT_OUTPUT_PATH, StringComparison.InvariantCultureIgnoreCase)) + return FormatPath(Path.Combine(folder, $"../..", defaultOutputPath)); + else if (folder.EndsWith(SAMPLE_DEFAULT_OUTPUT_PATH, StringComparison.InvariantCultureIgnoreCase) || folder.EndsWith(MOCK_TEST_DEFAULT_OUTPUT_PATH, StringComparison.InvariantCultureIgnoreCase)) + return folder; + else + throw new InvalidOperationException("'sample-gen.output-folder' is not configured and can't figure it out from give general output-folder"); + } + + private static string GetSourceFolder() + { + if (!string.IsNullOrEmpty(Configuration.MgmtTestConfiguration?.SourceCodePath)) return Configuration.MgmtTestConfiguration.SourceCodePath; - // try to find the sdk source code path according to the default folder structure + string folder = FormatPath(Configuration.OutputFolder); + string testFolder = FormatPath(Configuration.MgmtTestConfiguration?.OutputFolder); + + if (!string.IsNullOrEmpty(Configuration.MgmtTestConfiguration?.OutputFolder) && + !string.Equals(folder, testFolder, StringComparison.InvariantCultureIgnoreCase)) + { + // if the general output folder and our output folder is different, the general output folder should point to the sdk code folder src\Generated + return FormatPath(Path.Combine(Configuration.OutputFolder, "..")); + } + + // if only the general output folder is given or it's the same as our output folder. Let's try to figure it out from given output folder if possible according to default folder structure: // Azure.ResourceManager.XXX \ src <- default sdk source folder - // \ samples \ Generated <- default sample output folder defined in msbuild - return Path.Combine(Configuration.OutputFolder, "../../src"); + // \ samples(or tests) \ Generated <- default sample output folder defined in msbuild + if (folder.EndsWith(SOURCE_DEFAULT_OUTPUT_PATH, StringComparison.InvariantCultureIgnoreCase)) + return FormatPath(Path.Combine(folder, "..")); + else if (folder.EndsWith(SAMPLE_DEFAULT_OUTPUT_PATH, StringComparison.InvariantCultureIgnoreCase) || folder.EndsWith(MOCK_TEST_DEFAULT_OUTPUT_PATH, StringComparison.InvariantCultureIgnoreCase)) + return FormatPath(Path.Combine(folder, "../..", SOURCE_DEFAULT_FOLDER_NAME)); + else + throw new InvalidOperationException("'sample-gen.source-path' is not configured and can't figure it out from give output-folder and sample-gen.output-folder"); + } + + private static string FormatPath(string? path) + { + if (string.IsNullOrEmpty(path)) + return path ?? ""; + return Path.GetFullPath(path.TrimEnd('/', '\\')).Replace("\\", "/"); } private static IDictionary> _addedProjectFilenames = new Dictionary>(); diff --git a/src/AutoRest.CSharp/build/CodeGeneration.targets b/src/AutoRest.CSharp/build/CodeGeneration.targets index 3beeb0355b7..3e0e5420faa 100644 --- a/src/AutoRest.CSharp/build/CodeGeneration.targets +++ b/src/AutoRest.CSharp/build/CodeGeneration.targets @@ -30,7 +30,7 @@ <_GenerateCode Condition="'$(AutoRestInput)' != '' OR '$(TypeSpecInput)' != ''">true true - <_AutoRestCommand>node $(AutoRestEntryPoint) --max-memory-size=8192 --skip-csproj --skip-upgrade-check --version=$(AutoRestCoreVersion) $(AutoRestInput) $(AutoRestAdditionalParameters) --use=$(MSBuildThisFileDirectory)../tools/net6.0/any/ --clear-output-folder=true --shared-source-folders="$(AzureCoreSharedCodeDirectory);$(AutoRestSharedCodeDirectory)" + <_AutoRestCommand>npx autorest@$(AutoRestVersion) --max-memory-size=8192 --skip-csproj --skip-upgrade-check --version=$(AutoRestCoreVersion) $(AutoRestInput) $(AutoRestAdditionalParameters) --use=$(MSBuildThisFileDirectory)../tools/net6.0/any/ --clear-output-folder=true --shared-source-folders="$(AzureCoreSharedCodeDirectory);$(AutoRestSharedCodeDirectory)" <_AutoRestCommand Condition="'$(UseDefaultNamespaceAndOutputFolder)' == 'true'">$(_AutoRestCommand) --output-folder=$(MSBuildProjectDirectory)/Generated --namespace=$(RootNamespace) <_SaveInputs Condition="'$(SaveInputs)' == 'true'">-SaveInputs <_TypespecAdditionalOptions Condition="'$(TypespecAdditionalOptions)' != ''">-TypespecAdditionalOptions "$(TypespecAdditionalOptions)" @@ -60,12 +60,10 @@ - - + - - - + + @@ -77,7 +75,7 @@ - + diff --git a/src/AutoRest.CSharp/readme.md b/src/AutoRest.CSharp/readme.md index 0529b324873..b3a05a12288 100644 --- a/src/AutoRest.CSharp/readme.md +++ b/src/AutoRest.CSharp/readme.md @@ -34,7 +34,7 @@ pipeline: scope: output-scope ``` -```yaml $(testgen) +```yaml $(sample-gen) use-extension: "@autorest/testmodeler": "2.6.1" @@ -54,6 +54,8 @@ testmodeler: use-parents-value: true split-parents-value: false add-armtemplate-payload-string: true + +include-x-ms-examples-original-file: true # export-explicit-type: true ``` diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Configuration.json b/test/TestProjects/MgmtMockAndSample/tests/Generated/Configuration.json index 550f0622bed..676f30b3fb0 100644 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Configuration.json +++ b/test/TestProjects/MgmtMockAndSample/tests/Generated/Configuration.json @@ -42,7 +42,7 @@ "Type": "EncryptionType", "FirewallPolicyThreatIntelWhitelist.ipAddresses": "-|ip-address" }, - "testgen": { + "sample-gen": { "SkippedOperations": [ "Vaults_GetDeleted", "Vaults_Update" diff --git a/test/TestProjects/MgmtMockAndSample/tests/readme.md b/test/TestProjects/MgmtMockAndSample/tests/readme.md index 30f1eec1161..07e7839eaa0 100644 --- a/test/TestProjects/MgmtMockAndSample/tests/readme.md +++ b/test/TestProjects/MgmtMockAndSample/tests/readme.md @@ -5,9 +5,14 @@ ``` yaml require: ../src/readme.md -testgen: +include-x-ms-examples-original-file: false +mgmt-debug: + skip-codegen: true +sample-gen: mock: true sample: true + output-folder: $(this-folder)/Generated + clear-output-folder: true skipped-operations: # only to test if the configuration works - Vaults_GetDeleted - Vaults_Update