From 88207c1a13657630078ef62eddc83bc4cf939458 Mon Sep 17 00:00:00 2001 From: Bruce Johnston Date: Tue, 14 Jun 2016 14:53:34 -0700 Subject: [PATCH 1/5] Regenerating expected C# generated code and samples --- .../AzureBodyDurationAllSync/AutoRestDurationTestService.cs | 5 +++++ .../AzureBodyDurationNoSync/AutoRestDurationTestService.cs | 5 +++++ .../azure-storage/Azure.CSharp/StorageManagementClient.cs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationAllSync/AutoRestDurationTestService.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationAllSync/AutoRestDurationTestService.cs index 343555c4d5..9c060715e6 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationAllSync/AutoRestDurationTestService.cs +++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationAllSync/AutoRestDurationTestService.cs @@ -264,6 +264,10 @@ public AutoRestDurationTestService(Uri baseUri, ServiceClientCredentials credent } } + /// + /// An optional partial-method to perform custom initialization. + /// + partial void CustomInitialize(); /// /// Initializes client properties. /// @@ -299,6 +303,7 @@ private void Initialize() new Iso8601TimeSpanConverter() } }; + CustomInitialize(); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); } } diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationNoSync/AutoRestDurationTestService.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationNoSync/AutoRestDurationTestService.cs index bd9a8b84b5..f0afb3fe28 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationNoSync/AutoRestDurationTestService.cs +++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureBodyDurationNoSync/AutoRestDurationTestService.cs @@ -264,6 +264,10 @@ public AutoRestDurationTestService(Uri baseUri, ServiceClientCredentials credent } } + /// + /// An optional partial-method to perform custom initialization. + /// + partial void CustomInitialize(); /// /// Initializes client properties. /// @@ -299,6 +303,7 @@ private void Initialize() new Iso8601TimeSpanConverter() } }; + CustomInitialize(); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); } } diff --git a/Samples/azure-storage/Azure.CSharp/StorageManagementClient.cs b/Samples/azure-storage/Azure.CSharp/StorageManagementClient.cs index 94f5be4417..e1f6eca170 100644 --- a/Samples/azure-storage/Azure.CSharp/StorageManagementClient.cs +++ b/Samples/azure-storage/Azure.CSharp/StorageManagementClient.cs @@ -274,6 +274,10 @@ public StorageManagementClient(Uri baseUri, ServiceClientCredentials credentials } } + /// + /// An optional partial-method to perform custom initialization. + /// + partial void CustomInitialize(); /// /// Initializes client properties. /// @@ -311,6 +315,7 @@ private void Initialize() new Iso8601TimeSpanConverter() } }; + CustomInitialize(); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); } } From 44491b234031a175ebc1c0738fd746ed683e9a47 Mon Sep 17 00:00:00 2001 From: Bruce Johnston Date: Tue, 14 Jun 2016 17:33:03 -0700 Subject: [PATCH 2/5] Adding ExternalDocsUrl to ClientModel --- AutoRest/AutoRest.Core/ClientModel/CompositeType.cs | 5 +++++ AutoRest/AutoRest.Core/ClientModel/Method.cs | 5 +++++ AutoRest/Modelers/Swagger/OperationBuilder.cs | 1 + AutoRest/Modelers/Swagger/SchemaBuilder.cs | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs b/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs index 7e33d9f70e..97b7c07109 100644 --- a/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs +++ b/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs @@ -61,6 +61,11 @@ public IEnumerable ComposedProperties /// public string Documentation { get; set; } + /// + /// Gets or sets a URL pointing to related external documentation. + /// + public string ExternalDocsUrl { get; set; } + /// /// Returns true if any of the properties is a Constant or is /// a CompositeType which ContainsConstantProperties set to true. diff --git a/AutoRest/AutoRest.Core/ClientModel/Method.cs b/AutoRest/AutoRest.Core/ClientModel/Method.cs index 24ab66fe64..81ab689f39 100644 --- a/AutoRest/AutoRest.Core/ClientModel/Method.cs +++ b/AutoRest/AutoRest.Core/ClientModel/Method.cs @@ -135,6 +135,11 @@ public Parameter Body /// public string Summary { get; set; } + /// + /// Gets or sets a URL pointing to related external documentation. + /// + public string ExternalDocsUrl { get; set; } + /// /// Gets or sets the content type. /// diff --git a/AutoRest/Modelers/Swagger/OperationBuilder.cs b/AutoRest/Modelers/Swagger/OperationBuilder.cs index 8eb7a70725..c680c878c5 100644 --- a/AutoRest/Modelers/Swagger/OperationBuilder.cs +++ b/AutoRest/Modelers/Swagger/OperationBuilder.cs @@ -72,6 +72,7 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName, } method.Description = _operation.Description; method.Summary = _operation.Summary; + method.ExternalDocsUrl = _operation.ExternalDocs?.Url; // Service parameters if (_operation.Parameters != null) diff --git a/AutoRest/Modelers/Swagger/SchemaBuilder.cs b/AutoRest/Modelers/Swagger/SchemaBuilder.cs index 545c390422..0b1f18c85b 100644 --- a/AutoRest/Modelers/Swagger/SchemaBuilder.cs +++ b/AutoRest/Modelers/Swagger/SchemaBuilder.cs @@ -66,7 +66,8 @@ public override IType BuildServiceType(string serviceTypeName) { Name = serviceTypeName, SerializedName = serviceTypeName, - Documentation = _schema.Description + Documentation = _schema.Description, + ExternalDocsUrl = _schema.ExternalDocs?.Url }; // Put this in already generated types serializationProperty From 8dad7867f87d93e5c272dbea695f5755f8b021bb Mon Sep 17 00:00:00 2001 From: Bruce Johnston Date: Tue, 14 Jun 2016 18:30:04 -0700 Subject: [PATCH 3/5] Adding support for generating "see" tags in C# and Azure C# summary comments --- .../Templates/AzureMethodTemplate.cshtml | 8 ++++++++ .../Templates/ExtensionMethodTemplate.cshtml | 18 +++++++++++++++--- .../MethodGroupInterfaceTemplate.cshtml | 4 ++++ .../CSharp/Templates/MethodTemplate.cshtml | 4 ++++ .../CSharp/Templates/ModelTemplate.cshtml | 4 ++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/AutoRest/Generators/CSharp/Azure.CSharp/Templates/AzureMethodTemplate.cshtml b/AutoRest/Generators/CSharp/Azure.CSharp/Templates/AzureMethodTemplate.cshtml index 80cceeb7ec..ad6be621b0 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp/Templates/AzureMethodTemplate.cshtml +++ b/AutoRest/Generators/CSharp/Azure.CSharp/Templates/AzureMethodTemplate.cshtml @@ -18,6 +18,10 @@ if (!string.IsNullOrWhiteSpace(Model.Description) || !string.IsNullOrWhiteSpace( { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment()) +if (!string.IsNullOrWhiteSpace(Model.ExternalDocsUrl)) +{ +@:/// +} @:/// } if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary)) @@ -53,6 +57,10 @@ if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summ { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment()) +if (!string.IsNullOrWhiteSpace(Model.ExternalDocsUrl)) +{ +@:/// +} @:/// } if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary)) diff --git a/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml b/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml index 09ba406f08..4de93ac345 100644 --- a/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml +++ b/AutoRest/Generators/CSharp/CSharp/Templates/ExtensionMethodTemplate.cshtml @@ -6,12 +6,16 @@ @using Microsoft.Rest.Generator.Utilities @inherits Microsoft.Rest.Generator.Template @{ - if (Model.SyncMethods == SyncMethodsGenerationMode.All || Model.SyncMethods == SyncMethodsGenerationMode.Essential) +if (Model.SyncMethods == SyncMethodsGenerationMode.All || Model.SyncMethods == SyncMethodsGenerationMode.Essential) +{ + if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary)) { - if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary)) - { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment()) + if (!String.IsNullOrEmpty(Model.ExternalDocsUrl)) + { +@:/// + } @:/// } if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary)) @@ -49,6 +53,10 @@ if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summ { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment()) + if (!String.IsNullOrEmpty(Model.ExternalDocsUrl)) + { +@:/// + } @:/// } if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary)) @@ -105,6 +113,10 @@ foreach (var parameter in Model.LocalParameters) { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment()) + if (!String.IsNullOrEmpty(Model.ExternalDocsUrl)) + { +@:/// + } @:/// } if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary)) diff --git a/AutoRest/Generators/CSharp/CSharp/Templates/MethodGroupInterfaceTemplate.cshtml b/AutoRest/Generators/CSharp/CSharp/Templates/MethodGroupInterfaceTemplate.cshtml index 0ae7db520c..9e70bc65e5 100644 --- a/AutoRest/Generators/CSharp/CSharp/Templates/MethodGroupInterfaceTemplate.cshtml +++ b/AutoRest/Generators/CSharp/CSharp/Templates/MethodGroupInterfaceTemplate.cshtml @@ -27,6 +27,10 @@ namespace @Settings.Namespace { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(method.Summary) ? method.Description.EscapeXmlComment() : method.Summary.EscapeXmlComment()) + if (!String.IsNullOrEmpty(method.ExternalDocsUrl)) + { + @:/// + } @:/// } if (!String.IsNullOrEmpty(method.Description) && !String.IsNullOrEmpty(method.Summary)) diff --git a/AutoRest/Generators/CSharp/CSharp/Templates/MethodTemplate.cshtml b/AutoRest/Generators/CSharp/CSharp/Templates/MethodTemplate.cshtml index bc9c4abc47..273f1fb067 100644 --- a/AutoRest/Generators/CSharp/CSharp/Templates/MethodTemplate.cshtml +++ b/AutoRest/Generators/CSharp/CSharp/Templates/MethodTemplate.cshtml @@ -10,6 +10,10 @@ { @:/// @:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment()) + if (!string.IsNullOrEmpty(Model.ExternalDocsUrl)) + { +@:/// + } @:/// } @if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary)) diff --git a/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml b/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml index de6f680d69..20f3025f9e 100644 --- a/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml +++ b/AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml @@ -22,6 +22,10 @@ namespace @(Settings.Namespace).Models { @:/// @:@WrapComment("/// ", Model.Documentation.EscapeXmlComment()) + if (!string.IsNullOrEmpty(Model.ExternalDocsUrl)) + { + @:/// + } @:/// } From cca079f26f75c3f07a2b7b65c6af0eba8720ca89 Mon Sep 17 00:00:00 2001 From: Bruce Johnston Date: Tue, 14 Jun 2016 18:31:40 -0700 Subject: [PATCH 4/5] Adding externalDocs to some Swaggers and regenerating expected files --- .../AutoRestResourceFlatteningTestService.cs | 6 ++++ ...ResourceFlatteningTestServiceExtensions.cs | 12 +++++++ .../AzureResource/Models/Resource.cs | 4 +++ .../AutoRestResourceFlatteningTestService.cs | 9 ++++++ ...ResourceFlatteningTestServiceExtensions.cs | 18 +++++++++++ .../Models/FlattenedProduct.cs | 4 +++ .../models/FlattenedProduct.java | 2 +- .../AzureResource/models/index.d.ts | 1 + .../AzureResource/models/resource.js | 1 + .../models/flattenedProduct.js | 1 + .../ModelFlattening/models/index.d.ts | 1 + .../models/resource.py | 3 +- .../models/flattened_product.py | 3 +- .../TestServer/swagger/azure-resource.json | 22 +++++++++++++ .../TestServer/swagger/model-flattening.json | 31 +++++++++++++++++++ 15 files changed, 115 insertions(+), 3 deletions(-) diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs index 82fea546ef..8e080750d4 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs +++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestService.cs @@ -304,6 +304,7 @@ private void Initialize() } /// /// Put External Resource as an Array + /// /// /// /// External Resource as an Array to put @@ -445,6 +446,7 @@ private void Initialize() /// /// Get External Resource as an Array + /// /// /// /// Headers that will be added to request. @@ -597,6 +599,7 @@ private void Initialize() /// /// Put External Resource as a Dictionary + /// /// /// /// External Resource as a Dictionary to put @@ -738,6 +741,7 @@ private void Initialize() /// /// Get External Resource as a Dictionary + /// /// /// /// Headers that will be added to request. @@ -890,6 +894,7 @@ private void Initialize() /// /// Put External Resource as a ResourceCollection + /// /// /// /// External Resource as a ResourceCollection to put @@ -1031,6 +1036,7 @@ private void Initialize() /// /// Get External Resource as a ResourceCollection + /// /// /// /// Headers that will be added to request. diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestServiceExtensions.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestServiceExtensions.cs index 754fa41488..2bfdc94c75 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestServiceExtensions.cs +++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/AutoRestResourceFlatteningTestServiceExtensions.cs @@ -24,6 +24,7 @@ public static partial class AutoRestResourceFlatteningTestServiceExtensions { /// /// Put External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -38,6 +39,7 @@ public static partial class AutoRestResourceFlatteningTestServiceExtensions /// /// Put External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -55,6 +57,7 @@ public static partial class AutoRestResourceFlatteningTestServiceExtensions /// /// Get External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -66,6 +69,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Get External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -83,6 +87,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Put External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -97,6 +102,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Put External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -114,6 +120,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Get External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -125,6 +132,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Get External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -142,6 +150,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Put External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -156,6 +165,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Put External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -173,6 +183,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Get External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -184,6 +195,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Get External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/Models/Resource.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/Models/Resource.cs index 61d81a2722..f90ce95198 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/Models/Resource.cs +++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/Expected/AcceptanceTests/AzureResource/Models/Resource.cs @@ -16,6 +16,10 @@ namespace Fixtures.Azure.AcceptanceTestsAzureResource.Models using Microsoft.Rest.Serialization; using Microsoft.Rest.Azure; + /// + /// Some resource + /// + /// public partial class Resource : IResource { /// diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs index 4b96d5a686..308983653a 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestService.cs @@ -155,6 +155,7 @@ private void Initialize() } /// /// Put External Resource as an Array + /// /// /// /// External Resource as an Array to put @@ -269,6 +270,7 @@ private void Initialize() /// /// Get External Resource as an Array + /// /// /// /// Headers that will be added to request. @@ -394,6 +396,7 @@ private void Initialize() /// /// Put External Resource as a Dictionary + /// /// /// /// External Resource as a Dictionary to put @@ -508,6 +511,7 @@ private void Initialize() /// /// Get External Resource as a Dictionary + /// /// /// /// Headers that will be added to request. @@ -633,6 +637,7 @@ private void Initialize() /// /// Put External Resource as a ResourceCollection + /// /// /// /// External Resource as a ResourceCollection to put @@ -747,6 +752,7 @@ private void Initialize() /// /// Get External Resource as a ResourceCollection + /// /// /// /// Headers that will be added to request. @@ -872,6 +878,7 @@ private void Initialize() /// /// Put Simple Product with client flattening true on the model + /// /// /// /// Simple body product to put @@ -1011,6 +1018,7 @@ private void Initialize() /// /// Put Flattened Simple Product with client flattening true on the parameter + /// /// /// /// Unique identifier representing a specific product for a given latitude @@ -1181,6 +1189,7 @@ private void Initialize() /// /// Put Simple Product with client flattening true on the model + /// /// /// /// Additional parameters for the operation diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs index d2ab8e3efe..05b8cb27a5 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/AutoRestResourceFlatteningTestServiceExtensions.cs @@ -23,6 +23,7 @@ public static partial class AutoRestResourceFlatteningTestServiceExtensions { /// /// Put External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -37,6 +38,7 @@ public static partial class AutoRestResourceFlatteningTestServiceExtensions /// /// Put External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -54,6 +56,7 @@ public static partial class AutoRestResourceFlatteningTestServiceExtensions /// /// Get External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -65,6 +68,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Get External Resource as an Array + /// /// /// /// The operations group for this extension method. @@ -82,6 +86,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Put External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -96,6 +101,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Put External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -113,6 +119,7 @@ public static IList GetArray(this IAutoRestResourceFlatteningT /// /// Get External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -124,6 +131,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Get External Resource as a Dictionary + /// /// /// /// The operations group for this extension method. @@ -141,6 +149,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Put External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -155,6 +164,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Put External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -172,6 +182,7 @@ public static IDictionary GetDictionary(this IAutoRest /// /// Get External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -183,6 +194,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Get External Resource as a ResourceCollection + /// /// /// /// The operations group for this extension method. @@ -200,6 +212,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Put Simple Product with client flattening true on the model + /// /// /// /// The operations group for this extension method. @@ -214,6 +227,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Put Simple Product with client flattening true on the model + /// /// /// /// The operations group for this extension method. @@ -234,6 +248,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Put Flattened Simple Product with client flattening true on the parameter + /// /// /// /// The operations group for this extension method. @@ -262,6 +277,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Put Flattened Simple Product with client flattening true on the parameter + /// /// /// /// The operations group for this extension method. @@ -296,6 +312,7 @@ public static ResourceCollection GetResourceCollection(this IAutoRestResourceFla /// /// Put Simple Product with client flattening true on the model + /// /// /// /// The operations group for this extension method. @@ -310,6 +327,7 @@ public static SimpleProduct PutSimpleProductWithGrouping(this IAutoRestResourceF /// /// Put Simple Product with client flattening true on the model + /// /// /// /// The operations group for this extension method. diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenedProduct.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenedProduct.cs index fcca7e2f9f..0bd59ed909 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenedProduct.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/ModelFlattening/Models/FlattenedProduct.cs @@ -15,6 +15,10 @@ namespace Fixtures.AcceptanceTestsModelFlattening.Models using Microsoft.Rest; using Microsoft.Rest.Serialization; + /// + /// Flattened product. + /// + /// [JsonTransformation] public partial class FlattenedProduct : Resource { diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/models/FlattenedProduct.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/models/FlattenedProduct.java index 4ecc3dcda9..7203d9da4f 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/models/FlattenedProduct.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/models/FlattenedProduct.java @@ -14,7 +14,7 @@ import com.microsoft.rest.serializer.JsonFlatten; /** - * The FlattenedProduct model. + * Flattened product. */ @JsonFlatten public class FlattenedProduct extends Resource { diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/index.d.ts b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/index.d.ts index 55d50f7a17..2432157976 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/index.d.ts +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/index.d.ts @@ -28,6 +28,7 @@ export interface ErrorModel { * @class * Initializes a new instance of the Resource class. * @constructor + * Some resource * @member {string} [id] Resource Id * * @member {string} [type] Resource Type diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/resource.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/resource.js index 4e886c0664..b6ce44c8ac 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/resource.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/AzureResource/models/resource.js @@ -18,6 +18,7 @@ var util = require('util'); * @class * Initializes a new instance of the Resource class. * @constructor + * Some resource * @member {string} [id] Resource Id * * @member {string} [type] Resource Type diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/flattenedProduct.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/flattenedProduct.js index 572e314206..1a0ab18611 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/flattenedProduct.js +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/flattenedProduct.js @@ -18,6 +18,7 @@ var util = require('util'); * @class * Initializes a new instance of the FlattenedProduct class. * @constructor + * Flattened product. * @member {string} [pname] * * @member {string} [flattenedProductType] diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/index.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/index.d.ts index a105800dea..d205e9b249 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/index.d.ts +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/ModelFlattening/models/index.d.ts @@ -53,6 +53,7 @@ export interface Resource { * @class * Initializes a new instance of the FlattenedProduct class. * @constructor + * Flattened product. * @member {string} [pname] * * @member {string} [flattenedProductType] diff --git a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py index 349e6b7fbd..d9e4258973 100644 --- a/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py +++ b/AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/AzureResource/autorestresourceflatteningtestservice/models/resource.py @@ -13,7 +13,8 @@ class Resource(Model): - """Resource + """ + Some resource Variables are only populated by the server, and will be ignored when sending a request. diff --git a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py index 926f6784f8..1280506d63 100644 --- a/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py +++ b/AutoRest/Generators/Python/Python.Tests/Expected/AcceptanceTests/ModelFlattening/autorestresourceflatteningtestservice/models/flattened_product.py @@ -13,7 +13,8 @@ class FlattenedProduct(Resource): - """FlattenedProduct + """ + Flattened product. Variables are only populated by the server, and will be ignored when sending a request. diff --git a/AutoRest/TestServer/swagger/azure-resource.json b/AutoRest/TestServer/swagger/azure-resource.json index 2469627427..59d7766fb3 100644 --- a/AutoRest/TestServer/swagger/azure-resource.json +++ b/AutoRest/TestServer/swagger/azure-resource.json @@ -20,6 +20,9 @@ "put": { "operationId": "putArray", "description": "Put External Resource as an Array", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "ResourceArray", @@ -48,6 +51,9 @@ "get": { "operationId": "getArray", "description": "Get External Resource as an Array", + "externalDocs": { + "url": "http://tempuri.org" + }, "responses": { "200": { "description": "External Resource as an Array from get", @@ -71,6 +77,9 @@ "put": { "operationId": "putDictionary", "description": "Put External Resource as a Dictionary", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "ResourceDictionary", @@ -99,6 +108,9 @@ "get": { "operationId": "getDictionary", "description": "Get External Resource as a Dictionary", + "externalDocs": { + "url": "http://tempuri.org" + }, "responses": { "200": { "description": "External Resource as a Dictionary from get", @@ -122,6 +134,9 @@ "put": { "operationId": "putResourceCollection", "description": "Put External Resource as a ResourceCollection", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "ResourceComplexObject", @@ -147,6 +162,9 @@ "get": { "operationId": "getResourceCollection", "description": "Get External Resource as a ResourceCollection", + "externalDocs": { + "url": "http://tempuri.org" + }, "responses": { "200": { "description": "External Resource as a ResourceCollection from get", @@ -178,6 +196,10 @@ }, "Resource": { "x-ms-azure-resource": true, + "description": "Some resource", + "externalDocs": { + "url": "http://tempuri.org" + }, "properties": { "id": { "type": "string", diff --git a/AutoRest/TestServer/swagger/model-flattening.json b/AutoRest/TestServer/swagger/model-flattening.json index 0699f7f8e0..a86ebc9c3a 100644 --- a/AutoRest/TestServer/swagger/model-flattening.json +++ b/AutoRest/TestServer/swagger/model-flattening.json @@ -20,6 +20,9 @@ "put": { "operationId": "putArray", "description": "Put External Resource as an Array", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "ResourceArray", @@ -48,6 +51,9 @@ "get": { "operationId": "getArray", "description": "Get External Resource as an Array", + "externalDocs": { + "url": "http://tempuri.org" + }, "responses": { "200": { "description": "External Resource as an Array from get", @@ -71,6 +77,9 @@ "put": { "operationId": "putDictionary", "description": "Put External Resource as a Dictionary", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "ResourceDictionary", @@ -99,6 +108,9 @@ "get": { "operationId": "getDictionary", "description": "Get External Resource as a Dictionary", + "externalDocs": { + "url": "http://tempuri.org" + }, "responses": { "200": { "description": "External Resource as a Dictionary from get", @@ -122,6 +134,9 @@ "put": { "operationId": "putResourceCollection", "description": "Put External Resource as a ResourceCollection", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "ResourceComplexObject", @@ -147,6 +162,9 @@ "get": { "operationId": "getResourceCollection", "description": "Get External Resource as a ResourceCollection", + "externalDocs": { + "url": "http://tempuri.org" + }, "responses": { "200": { "description": "External Resource as a ResourceCollection from get", @@ -167,6 +185,9 @@ "put": { "operationId": "putSimpleProduct", "description": "Put Simple Product with client flattening true on the model", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "SimpleBodyProduct", @@ -197,6 +218,9 @@ "post": { "operationId": "postFlattenedSimpleProduct", "description": "Put Flattened Simple Product with client flattening true on the parameter", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "SimpleBodyProduct", @@ -230,6 +254,9 @@ "put": { "operationId": "putSimpleProductWithGrouping", "description": "Put Simple Product with client flattening true on the model", + "externalDocs": { + "url": "http://tempuri.org" + }, "parameters": [ { "name": "SimpleBodyProduct", @@ -324,6 +351,10 @@ "$ref": "Resource" } ], + "description": "Flattened product.", + "externalDocs": { + "url": "http://tempuri.org" + }, "properties": { "properties": { "x-ms-client-flatten": true, From 8846943557e6b012d69c39c71983b5791a4d6dca Mon Sep 17 00:00:00 2001 From: Bruce Johnston Date: Tue, 14 Jun 2016 18:49:39 -0700 Subject: [PATCH 5/5] Appeasing FxCop by suppressing a few rules and refactoring OperationBuilder --- .../ClientModel/CompositeType.cs | 3 + AutoRest/AutoRest.Core/ClientModel/Method.cs | 5 +- AutoRest/Modelers/Swagger/OperationBuilder.cs | 94 +++++++++++-------- 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs b/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs index 97b7c07109..d32ff16541 100644 --- a/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs +++ b/AutoRest/AutoRest.Core/ClientModel/CompositeType.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Microsoft.Rest.Generator.ClientModel @@ -64,6 +65,8 @@ public IEnumerable ComposedProperties /// /// Gets or sets a URL pointing to related external documentation. /// + [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", + Justification = "May not parse as a valid URI.")] public string ExternalDocsUrl { get; set; } /// diff --git a/AutoRest/AutoRest.Core/ClientModel/Method.cs b/AutoRest/AutoRest.Core/ClientModel/Method.cs index 81ab689f39..ef8c55cc17 100644 --- a/AutoRest/AutoRest.Core/ClientModel/Method.cs +++ b/AutoRest/AutoRest.Core/ClientModel/Method.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Net; @@ -46,7 +47,7 @@ public Method() /// /// Gets or sets the HTTP url. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", + [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification= "Url might be used as a template, thus making it invalid url in certain scenarios.")] public string Url { get; set; } @@ -138,6 +139,8 @@ public Parameter Body /// /// Gets or sets a URL pointing to related external documentation. /// + [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", + Justification = "May not parse as a valid URI.")] public string ExternalDocsUrl { get; set; } /// diff --git a/AutoRest/Modelers/Swagger/OperationBuilder.cs b/AutoRest/Modelers/Swagger/OperationBuilder.cs index c680c878c5..44f49c3117 100644 --- a/AutoRest/Modelers/Swagger/OperationBuilder.cs +++ b/AutoRest/Modelers/Swagger/OperationBuilder.cs @@ -70,6 +70,7 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName, // Enable UTF-8 charset method.RequestContentType += "; charset=utf-8"; } + method.Description = _operation.Description; method.Summary = _operation.Summary; method.ExternalDocsUrl = _operation.ExternalDocs?.Url; @@ -77,21 +78,7 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName, // Service parameters if (_operation.Parameters != null) { - foreach (var swaggerParameter in DeduplicateParameters(_operation.Parameters)) - { - var parameter = ((ParameterBuilder) swaggerParameter.GetBuilder(_swaggerModeler)).Build(); - method.Parameters.Add(parameter); - - StringBuilder parameterName = new StringBuilder(parameter.Name); - parameterName = CollectionFormatBuilder.OnBuildMethodParameter(method, swaggerParameter, - parameterName); - - if (swaggerParameter.In == ParameterLocation.Header) - { - method.RequestHeaders[swaggerParameter.Name] = - string.Format(CultureInfo.InvariantCulture, "{{{0}}}", parameterName); - } - } + BuildMethodParameters(method); } // Build header object @@ -100,7 +87,7 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName, { if (response.Headers != null) { - response.Headers.ForEach( h => responseHeaders[h.Key] = h.Value); + response.Headers.ForEach(h => responseHeaders[h.Key] = h.Value); } } @@ -130,30 +117,7 @@ public Method BuildMethod(HttpMethod httpMethod, string url, string methodName, } // Response format - var typesList = new List>(); - foreach (var response in _operation.Responses) - { - if (string.Equals(response.Key, "default", StringComparison.OrdinalIgnoreCase)) - { - TryBuildDefaultResponse(methodName, response.Value, method, headerType); - } - else - { - if ( - !(TryBuildResponse(methodName, response.Key.ToHttpStatusCode(), response.Value, method, - typesList, headerType) || - TryBuildStreamResponse(response.Key.ToHttpStatusCode(), response.Value, method, typesList, headerType) || - TryBuildEmptyResponse(methodName, response.Key.ToHttpStatusCode(), response.Value, method, - typesList, headerType))) - { - throw new InvalidOperationException( - string.Format(CultureInfo.InvariantCulture, - Resources.UnsupportedMimeTypeForResponseBody, - methodName, - response.Key)); - } - } - } + List> typesList = BuildResponses(method, headerType); method.ReturnType = BuildMethodReturnType(typesList, headerType); if (method.Responses.Count == 0) @@ -209,6 +173,56 @@ private static void BuildMethodReturnTypeStack(IType type, List> ty types.Add(typeStack); } + private void BuildMethodParameters(Method method) + { + foreach (var swaggerParameter in DeduplicateParameters(_operation.Parameters)) + { + var parameter = ((ParameterBuilder)swaggerParameter.GetBuilder(_swaggerModeler)).Build(); + method.Parameters.Add(parameter); + + StringBuilder parameterName = new StringBuilder(parameter.Name); + parameterName = CollectionFormatBuilder.OnBuildMethodParameter(method, swaggerParameter, + parameterName); + + if (swaggerParameter.In == ParameterLocation.Header) + { + method.RequestHeaders[swaggerParameter.Name] = + string.Format(CultureInfo.InvariantCulture, "{{{0}}}", parameterName); + } + } + } + + private List> BuildResponses(Method method, CompositeType headerType) + { + string methodName = method.Name; + var typesList = new List>(); + foreach (var response in _operation.Responses) + { + if (string.Equals(response.Key, "default", StringComparison.OrdinalIgnoreCase)) + { + TryBuildDefaultResponse(methodName, response.Value, method, headerType); + } + else + { + if ( + !(TryBuildResponse(methodName, response.Key.ToHttpStatusCode(), response.Value, method, + typesList, headerType) || + TryBuildStreamResponse(response.Key.ToHttpStatusCode(), response.Value, method, typesList, headerType) || + TryBuildEmptyResponse(methodName, response.Key.ToHttpStatusCode(), response.Value, method, + typesList, headerType))) + { + throw new InvalidOperationException( + string.Format(CultureInfo.InvariantCulture, + Resources.UnsupportedMimeTypeForResponseBody, + methodName, + response.Key)); + } + } + } + + return typesList; + } + private Response BuildMethodReturnType(List> types, IType headerType) { IType baseType = new PrimaryType(KnownPrimaryType.Object);