diff --git a/readme.md b/readme.md
index 971d47b36b1..71e18535fe3 100644
--- a/readme.md
+++ b/readme.md
@@ -50,6 +50,7 @@ ___
- [Change operation accessibility in bulk](#change-operation-accessibility-in-bulk)
- [Exclude models from namespace](#exclude-models-from-namespace)
- [Extending a model with additional constructors](#extending-a-model-with-additional-constructors)
+ - [Change the file license header](#change-the-file-license-header)
- [Management plane concepts and configurations](#management-plane-concepts-and-configurations)
@@ -1788,6 +1789,16 @@ namespace Azure.Service.Models
+### Change the file license header
+
+
+Add the `--custom-header="// Your header content\n"` option to the autorest command, or add the following configuration in your `md` file for autorest
+```yaml
+custom-header: "// Your header content\n"
+```
+to change the file license headers in all generated files.
+
+
Repository-specific pipeline configuration
diff --git a/src/AutoRest.CSharp/Common/Input/AzureApiTypes.cs b/src/AutoRest.CSharp/Common/Input/AzureApiTypes.cs
index d5e181482ee..5d5ffcef4ce 100644
--- a/src/AutoRest.CSharp/Common/Input/AzureApiTypes.cs
+++ b/src/AutoRest.CSharp/Common/Input/AzureApiTypes.cs
@@ -88,7 +88,7 @@ public override ValueExpression GetKeySampleExpression(string clientName)
public override ExtensibleSnippets ExtensibleSnippets { get; } = new AzureExtensibleSnippets();
- public override string LicenseString => """
+ public override string LicenseString => Configuration.CustomHeader ?? """
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
diff --git a/src/AutoRest.CSharp/Common/Input/Configuration.cs b/src/AutoRest.CSharp/Common/Input/Configuration.cs
index 3987159c399..f462cb1d8a8 100644
--- a/src/AutoRest.CSharp/Common/Input/Configuration.cs
+++ b/src/AutoRest.CSharp/Common/Input/Configuration.cs
@@ -66,6 +66,7 @@ public static class Options
public const string EnableInternalRawData = "enable-internal-raw-data";
public const string HelperNamespace = "helper-namespace";
public const string DisableXmlDocs = "disable-xml-docs";
+ public const string CustomHeader = "custom-header";
}
public enum UnreferencedTypesHandlingOption
@@ -117,7 +118,8 @@ public static void Initialize(
bool generateSampleProject,
bool generateTestProject,
string? examplesDirectory,
- string? helperNamespace)
+ string? helperNamespace,
+ string? customHeader)
{
_outputFolder = outputFolder;
_namespace = ns;
@@ -191,6 +193,7 @@ public static void Initialize(
GenerateSampleProject = DisableXmlDocs ? false : generateSampleProject; // turn off the samples if all xml docs are explicitly disabled
GenerateTestProject = generateTestProject;
ExamplesDirectory = examplesDirectory;
+ CustomHeader = customHeader;
_helperNamespace = helperNamespace ?? Namespace;
}
@@ -249,6 +252,8 @@ internal static (string AbsoluteProjectFolder, string RelativeProjectFolder) Par
private static string? _helperNamespace;
public static string HelperNamespace => _helperNamespace ?? throw new InvalidOperationException("Configuration has not been initialized");
+ public static string? CustomHeader { get; private set; }
+
public static bool DisableXmlDocs { get; private set; }
public static bool GenerateSampleProject { get; private set; }
@@ -396,7 +401,8 @@ public static void Initialize(IPluginCommunication autoRest, string defaultNames
generateTestProject: GetOptionBoolValue(autoRest, Options.GenerateTestProject),
examplesDirectory: null, // TODO -- what we put here?
helperNamespace: autoRest.GetValue(Options.HelperNamespace).GetAwaiter().GetResult(),
- disableXmlDocs: GetOptionBoolValue(autoRest, Options.DisableXmlDocs)
+ disableXmlDocs: GetOptionBoolValue(autoRest, Options.DisableXmlDocs),
+ customHeader: autoRest.GetValue(Options.CustomHeader).GetAwaiter().GetResult()
);
}
@@ -569,12 +575,12 @@ internal static void LoadConfiguration(JsonElement root, string? projectPath, st
mgmtConfiguration: MgmtConfiguration.LoadConfiguration(root),
mgmtTestConfiguration: MgmtTestConfiguration.LoadConfiguration(root),
flavor: ReadStringOption(root, Options.Flavor),
- disableXmlDocs: ReadOption(root, Options.DisableXmlDocs)
-,
+ disableXmlDocs: ReadOption(root, Options.DisableXmlDocs),
generateSampleProject: ReadOption(root, Options.GenerateSampleProject),
generateTestProject: ReadOption(root, Options.GenerateTestProject),
examplesDirectory: ReadStringOption(root, Options.ExamplesDirectory),
- helperNamespace: ReadStringOption(root, Options.HelperNamespace));
+ helperNamespace: ReadStringOption(root, Options.HelperNamespace),
+ customHeader: ReadStringOption(root, Options.CustomHeader));
}
internal static string SaveConfiguration()
@@ -644,6 +650,7 @@ private static void WriteConfiguration(Utf8JsonWriter writer)
WriteIfNotDefault(writer, Options.GenerateTestProject, GenerateTestProject);
WriteIfNotDefault(writer, Options.HelperNamespace, HelperNamespace);
WriteIfNotDefault(writer, Options.DisableXmlDocs, DisableXmlDocs);
+ WriteIfNotDefault(writer, Options.CustomHeader, CustomHeader);
writer.WriteEndObject();
}
diff --git a/src/AutoRest.CSharp/Common/Input/SystemApiTypes.cs b/src/AutoRest.CSharp/Common/Input/SystemApiTypes.cs
index 0435e241326..13a95b0343b 100644
--- a/src/AutoRest.CSharp/Common/Input/SystemApiTypes.cs
+++ b/src/AutoRest.CSharp/Common/Input/SystemApiTypes.cs
@@ -8,7 +8,6 @@
using AutoRest.CSharp.Common.Output.Expressions.KnownValueExpressions;
using AutoRest.CSharp.Common.Output.Expressions.System;
using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
-using AutoRest.CSharp.Common.Output.Models.Types.HelperTypeProviders;
using AutoRest.CSharp.Generation.Types;
using AutoRest.CSharp.Generation.Writers;
using AutoRest.CSharp.Output.Models;
@@ -99,7 +98,7 @@ public override ValueExpression GetKeySampleExpression(string clientName)
public override ExtensibleSnippets ExtensibleSnippets { get; } = new SystemExtensibleSnippets();
- public override string LicenseString => string.Empty;
+ public override string LicenseString => Configuration.CustomHeader ?? string.Empty;
public override string ResponseClassifierIsErrorResponseName => nameof(PipelineMessageClassifier.TryClassify);
}
diff --git a/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs b/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs
index 19ea12b6959..9ae09a3da19 100644
--- a/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs
+++ b/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs
@@ -116,7 +116,8 @@ public void Method(int? nullableInt, List intList, List nullableIntLi
generateSampleProject: true,
generateTestProject: true,
examplesDirectory: null,
- helperNamespace: "");
+ helperNamespace: "",
+ customHeader: null);
}
[Test]
diff --git a/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs b/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs
index 76b5951ed90..2600a4e871a 100644
--- a/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs
+++ b/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs
@@ -93,7 +93,8 @@ public void Setup()
generateSampleProject: true,
generateTestProject: true,
examplesDirectory: null,
- helperNamespace: "");
+ helperNamespace: "",
+ customHeader: null);
}
private void TestPair(ResourceMatchType expected, string httpMethod, string resourcePathStr, string requestPathStr, bool isList)
diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs
index c0f0fede6b2..f438e514000 100644
--- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs
+++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs
@@ -74,7 +74,8 @@ public void Initialize()
generateSampleProject: true,
generateTestProject: true,
examplesDirectory: null,
- helperNamespace: "");
+ helperNamespace: "",
+ customHeader: null);
}