From 8e9c2d3704a04913a175ab76972b7d9597c77687 Mon Sep 17 00:00:00 2001 From: Johannes Bader Date: Mon, 26 Jun 2017 10:15:30 -0700 Subject: [PATCH] max-comment-columns setting (#2392) * max cols setting * added sample * go default comm cols to 120 * regen * package-version for go --- .../1b-code-generation-multilang/Go/client.go | 3 +-- .../1b-code-generation-multilang/Go/models.go | 3 +-- .../1b-code-generation-multilang/Go/version.go | 3 +-- Samples/1d-common-settings/readme.md | 2 ++ .../stream-with-content-type/ClientGo/client.go | 3 +-- .../ClientGo/imagegroup.go | 16 ++++++---------- .../stream-with-content-type/ClientGo/models.go | 3 +-- .../stream-with-content-type/ClientGo/version.go | 3 +-- src/core/AutoRest.Core/Settings.cs | 5 +++++ src/core/AutoRest.Core/Template.cs | 4 +--- src/core/AutoRest/Plugins/Generator.cs | 6 ++++++ src/generator/AutoRest.Python/PythonTemplate.cs | 5 ++--- 12 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Samples/1b-code-generation-multilang/Go/client.go b/Samples/1b-code-generation-multilang/Go/client.go index 306a3ab93..053f9f698 100644 --- a/Samples/1b-code-generation-multilang/Go/client.go +++ b/Samples/1b-code-generation-multilang/Go/client.go @@ -4,8 +4,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( "github.com/Azure/go-autorest/autorest" diff --git a/Samples/1b-code-generation-multilang/Go/models.go b/Samples/1b-code-generation-multilang/Go/models.go index 7ac3edc30..311bc010f 100644 --- a/Samples/1b-code-generation-multilang/Go/models.go +++ b/Samples/1b-code-generation-multilang/Go/models.go @@ -1,8 +1,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( "github.com/Azure/go-autorest/autorest" diff --git a/Samples/1b-code-generation-multilang/Go/version.go b/Samples/1b-code-generation-multilang/Go/version.go index f59007210..277e837c6 100644 --- a/Samples/1b-code-generation-multilang/Go/version.go +++ b/Samples/1b-code-generation-multilang/Go/version.go @@ -1,8 +1,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. // UserAgent returns the UserAgent string to use when sending http.Requests. diff --git a/Samples/1d-common-settings/readme.md b/Samples/1d-common-settings/readme.md index 9a9621620..0f7b30274 100644 --- a/Samples/1d-common-settings/readme.md +++ b/Samples/1d-common-settings/readme.md @@ -61,6 +61,7 @@ Some settings are specific to plugins, such as: - `sync-methods` which allows specifying whether synchronous wrappers for asynchronous methods should be generated (discouraged!) - `payload-flattening-threshold` which controls whether a body parameter should be passed directly (as an argument to the generated method) or whether its properties should be passed as arguments. As the latter option makes sense for body parameter types with few properties (less overhead for `new`ing), this setting is a threshold specifying when to use which option. - `client-side-validation` which controls whether or not client side validation of constrains such as `minLength`, `maximum` or `pattern` is desired +- `max-comment-columns` which controls the maximum number columns occupied by multiline comments ``` yaml csharp: @@ -71,4 +72,5 @@ csharp: sync-methods: none # other possible values: essential, all payload-flattening-threshold: 3 # body parameter types with 3 or less properties cause method to expect those properties instead of an object client-side-validation: false # disable client side validation + max-comment-columns: 80 # multiline comments shall not be wider than 80 characters ``` diff --git a/Samples/test/stream-with-content-type/ClientGo/client.go b/Samples/test/stream-with-content-type/ClientGo/client.go index 7e4c66909..eb18d7f43 100644 --- a/Samples/test/stream-with-content-type/ClientGo/client.go +++ b/Samples/test/stream-with-content-type/ClientGo/client.go @@ -4,8 +4,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( "github.com/Azure/go-autorest/autorest" diff --git a/Samples/test/stream-with-content-type/ClientGo/imagegroup.go b/Samples/test/stream-with-content-type/ClientGo/imagegroup.go index 91ef6b596..13d6a6eff 100644 --- a/Samples/test/stream-with-content-type/ClientGo/imagegroup.go +++ b/Samples/test/stream-with-content-type/ClientGo/imagegroup.go @@ -1,8 +1,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( "github.com/Azure/go-autorest/autorest" @@ -20,17 +19,15 @@ func NewImageGroupClient() ImageGroupClient { return NewImageGroupClientWithBaseURI(DefaultBaseURI, ) } -// NewImageGroupClientWithBaseURI creates an instance of the ImageGroupClient -// client. +// NewImageGroupClientWithBaseURI creates an instance of the ImageGroupClient client. func NewImageGroupClientWithBaseURI(baseURI string, ) ImageGroupClient { return ImageGroupClient{ NewWithBaseURI(baseURI, )} } // AMethod sends the a method request. // -// imageParameter is an image stream. imageParameter will be closed upon -// successful return. Callers should ensure closure when receiving an -// error.imageContentType is the content type of the image. +// imageParameter is an image stream. imageParameter will be closed upon successful return. Callers should ensure +// closure when receiving an error.imageContentType is the content type of the image. func (client ImageGroupClient) AMethod(imageParameter io.ReadCloser, imageContentType ContentTypeEnum) (result autorest.Response, err error) { req, err := client.AMethodPreparer(imageParameter, imageContentType) if err != nil { @@ -87,9 +84,8 @@ func (client ImageGroupClient) AMethodResponder(resp *http.Response) (result aut // BMethod sends the b method request. // -// imageParameter is an image stream. imageParameter will be closed upon -// successful return. Callers should ensure closure when receiving an -// error.imageContentType is the content type of the image. +// imageParameter is an image stream. imageParameter will be closed upon successful return. Callers should ensure +// closure when receiving an error.imageContentType is the content type of the image. func (client ImageGroupClient) BMethod(imageParameter io.ReadCloser, imageContentType ContentTypeEnum) (result autorest.Response, err error) { req, err := client.BMethodPreparer(imageParameter, imageContentType) if err != nil { diff --git a/Samples/test/stream-with-content-type/ClientGo/models.go b/Samples/test/stream-with-content-type/ClientGo/models.go index b1481581c..2030302f2 100644 --- a/Samples/test/stream-with-content-type/ClientGo/models.go +++ b/Samples/test/stream-with-content-type/ClientGo/models.go @@ -1,8 +1,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. // ContentTypeEnum enumerates the values for content type enum. type ContentTypeEnum string diff --git a/Samples/test/stream-with-content-type/ClientGo/version.go b/Samples/test/stream-with-content-type/ClientGo/version.go index a252ad379..469e6ec57 100644 --- a/Samples/test/stream-with-content-type/ClientGo/version.go +++ b/Samples/test/stream-with-content-type/ClientGo/version.go @@ -1,8 +1,7 @@ package // Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0 -// Changes may cause incorrect behavior and will be lost if the code is -// regenerated. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. // UserAgent returns the UserAgent string to use when sending http.Requests. diff --git a/src/core/AutoRest.Core/Settings.cs b/src/core/AutoRest.Core/Settings.cs index c57a54bd0..9db9b7e5f 100644 --- a/src/core/AutoRest.Core/Settings.cs +++ b/src/core/AutoRest.Core/Settings.cs @@ -33,6 +33,8 @@ namespace AutoRest.Core } public class Settings : IsSingleton { + public const int DefaultMaximumCommentColumns = 80; + public const string DefaultCodeGenerationHeader = @"Code generated by Microsoft (R) AutoRest Code Generator {0} Changes may cause incorrect behavior and will be lost if the code is regenerated."; @@ -88,6 +90,7 @@ Licensed under the MIT License. See License.txt in the project root for license ValidationLevel = Category.Error; ModelsName = "Models"; CodeGenerationMode = "rest-client"; + MaximumCommentColumns = DefaultMaximumCommentColumns; } /// @@ -112,6 +115,8 @@ Licensed under the MIT License. See License.txt in the project root for license #region ordered_properties + public int MaximumCommentColumns { get; set; } + /// /// Gets or sets the path to the input specification file. /// diff --git a/src/core/AutoRest.Core/Template.cs b/src/core/AutoRest.Core/Template.cs index 23809cd2a..2c7c1f653 100644 --- a/src/core/AutoRest.Core/Template.cs +++ b/src/core/AutoRest.Core/Template.cs @@ -16,8 +16,6 @@ namespace AutoRest.Core /// public class Template : ITemplate { - protected const int MaximumCommentColumn = 80; - private string _indentation; private string _lastLiteral = String.Empty; @@ -232,7 +230,7 @@ namespace AutoRest.Core } int available = - MaximumCommentColumn - // Maximum desired width + (Settings.Instance?.MaximumCommentColumns ?? Settings.DefaultMaximumCommentColumns) - // Maximum desired width Indentation.Length - // - Space used for indent prefix.Length - // - Prefix //'s length 1; // - Extra space between prefix and text diff --git a/src/core/AutoRest/Plugins/Generator.cs b/src/core/AutoRest/Plugins/Generator.cs index e8c01e9db..622b14448 100644 --- a/src/core/AutoRest/Plugins/Generator.cs +++ b/src/core/AutoRest/Plugins/Generator.cs @@ -84,6 +84,8 @@ public class Generator : NewPlugin Settings.Instance.CustomSettings.Add("SyncMethods", GetXmsCodeGenSetting(sd, "syncMethods") ?? await GetValue("sync-methods") ?? "essential"); Settings.Instance.CustomSettings.Add("UseDateTimeOffset", GetXmsCodeGenSetting(sd, "useDateTimeOffset") ?? await GetValue("use-datetimeoffset") ?? false); Settings.Instance.CustomSettings["ClientSideValidation"] = await GetValue("client-side-validation") ?? false; + int defaultMaximumCommentColumns = codeGenerator == "go" ? 120 : Settings.DefaultMaximumCommentColumns; + Settings.Instance.MaximumCommentColumns = await GetValue("max-comment-columns") ?? defaultMaximumCommentColumns; if (codeGenerator == "csharp") { Settings.Instance.OutputFileName = await GetValue("output-file"); @@ -96,6 +98,10 @@ public class Generator : NewPlugin Settings.Instance.PackageName = await GetValue("package-name"); Settings.Instance.PackageVersion = await GetValue("package-version"); } + if (codeGenerator == "go") + { + Settings.Instance.PackageVersion = await GetValue("package-version"); + } // process var plugin = ExtensionsLoader.GetPlugin( diff --git a/src/generator/AutoRest.Python/PythonTemplate.cs b/src/generator/AutoRest.Python/PythonTemplate.cs index ffe1e6615..13c29b184 100644 --- a/src/generator/AutoRest.Python/PythonTemplate.cs +++ b/src/generator/AutoRest.Python/PythonTemplate.cs @@ -19,14 +19,13 @@ namespace AutoRest.Python comment = comment.Replace("\\", "\\\\"); int available = - MaximumCommentColumn - // Maximum desired width + (Settings.Instance?.MaximumCommentColumns ?? Settings.DefaultMaximumCommentColumns) - // Maximum desired width Indentation.Length - // - Space used for indent prefix.Length - // - Prefix //'s length 1 - // - Extra space between prefix and text 1; // - Extra space for parameter start - return string.Join(Environment.NewLine + " ", comment.WordWrap(available) - .Select(s => string.Format(CultureInfo.InvariantCulture, "{0}{1}", prefix, s))); + return string.Join(Environment.NewLine + " ", comment.WordWrap(available).Select(s => $"{prefix}{s}")); } } }