From 7611a283a6bdc88797318b940595c2958edc65c7 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Tue, 3 Oct 2017 18:34:34 -0700 Subject: [PATCH 1/4] initial commit for generating README --- src/azure/CodeGeneratorTSa.cs | 4 + src/azure/Model/CodeModelTSa.cs | 2 +- .../Templates/AzureReadmeTemplate.cshtml | 74 +++++++++++++++++++ .../AzureServiceClientTemplate.cshtml | 3 +- src/vanilla/CodeGeneratorTS.cs | 5 +- src/vanilla/Model/CodeModelTS.cs | 52 ++++++++++++- src/vanilla/Templates/PackageJson.cshtml | 2 +- src/vanilla/Templates/ReadmeTemplate.cshtml | 71 ++++++++++++++++++ 8 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 src/azure/Templates/AzureReadmeTemplate.cshtml create mode 100644 src/vanilla/Templates/ReadmeTemplate.cshtml diff --git a/src/azure/CodeGeneratorTSa.cs b/src/azure/CodeGeneratorTSa.cs index 1ffd933d99..3e64aefbbd 100644 --- a/src/azure/CodeGeneratorTSa.cs +++ b/src/azure/CodeGeneratorTSa.cs @@ -78,6 +78,10 @@ public override async Task Generate(CodeModel cm) // webpack.config.js var webpackConfig = new WebpackConfig { Model = codeModel }; await Write(webpackConfig, Path.Combine("../", "webpack.config.js")); + + //README.md + var readme = new AzureReadmeTemplate { Model = codeModel }; + await Write(readme, Path.Combine("../", "README.md")); } } } diff --git a/src/azure/Model/CodeModelTSa.cs b/src/azure/Model/CodeModelTSa.cs index f759a8c499..2969080ce8 100644 --- a/src/azure/Model/CodeModelTSa.cs +++ b/src/azure/Model/CodeModelTSa.cs @@ -76,7 +76,7 @@ public override string ConstructRuntimeImportForModelIndex() public override string PackageDependencies() { - return "\"ms-rest-azure-js\": \"azure/ms-rest-azure-js#master\""; + return "\"ms-rest-azure-js\": \"^0.1.0\""; } } } \ No newline at end of file diff --git a/src/azure/Templates/AzureReadmeTemplate.cshtml b/src/azure/Templates/AzureReadmeTemplate.cshtml new file mode 100644 index 0000000000..7cf01ca55c --- /dev/null +++ b/src/azure/Templates/AzureReadmeTemplate.cshtml @@ -0,0 +1,74 @@ +@using AutoRest.Core.Utilities +@using AutoRest.TypeScript.Azure.Model +@inherits AutoRest.Core.Template + +# Microsoft Azure SDK for isomorphic javascript - @(Model.Name) +This project provides an isomorphic javascript package for accessing Azure. Right now it supports: +- node.js version 6.x.x or higher +- browser javascript +@EmptyLine +## How to Install +@EmptyLine +- nodejs +``` +npm install @(Model.PackageName) +``` +- browser +```html +@{ +@: +} +``` +@EmptyLine +## How to use +@EmptyLine +### nodejs - Authentication, client creation and @(Model.GetSampleMethod().Name) @(Model.GetSampleMethodGroupName()) as an example written in TypeScript. +@EmptyLine +```javascript +import * as msRest from "ms-rest-js"; +import * as msRestAzure from "ms-rest-azure-js"; +import * as msRestNodeAuth from "ms-rest-nodeauth"; +import { @(Model.Name), @(Model.ClientPrefix)Models, @(Model.ClientPrefix)Mappers } from "@(Model.PackageName)"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; +@EmptyLine +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new @(Model.Name)(creds, undefined, subscriptionId); + @(Model.GenerateSampleMethod()) +}).catch((err) => { + console.log('An error ocurred:'); + console.dir(err, {depth: null, colors: true}); +}); +``` +@EmptyLine +### browser - Authentication, client creation and @(Model.GetSampleMethod().Name) @(Model.GetSampleMethodGroupName()) as an example written in javascript. +@EmptyLine +- index.html +```html +@{ +@: +@: +@: +@: My Todos +@: +@: +@: +@: +@: +@: +@: +@: +} +``` +@EmptyLine +# Related projects + - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) diff --git a/src/azure/Templates/AzureServiceClientTemplate.cshtml b/src/azure/Templates/AzureServiceClientTemplate.cshtml index 5ad20af35a..c7ce09deca 100644 --- a/src/azure/Templates/AzureServiceClientTemplate.cshtml +++ b/src/azure/Templates/AzureServiceClientTemplate.cshtml @@ -3,7 +3,8 @@ @using AutoRest.Core.Utilities @using AutoRest.TypeScript.vanilla.Templates @using AutoRest.TypeScript -@inherits AutoRest.Core.Template +@using AutoRest.TypeScript.Azure.Model +@inherits AutoRest.Core.Template /* @Header(" * ") */ diff --git a/src/vanilla/CodeGeneratorTS.cs b/src/vanilla/CodeGeneratorTS.cs index f5aa35768c..fcf9dd4382 100644 --- a/src/vanilla/CodeGeneratorTS.cs +++ b/src/vanilla/CodeGeneratorTS.cs @@ -3,7 +3,6 @@ // using System; -using System.Globalization; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -82,6 +81,10 @@ public override async Task Generate(CodeModel cm) // webpack.config.js var webpackConfig = new WebpackConfig { Model = codeModel }; await Write(webpackConfig, Path.Combine("../", "webpack.config.js")); + + //README.md + var readme = new ReadmeTemplate { Model = codeModel }; + await Write(readme, Path.Combine("../", "README.md")); } } } diff --git a/src/vanilla/Model/CodeModelTS.cs b/src/vanilla/Model/CodeModelTS.cs index 44be4566ef..b784ee0053 100644 --- a/src/vanilla/Model/CodeModelTS.cs +++ b/src/vanilla/Model/CodeModelTS.cs @@ -277,7 +277,57 @@ public virtual string ConstructRuntimeImportForModelIndex() public virtual string PackageDependencies() { - return "\"ms-rest-js\": \"azure/ms-rest-js#master\""; + return "\"ms-rest-js\": \"^0.1.0\""; + } + + public virtual Method GetSampleMethod() + { + return Methods.Where(m => m.HttpMethod == HttpMethod.Get).FirstOrDefault(); + } + + public virtual string GetSampleMethodGroupName() + { + return GetSampleMethod()?.MethodGroup?.Name.ToCamelCase(); + } + + public virtual string GenerateSampleMethod(bool isBrowser = false) + { + var method = GetSampleMethod(); + var methodGroup = GetSampleMethodGroupName(); + var requiredParameters = method.LogicalParameters.Where( + p => p != null && !p.IsClientProperty && !string.IsNullOrWhiteSpace(p.Name) && !p.IsConstant).OrderBy(item => !item.IsRequired).ToList(); + //TODO: Build a robust declaration for different types + var declaration = new StringBuilder(); + bool first = true; + foreach (var param in requiredParameters) + { + if (!first) + declaration.Append(","); + declaration.Append(param.Name); + first = false; + } + var clientRef = "client."; + if (methodGroup != null) + { + clientRef = $"client.{methodGroup}."; + } + var methodRef = $"{clientRef}{method.Name.ToCamelCase()}({declaration.ToString()}).then((result) => {{"; + var builder = new IndentedStringBuilder(" "); + builder.AppendLine(methodRef) + .Indent() + .AppendLine("console.log(\"The result is:\");") + .AppendLine("console.log(result);") + .Outdent(); + if (isBrowser) + { + builder.Append("})"); + } + else + { + builder.AppendLine("});"); + } + + return builder.ToString(); } } } \ No newline at end of file diff --git a/src/vanilla/Templates/PackageJson.cshtml b/src/vanilla/Templates/PackageJson.cshtml index 84e0c80a56..3f3f1e63bb 100644 --- a/src/vanilla/Templates/PackageJson.cshtml +++ b/src/vanilla/Templates/PackageJson.cshtml @@ -31,6 +31,6 @@ }, "scripts": { "tsc": "tsc -p tsconfig.node.json && tsc -p tsconfig.browser.json", - "build": "npm -s run-script tsc && webpack && node node_modules/uglify-es/bin/uglifyjs --source-map -c -m -o bundle.min.js bundle.js" + "build": "npm -s run-script tsc && webpack && node node_modules/uglify-es/bin/uglifyjs --source-map -c -m -o @(Model.Name.ToCamelCase())Bundle.min.js @(Model.Name.ToCamelCase())Bundle.js" } } \ No newline at end of file diff --git a/src/vanilla/Templates/ReadmeTemplate.cshtml b/src/vanilla/Templates/ReadmeTemplate.cshtml new file mode 100644 index 0000000000..b6b3edff97 --- /dev/null +++ b/src/vanilla/Templates/ReadmeTemplate.cshtml @@ -0,0 +1,71 @@ +@using AutoRest.Core.Utilities +@using AutoRest.TypeScript.Model +@inherits AutoRest.Core.Template + +# An isomorphic javascript sdk for - @(Model.Name) +This project provides an isomorphic javascript package. Right now it supports: +- node.js version 6.x.x or higher +- browser javascript +@EmptyLine +## How to Install +@EmptyLine +- nodejs +``` +npm install @(Model.PackageName) +``` +- browser +```html +@{ +@: +} +``` +@EmptyLine +## How to use +@EmptyLine +### nodejs - Authentication, client creation and @(Model.GetSampleMethod().Name) @(Model.GetSampleMethodGroupName()) as an example written in TypeScript. +@EmptyLine +```javascript +import * as msRest from "ms-rest-js"; +import { @(Model.Name), @(Model.ClientPrefix)Models, @(Model.ClientPrefix)Mappers } from "@(Model.PackageName)"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; +@EmptyLine +const token = ""; +const creds = new msRest.TokenCredentials(token); +const client = new @(Model.Name)(creds, subscriptionId); +@(Model.GenerateSampleMethod(true)).catch((err) => { + console.log('An error ocurred:'); + console.dir(err, {depth: null, colors: true}); +}); +``` +@EmptyLine +### browser - Authentication, client creation and @(Model.GetSampleMethod().Name) @(Model.GetSampleMethodGroupName()) as an example written in javascript. +@EmptyLine +- index.html +```html +@{ +@: +@: +@: +@: My Todos +@: +@: +@: +@: +@: +@: +@: +} +``` +@EmptyLine +# Related projects + - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) From 6e8214a5d4cf967e41983b5e08a73b64af4103b9 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Wed, 4 Oct 2017 17:09:44 -0700 Subject: [PATCH 2/4] Support complex parameter types in sample generation in README.md --- .../Templates/AzureReadmeTemplate.cshtml | 2 +- src/vanilla/ClientModelExtensions.cs | 143 ++++++++++++++++++ src/vanilla/Model/CodeModelTS.cs | 79 ++++++---- src/vanilla/Templates/ReadmeTemplate.cshtml | 2 +- 4 files changed, 196 insertions(+), 30 deletions(-) diff --git a/src/azure/Templates/AzureReadmeTemplate.cshtml b/src/azure/Templates/AzureReadmeTemplate.cshtml index 7cf01ca55c..726c425a9d 100644 --- a/src/azure/Templates/AzureReadmeTemplate.cshtml +++ b/src/azure/Templates/AzureReadmeTemplate.cshtml @@ -22,7 +22,7 @@ npm install @(Model.PackageName) @EmptyLine ## How to use @EmptyLine -### nodejs - Authentication, client creation and @(Model.GetSampleMethod().Name) @(Model.GetSampleMethodGroupName()) as an example written in TypeScript. +### nodejs - Authentication, client creation and @(Model.GetSampleMethod()?.Name) @(Model.GetSampleMethodGroupName()) as an example written in TypeScript. @EmptyLine ```javascript import * as msRest from "ms-rest-js"; diff --git a/src/vanilla/ClientModelExtensions.cs b/src/vanilla/ClientModelExtensions.cs index ac9b2d25f8..665b000468 100644 --- a/src/vanilla/ClientModelExtensions.cs +++ b/src/vanilla/ClientModelExtensions.cs @@ -939,5 +939,148 @@ public static bool SkipUrlEncoding(this Parameter parameter) return parameter.Extensions.ContainsKey(SwaggerExtensions.SkipUrlEncodingExtension) && (bool)parameter.Extensions[SwaggerExtensions.SkipUrlEncodingExtension]; } + + public static string InitializeType(this IModelType paramType, string paramName, bool isBrowser = false) + { + if (paramType is EnumType) + { + return paramType.InitializeEnumType(isBrowser); + } + else if (paramType is PrimaryType) + { + return paramType.InitializePrimaryType(paramName, isBrowser); + } + else if (paramType is SequenceType) + { + return paramType.InitializeSequenceType(paramName, isBrowser); + } + else if (paramType is DictionaryType) + { + return paramType.InitializeDictionaryType(paramName, isBrowser); + } + else if (paramType is CompositeType) + { + return paramType.InitializeCompositeType(paramName, isBrowser); + } + + return null; + } + + public static string InitializeCompositeType(this IModelType paramType, string paramName, bool isBrowser = false) + { + var builder = new IndentedStringBuilder(" "); + var composite = (CompositeType)paramType; + if (composite.ComposedProperties.Any()) + { + builder.AppendLine("{").Indent(); + var composedPropertyList = new List(composite.ComposedProperties.Where(p => /**p.IsRequired &&**/ !p.IsReadOnly)); + for (var i = 0; i < composedPropertyList.Count; i++) + { + var prop = composedPropertyList[i]; + if (i != composedPropertyList.Count - 1) + { + builder.AppendLine("{0}: {1},", prop.Name, prop.ModelType.InitializeType(prop.Name, isBrowser)); + } + else + { + builder.AppendLine("{0}: {1}", prop.Name, prop.ModelType.InitializeType(prop.Name, isBrowser)); + } + } + builder.Outdent().Append("}"); + } + else + { + builder.AppendLine("{}"); + } + return builder.ToString(); + } + + public static string InitializeDictionaryType(this IModelType paramType, string paramName, bool isBrowser = false) + { + var dictionary = (DictionaryType)paramType; + var paramValue = $"{{ \"key1\": {dictionary.ValueType.InitializeType(paramName, isBrowser)} }}"; + return paramValue; + } + + public static string InitializeSequenceType(this IModelType paramType, string paramName, bool isBrowser = false) + { + var sequence = (SequenceType)paramType; + var paramValue = $"[{sequence.ElementType.InitializeType(paramName, isBrowser)}]"; + return paramValue; + } + + public static string InitializeEnumType(this IModelType paramType, bool isBrowser = false) + { + var paramValue = "\"\""; + var enumValue = ((EnumType)paramType).Values[0].SerializedName; + paramValue = $"\"{enumValue}\""; + // TODO: Till we support setting UnderlyingType in autorest.modeler we wil default to string type as the enum value + // if ( ((EnumType)paramType).UnderlyingType.IsPrimaryType(KnownPrimaryType.String)) + // { + // paramValue = $"\"{enumValue}\""; + // } + return paramValue; + } + + public static string InitializePrimaryType(this IModelType paramType, string paramName, bool isBrowser = false) + { + var paramValue = "\"\""; + if (paramType.IsPrimaryType(KnownPrimaryType.String)) + { + if (paramName.EqualsIgnoreCase("location")) + { + paramValue = "\"westus\""; + } + else + { + paramValue = $"\"test{paramName.ToCamelCase()}\""; + } + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Date)) + { + paramValue = "new Date().toISOString().substring(0, 10)"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.DateTime)) + { + paramValue = "new Date().toISOString()"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.DateTimeRfc1123)) + { + paramValue = "new Date().toUTCString()"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.UnixTime)) + { + paramValue = "new Date()"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.TimeSpan)) + { + paramValue = "\"P1Y2M3DT4H5M6S\""; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Boolean)) + { + paramValue = "true"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Int) || paramType.IsPrimaryType(KnownPrimaryType.Long)) + { + paramValue = "1"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Decimal) || paramType.IsPrimaryType(KnownPrimaryType.Double)) + { + paramValue = "1.01"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Object)) + { + paramValue = "{}"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Uuid)) + { + paramValue = "ec7b1657-199d-4d8a-bbb2-89a11a42e02a"; + } + else if (paramType.IsPrimaryType(KnownPrimaryType.Stream)) + { + paramValue = isBrowser ? "new ReadableStream()" : "new require(\"stream\").Readable()"; + } + return paramValue; + } } } diff --git a/src/vanilla/Model/CodeModelTS.cs b/src/vanilla/Model/CodeModelTS.cs index b784ee0053..503906ccd5 100644 --- a/src/vanilla/Model/CodeModelTS.cs +++ b/src/vanilla/Model/CodeModelTS.cs @@ -13,7 +13,7 @@ namespace AutoRest.TypeScript.Model { - public class CodeModelTS : CodeModel + public class CodeModelTS : CodeModel { public CodeModelTS() { @@ -29,7 +29,7 @@ public CodeModelTS(string packageName = "test-client", string packageVersion = " public bool IsCustomBaseUri => Extensions.ContainsKey(SwaggerExtensions.ParameterizedHostExtension); [JsonIgnore] - public IEnumerable MethodTemplateModels => Methods.Cast().Where( each => each.MethodGroup.IsCodeModelMethodGroup); + public IEnumerable MethodTemplateModels => Methods.Cast().Where(each => each.MethodGroup.IsCodeModelMethodGroup); [JsonIgnore] public virtual IEnumerable ModelTemplateModels => ModelTypes.Cast(); @@ -38,7 +38,7 @@ public CodeModelTS(string packageName = "test-client", string packageVersion = " public virtual IEnumerable EnumTemplateModels => EnumTypes.Cast(); [JsonIgnore] - public virtual IEnumerable MethodGroupModels => Operations.Cast().Where( each => !each.IsCodeModelMethodGroup ); + public virtual IEnumerable MethodGroupModels => Operations.Cast().Where(each => !each.IsCodeModelMethodGroup); /// /// Provides an ordered ModelTemplateModel list such that the parent @@ -46,7 +46,7 @@ public CodeModelTS(string packageName = "test-client", string packageVersion = " /// requiring models in index.js /// [JsonIgnore] - public virtual IEnumerable OrderedModelTemplateModels + public virtual IEnumerable OrderedModelTemplateModels { get { @@ -83,10 +83,10 @@ public bool ContainsDurationProperty() public bool ContainsDurationPropertyInModels() { - return OrderedModelTemplateModels.Any(m => m.Properties.FirstOrDefault(p => - (p.ModelType is PrimaryTypeTS && (p.ModelType as PrimaryTypeTS).KnownPrimaryType == KnownPrimaryType.TimeSpan) || - (p.ModelType is SequenceType && (p.ModelType as SequenceType).ElementType.IsPrimaryType(KnownPrimaryType.TimeSpan)) || - (p.ModelType is DictionaryType && (p.ModelType as DictionaryType).ValueType.IsPrimaryType(KnownPrimaryType.TimeSpan))) != null); + return OrderedModelTemplateModels.Any(m => m.Properties.FirstOrDefault(p => + (p.ModelType is PrimaryTypeTS && (p.ModelType as PrimaryTypeTS).KnownPrimaryType == KnownPrimaryType.TimeSpan) || + (p.ModelType is SequenceType && (p.ModelType as SequenceType).ElementType.IsPrimaryType(KnownPrimaryType.TimeSpan)) || + (p.ModelType is DictionaryType && (p.ModelType as DictionaryType).ValueType.IsPrimaryType(KnownPrimaryType.TimeSpan))) != null); } private void constructOrderedList(CompositeTypeTS model, List orderedList) @@ -100,8 +100,8 @@ private void constructOrderedList(CompositeTypeTS model, List o // They are required explicitly in a different way. Hence, they // are not included in the ordered list. if (model.BaseModelType == null || - (model.BaseModelType != null && - (model.BaseModelType.Name == "BaseResource" || + (model.BaseModelType != null && + (model.BaseModelType.Name == "BaseResource" || model.BaseModelType.Name == "CloudError"))) { if (!orderedList.Contains(model)) @@ -130,7 +130,7 @@ public string PolymorphicDictionary IndentedStringBuilder builder = new IndentedStringBuilder(IndentedStringBuilder.TwoSpaces); var polymorphicTypes = ModelTemplateModels.Where(m => m.BaseIsPolymorphic); - for (int i = 0; i < polymorphicTypes.Count(); i++ ) + for (int i = 0; i < polymorphicTypes.Count(); i++) { string discriminatorField = polymorphicTypes.ElementAt(i).SerializedName; var polymorphicType = polymorphicTypes.ElementAt(i) as CompositeType; @@ -155,13 +155,13 @@ public string PolymorphicDictionary discriminatorField, polymorphicTypes.ElementAt(i).Name)); } - - if(i == polymorphicTypes.Count() -1) + + if (i == polymorphicTypes.Count() - 1) { builder.AppendLine(); } - else + else { builder.AppendLine(","); } @@ -183,7 +183,7 @@ public string RequiredConstructorParameters requireParams.Add("baseUri"); } - if(requireParams == null || requireParams.Count == 0) + if (requireParams == null || requireParams.Count == 0) { return string.Empty; } @@ -195,12 +195,15 @@ public string RequiredConstructorParameters /// /// Return the service client constructor required parameters, in TypeScript syntax. /// - public string RequiredConstructorParametersTS { - get { + public string RequiredConstructorParametersTS + { + get + { StringBuilder requiredParams = new StringBuilder(); bool first = true; - foreach (var p in this.Properties) { + foreach (var p in this.Properties) + { if (!p.IsRequired || p.IsConstant || (p.IsRequired && !string.IsNullOrEmpty(p.DefaultValue))) continue; @@ -248,21 +251,21 @@ public string ExportMethodGroupNames() var length = methodGroups.Count(); for (var i = 0; i < methodGroups.Count(); i++) { - if (i == length-1) + if (i == length - 1) { builder.Append(methodGroups[i].TypeName); } else { builder.Append(methodGroups[i].TypeName + ", "); - } + } } return builder.ToString(); } public bool IsAnyModelInheritingFromRequestOptionsBase() { - return ModelTemplateModels.Any(m => m != null && m.BaseModelType!= null && m.BaseModelType.Name.EqualsIgnoreCase("RequestOptionsBase")); + return ModelTemplateModels.Any(m => m != null && m.BaseModelType != null && m.BaseModelType.Name.EqualsIgnoreCase("RequestOptionsBase")); } public virtual string ConstructRuntimeImportForModelIndex() @@ -282,12 +285,13 @@ public virtual string PackageDependencies() public virtual Method GetSampleMethod() { - return Methods.Where(m => m.HttpMethod == HttpMethod.Get).FirstOrDefault(); + var getMethod = Methods.Where(m => m.HttpMethod == HttpMethod.Get).FirstOrDefault(); + return getMethod != null ? getMethod : Methods.FirstOrDefault(); } public virtual string GetSampleMethodGroupName() { - return GetSampleMethod()?.MethodGroup?.Name.ToCamelCase(); + return GetSampleMethod()?.MethodGroup?.Name?.ToCamelCase(); } public virtual string GenerateSampleMethod(bool isBrowser = false) @@ -296,23 +300,24 @@ public virtual string GenerateSampleMethod(bool isBrowser = false) var methodGroup = GetSampleMethodGroupName(); var requiredParameters = method.LogicalParameters.Where( p => p != null && !p.IsClientProperty && !string.IsNullOrWhiteSpace(p.Name) && !p.IsConstant).OrderBy(item => !item.IsRequired).ToList(); - //TODO: Build a robust declaration for different types + var builder = new IndentedStringBuilder(" "); + var paramInit = InitializeParametersForSampleMethod(requiredParameters, isBrowser); + builder.AppendLine(paramInit); var declaration = new StringBuilder(); bool first = true; foreach (var param in requiredParameters) { if (!first) - declaration.Append(","); + declaration.Append(", "); declaration.Append(param.Name); first = false; } var clientRef = "client."; - if (methodGroup != null) + if (!string.IsNullOrEmpty(methodGroup)) { clientRef = $"client.{methodGroup}."; } var methodRef = $"{clientRef}{method.Name.ToCamelCase()}({declaration.ToString()}).then((result) => {{"; - var builder = new IndentedStringBuilder(" "); builder.AppendLine(methodRef) .Indent() .AppendLine("console.log(\"The result is:\");") @@ -326,7 +331,25 @@ public virtual string GenerateSampleMethod(bool isBrowser = false) { builder.AppendLine("});"); } - + + return builder.ToString(); + } + + public string InitializeParametersForSampleMethod(List requiredParameters, bool isBrowser = false) + { + var builder = new IndentedStringBuilder(" "); + foreach (var param in requiredParameters) + { + var paramValue = "\"\""; + paramValue = param.ModelType.InitializeType(param.Name, isBrowser); + var paramDeclaration = $"const {param.Name}"; + if (param.ModelType is CompositeType && !isBrowser) + { + paramDeclaration += $": {ClientPrefix}Models.{param.ModelTypeName}"; + } + paramDeclaration += $" = {paramValue};"; + builder.AppendLine(paramDeclaration); + } return builder.ToString(); } } diff --git a/src/vanilla/Templates/ReadmeTemplate.cshtml b/src/vanilla/Templates/ReadmeTemplate.cshtml index b6b3edff97..bc85f4cbb6 100644 --- a/src/vanilla/Templates/ReadmeTemplate.cshtml +++ b/src/vanilla/Templates/ReadmeTemplate.cshtml @@ -22,7 +22,7 @@ npm install @(Model.PackageName) @EmptyLine ## How to use @EmptyLine -### nodejs - Authentication, client creation and @(Model.GetSampleMethod().Name) @(Model.GetSampleMethodGroupName()) as an example written in TypeScript. +### nodejs - Authentication, client creation and @(Model.GetSampleMethod()?.Name) @(Model.GetSampleMethodGroupName()) as an example written in TypeScript. @EmptyLine ```javascript import * as msRest from "ms-rest-js"; From afa397463534ab501742b88edca03e707f9e965d Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Thu, 5 Oct 2017 11:18:34 -0700 Subject: [PATCH 3/4] temp codegen changes --- .../AzureCompositeModelClient/models/index.ts | 17 + .../models/mappers.ts | 87 +++++ .../operations/polymorphism.ts | 307 ++++++++++++++++++ .../AcceptanceTests/Lro/models/index.ts | 196 +---------- .../AcceptanceTests/Paging/models/index.ts | 62 +--- .../BodyComplex/models/index.ts | 17 + .../BodyComplex/models/mappers.ts | 87 +++++ .../BodyComplex/operations/polymorphism.ts | 276 ++++++++++++++++ .../BodyString/models/index.ts | 151 +-------- .../BodyString/operations/string.ts | 124 +++---- .../AcceptanceTests/Http/models/index.ts | 255 --------------- .../ModelFlattening/models/index.ts | 67 +--- 12 files changed, 871 insertions(+), 775 deletions(-) diff --git a/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/index.ts b/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/index.ts index 58d7516cfe..854a13f3ab 100644 --- a/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/index.ts +++ b/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/index.ts @@ -224,6 +224,23 @@ export interface Salmon extends Fish { iswild?: boolean; } +/** + * @interface + * An interface representing SmartSalmon. + * @extends Salmon + */ +export interface SmartSalmon extends Salmon { + /** + * @member {{ [propertyName: string]: any }} [additionalProperties] Unmatched + * properties from the message are deserialized this collection + */ + additionalProperties?: { [propertyName: string]: any }; + /** + * @member {string} [collegeDegree] + */ + collegeDegree?: string; +} + /** * @interface * An interface representing Shark. diff --git a/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/mappers.ts b/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/mappers.ts index b32569d69d..d14a2c4fd3 100644 --- a/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/mappers.ts +++ b/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/models/mappers.ts @@ -516,6 +516,92 @@ export const Salmon = { } }; +export const SmartSalmon = { + required: false, + serializedName: 'smart_salmon', + type: { + name: 'Composite', + className: 'SmartSalmon', + modelProperties: { + species: { + required: false, + serializedName: 'species', + type: { + name: 'String' + } + }, + length: { + required: true, + serializedName: 'length', + type: { + name: 'Number' + } + }, + siblings: { + required: false, + serializedName: 'siblings', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'FishElementType', + type: { + name: 'Composite', + polymorphicDiscriminator: { + serializedName: 'fishtype', + clientName: 'fishtype' + }, + uberParent: 'Fish', + className: 'Fish' + } + } + } + }, + fishtype: { + required: true, + serializedName: 'fishtype', + type: { + name: 'String' + } + }, + location: { + required: false, + serializedName: 'location', + type: { + name: 'String' + } + }, + iswild: { + required: false, + serializedName: 'iswild', + type: { + name: 'Boolean' + } + }, + additionalProperties: { + required: false, + type: { + name: 'Dictionary', + value: { + required: false, + serializedName: 'ObjectElementType', + type: { + name: 'Object' + } + } + } + }, + collegeDegree: { + required: false, + serializedName: 'college_degree', + type: { + name: 'String' + } + } + } + } +}; + export const Shark = { required: false, serializedName: 'shark', @@ -1361,6 +1447,7 @@ export const ReadonlypropertyPutValidOptionalParams = { export const discriminators = { 'Fish' : Fish, 'Fish.salmon' : Salmon, + 'Fish.smart_salmon' : SmartSalmon, 'Fish.shark' : Shark, 'Fish.sawshark' : Sawshark, 'Fish.goblin' : Goblinshark, diff --git a/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/operations/polymorphism.ts b/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/operations/polymorphism.ts index 0555fe9a5a..fc90587dc6 100644 --- a/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/operations/polymorphism.ts +++ b/test/azure/Expected/AcceptanceTests/AzureCompositeModelClient/operations/polymorphism.ts @@ -270,6 +270,220 @@ export class Polymorphism { return Promise.resolve(operationRes); } + /** + * Get complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + async getComplicatedWithHttpOperationResponse(options?: msRest.RequestOptionsBase): Promise { + let client = this.client; + // Validate + try { + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return Promise.reject(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'complex/polymorphism/complicated'; + let queryParamsArray: Array = []; + if (queryParamsArray.length > 0) { + requestUrl += '?' + queryParamsArray.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRest.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options && options.customHeaders) { + for(let headerName in options.customHeaders) { + if (options.customHeaders.hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options.customHeaders[headerName]; + } + } + } + httpRequest.body = null; + // Send Request + let operationRes: msRest.HttpOperationResponse; + try { + operationRes = await client.pipeline(httpRequest); + let response = operationRes.response; + let statusCode = response.status; + if (statusCode !== 200) { + let error = new msRest.RestError(operationRes.bodyAsText as string); + error.statusCode = response.status; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + let parsedErrorResponse = operationRes.bodyAsJson as { [key: string]: any }; + try { + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = Mappers.ErrorModel; + error.body = client.serializer.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${operationRes.bodyAsText}" for the default response.`; + return Promise.reject(error); + } + return Promise.reject(error); + } + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = operationRes.bodyAsJson as { [key: string]: any }; + try { + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = Mappers.Salmon; + operationRes.bodyAsJson = client.serializer.deserialize(resultMapper, parsedResponse, 'operationRes.bodyAsJson'); + } + } catch (error) { + let deserializationError = new msRest.RestError(`Error ${error} occurred in deserializing the responseBody - ${operationRes.bodyAsText}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return Promise.reject(deserializationError); + } + } + + } catch(err) { + return Promise.reject(err); + } + + return Promise.resolve(operationRes); + } + + /** + * Put complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {Salmon} complexBody + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + async putComplicatedWithHttpOperationResponse(complexBody: Models.Salmon, options?: msRest.RequestOptionsBase): Promise { + let client = this.client; + // Validate + try { + if (complexBody === null || complexBody === undefined) { + throw new Error('complexBody cannot be null or undefined.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return Promise.reject(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'complex/polymorphism/complicated'; + let queryParamsArray: Array = []; + if (queryParamsArray.length > 0) { + requestUrl += '?' + queryParamsArray.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PUT'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRest.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options && options.customHeaders) { + for(let headerName in options.customHeaders) { + if (options.customHeaders.hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options.customHeaders[headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (complexBody !== null && complexBody !== undefined) { + let requestModelMapper = Mappers.Salmon; + requestModel = client.serializer.serialize(requestModelMapper, complexBody, 'complexBody'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(complexBody, null, 2)}.`); + return Promise.reject(serializationError); + } + httpRequest.body = requestContent; + // Send Request + let operationRes: msRest.HttpOperationResponse; + try { + operationRes = await client.pipeline(httpRequest); + let response = operationRes.response; + let statusCode = response.status; + if (statusCode !== 200) { + let error = new msRest.RestError(operationRes.bodyAsText as string); + error.statusCode = response.status; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + let parsedErrorResponse = operationRes.bodyAsJson as { [key: string]: any }; + try { + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = Mappers.ErrorModel; + error.body = client.serializer.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${operationRes.bodyAsText}" for the default response.`; + return Promise.reject(error); + } + return Promise.reject(error); + } + + } catch(err) { + return Promise.reject(err); + } + + return Promise.resolve(operationRes); + } + /** * Put complex types that are polymorphic, attempting to omit required * 'birthday' field - the request should not be allowed from the client @@ -528,6 +742,99 @@ export class Polymorphism { } } + /** + * Get complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @param {ServiceCallback} callback - The callback. + * + * @returns {ServiceCallback} callback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {Models.Salmon} [result] - The deserialized result object if an error did not occur. + * See {@link Models.Salmon} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {Response} [response] - The HTTP Response stream if an error did not occur. + */ + getComplicated(): Promise; + getComplicated(options: msRest.RequestOptionsBase): Promise; + getComplicated(callback: msRest.ServiceCallback): void; + getComplicated(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getComplicated(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + if (!callback && typeof options === 'function') { + callback = options; + options = undefined; + } + let cb = callback as msRest.ServiceCallback; + if (!callback) { + return this.getComplicatedWithHttpOperationResponse(options).then((operationRes: msRest.HttpOperationResponse) => { + return Promise.resolve(operationRes.bodyAsJson as Models.Salmon); + }).catch((err: Error) => { + return Promise.reject(err); + }); + } else { + msRest.promiseToCallback(this.getComplicatedWithHttpOperationResponse(options))((err: Error, data: msRest.HttpOperationResponse) => { + if (err) { + return cb(err); + } + let result = data.bodyAsJson as Models.Salmon; + return cb(err, result, data.request, data.response); + }); + } + } + + /** + * Put complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {Salmon} complexBody + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @param {ServiceCallback} callback - The callback. + * + * @returns {ServiceCallback} callback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {void} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {Response} [response] - The HTTP Response stream if an error did not occur. + */ + putComplicated(complexBody: Models.Salmon): Promise; + putComplicated(complexBody: Models.Salmon, options: msRest.RequestOptionsBase): Promise; + putComplicated(complexBody: Models.Salmon, callback: msRest.ServiceCallback): void; + putComplicated(complexBody: Models.Salmon, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + putComplicated(complexBody: Models.Salmon, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + if (!callback && typeof options === 'function') { + callback = options; + options = undefined; + } + let cb = callback as msRest.ServiceCallback; + if (!callback) { + return this.putComplicatedWithHttpOperationResponse(complexBody, options).then((operationRes: msRest.HttpOperationResponse) => { + return Promise.resolve(operationRes.bodyAsJson as void); + }).catch((err: Error) => { + return Promise.reject(err); + }); + } else { + msRest.promiseToCallback(this.putComplicatedWithHttpOperationResponse(complexBody, options))((err: Error, data: msRest.HttpOperationResponse) => { + if (err) { + return cb(err); + } + let result = data.bodyAsJson as void; + return cb(err, result, data.request, data.response); + }); + } + } + /** * Put complex types that are polymorphic, attempting to omit required * 'birthday' field - the request should not be allowed from the client diff --git a/test/azure/Expected/AcceptanceTests/Lro/models/index.ts b/test/azure/Expected/AcceptanceTests/Lro/models/index.ts index c72ed68042..5d46f64507 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/models/index.ts +++ b/test/azure/Expected/AcceptanceTests/Lro/models/index.ts @@ -68,11 +68,11 @@ export interface Product extends Resource { */ provisioningState?: string; /** - * @member {PropertiesProvisioningStateValues} [provisioningStateValues] - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' + * @member {Enum} [provisioningStateValues] Possible values include: + * 'Succeeded', 'Failed', 'canceled', 'Accepted', 'Creating', 'Created', + * 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' */ - readonly provisioningStateValues?: PropertiesProvisioningStateValues; + readonly provisioningStateValues?: Enum; } /** @@ -98,11 +98,11 @@ export interface SubProduct extends SubResource { */ provisioningState?: string; /** - * @member {PropertiesProvisioningStateValues1} [provisioningStateValues] - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' + * @member {Enum} [provisioningStateValues] Possible values include: + * 'Succeeded', 'Failed', 'canceled', 'Accepted', 'Creating', 'Created', + * 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' */ - readonly provisioningStateValues?: PropertiesProvisioningStateValues1; + readonly provisioningStateValues?: Enum; } /** @@ -126,11 +126,11 @@ export interface OperationResultError { */ export interface OperationResult { /** - * @member {Status} [status] The status of the request. Possible values + * @member {Enum} [status] The status of the request. Possible values * include: 'Succeeded', 'Failed', 'canceled', 'Accepted', 'Creating', * 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' */ - status?: Status; + status?: Enum; /** * @member {OperationResultError} [error] */ @@ -1509,179 +1509,3 @@ export interface LROsCustomHeaderBeginPostAsyncRetrySucceededOptionalParams exte product?: Product; } - -/** - * Defines values for PropertiesProvisioningStateValues. - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: PropertiesProvisioningStateValues = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum PropertiesProvisioningStateValues { - /** - * Succeeded. - */ - Succeeded = "Succeeded", - /** - * Failed. - */ - Failed = "Failed", - /** - * canceled. - */ - Canceled = "canceled", - /** - * Accepted. - */ - Accepted = "Accepted", - /** - * Creating. - */ - Creating = "Creating", - /** - * Created. - */ - Created = "Created", - /** - * Updating. - */ - Updating = "Updating", - /** - * Updated. - */ - Updated = "Updated", - /** - * Deleting. - */ - Deleting = "Deleting", - /** - * Deleted. - */ - Deleted = "Deleted", - /** - * OK. - */ - OK = "OK" -} - -/** - * Defines values for PropertiesProvisioningStateValues1. - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: PropertiesProvisioningStateValues1 = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum PropertiesProvisioningStateValues1 { - /** - * Succeeded. - */ - Succeeded = "Succeeded", - /** - * Failed. - */ - Failed = "Failed", - /** - * canceled. - */ - Canceled = "canceled", - /** - * Accepted. - */ - Accepted = "Accepted", - /** - * Creating. - */ - Creating = "Creating", - /** - * Created. - */ - Created = "Created", - /** - * Updating. - */ - Updating = "Updating", - /** - * Updated. - */ - Updated = "Updated", - /** - * Deleting. - */ - Deleting = "Deleting", - /** - * Deleted. - */ - Deleted = "Deleted", - /** - * OK. - */ - OK = "OK" -} - -/** - * Defines values for Status. - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Status = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Status { - /** - * Succeeded. - */ - Succeeded = "Succeeded", - /** - * Failed. - */ - Failed = "Failed", - /** - * canceled. - */ - Canceled = "canceled", - /** - * Accepted. - */ - Accepted = "Accepted", - /** - * Creating. - */ - Creating = "Creating", - /** - * Created. - */ - Created = "Created", - /** - * Updating. - */ - Updating = "Updating", - /** - * Updated. - */ - Updated = "Updated", - /** - * Deleting. - */ - Deleting = "Deleting", - /** - * Deleted. - */ - Deleted = "Deleted", - /** - * OK. - */ - OK = "OK" -} diff --git a/test/azure/Expected/AcceptanceTests/Paging/models/index.ts b/test/azure/Expected/AcceptanceTests/Paging/models/index.ts index 29ffaa3142..9bbbcf0b4e 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/models/index.ts +++ b/test/azure/Expected/AcceptanceTests/Paging/models/index.ts @@ -46,11 +46,11 @@ export interface Product { */ export interface OperationResult { /** - * @member {Status} [status] The status of the request. Possible values + * @member {Enum} [status] The status of the request. Possible values * include: 'Succeeded', 'Failed', 'canceled', 'Accepted', 'Creating', * 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' */ - status?: Status; + status?: Enum; } /** @@ -292,61 +292,3 @@ export interface OdataProductResult extends Array { */ odatanextLink?: string; } - -/** - * Defines values for Status. - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Status = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Status { - /** - * Succeeded. - */ - Succeeded = "Succeeded", - /** - * Failed. - */ - Failed = "Failed", - /** - * canceled. - */ - Canceled = "canceled", - /** - * Accepted. - */ - Accepted = "Accepted", - /** - * Creating. - */ - Creating = "Creating", - /** - * Created. - */ - Created = "Created", - /** - * Updating. - */ - Updating = "Updating", - /** - * Updated. - */ - Updated = "Updated", - /** - * Deleting. - */ - Deleting = "Deleting", - /** - * Deleted. - */ - Deleted = "Deleted", - /** - * OK. - */ - OK = "OK" -} diff --git a/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/index.ts b/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/index.ts index de1915f082..aaf2e52913 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/index.ts +++ b/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/index.ts @@ -142,6 +142,23 @@ export interface Salmon extends Fish { iswild?: boolean; } +/** + * @interface + * An interface representing SmartSalmon. + * @extends Salmon + */ +export interface SmartSalmon extends Salmon { + /** + * @member {{ [propertyName: string]: any }} [additionalProperties] Unmatched + * properties from the message are deserialized this collection + */ + additionalProperties?: { [propertyName: string]: any }; + /** + * @member {string} [collegeDegree] + */ + collegeDegree?: string; +} + /** * @interface * An interface representing Shark. diff --git a/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/mappers.ts b/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/mappers.ts index 15061c78a4..7d583e6bb0 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/mappers.ts +++ b/test/vanilla/Expected/AcceptanceTests/BodyComplex/models/mappers.ts @@ -347,6 +347,92 @@ export const Salmon = { } }; +export const SmartSalmon = { + required: false, + serializedName: 'smart_salmon', + type: { + name: 'Composite', + className: 'SmartSalmon', + modelProperties: { + species: { + required: false, + serializedName: 'species', + type: { + name: 'String' + } + }, + length: { + required: true, + serializedName: 'length', + type: { + name: 'Number' + } + }, + siblings: { + required: false, + serializedName: 'siblings', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'FishElementType', + type: { + name: 'Composite', + polymorphicDiscriminator: { + serializedName: 'fishtype', + clientName: 'fishtype' + }, + uberParent: 'Fish', + className: 'Fish' + } + } + } + }, + fishtype: { + required: true, + serializedName: 'fishtype', + type: { + name: 'String' + } + }, + location: { + required: false, + serializedName: 'location', + type: { + name: 'String' + } + }, + iswild: { + required: false, + serializedName: 'iswild', + type: { + name: 'Boolean' + } + }, + additionalProperties: { + required: false, + type: { + name: 'Dictionary', + value: { + required: false, + serializedName: 'ObjectElementType', + type: { + name: 'Object' + } + } + } + }, + collegeDegree: { + required: false, + serializedName: 'college_degree', + type: { + name: 'String' + } + } + } + } +}; + export const Shark = { required: false, serializedName: 'shark', @@ -1126,6 +1212,7 @@ export const ReadonlypropertyPutValidOptionalParams = { export const discriminators = { 'Fish' : Fish, 'Fish.salmon' : Salmon, + 'Fish.smart_salmon' : SmartSalmon, 'Fish.shark' : Shark, 'Fish.sawshark' : Sawshark, 'Fish.goblin' : Goblinshark, diff --git a/test/vanilla/Expected/AcceptanceTests/BodyComplex/operations/polymorphism.ts b/test/vanilla/Expected/AcceptanceTests/BodyComplex/operations/polymorphism.ts index c6dfb63ceb..97b3f5f208 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyComplex/operations/polymorphism.ts +++ b/test/vanilla/Expected/AcceptanceTests/BodyComplex/operations/polymorphism.ts @@ -239,6 +239,189 @@ export class Polymorphism { return Promise.resolve(operationRes); } + /** + * Get complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + async getComplicatedWithHttpOperationResponse(options?: msRest.RequestOptionsBase): Promise { + let client = this.client; + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'complex/polymorphism/complicated'; + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options && options.customHeaders) { + for(let headerName in options.customHeaders) { + if (options.customHeaders.hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options.customHeaders[headerName]; + } + } + } + httpRequest.body = null; + // Send Request + let operationRes: msRest.HttpOperationResponse; + try { + operationRes = await client.pipeline(httpRequest); + let response = operationRes.response; + let statusCode = response.status; + if (statusCode !== 200) { + let error = new msRest.RestError(operationRes.bodyAsText as string); + error.statusCode = response.status; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + let parsedErrorResponse = operationRes.bodyAsJson as { [key: string]: any }; + try { + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = Mappers.ErrorModel; + error.body = client.serializer.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${operationRes.bodyAsText}" for the default response.`; + return Promise.reject(error); + } + return Promise.reject(error); + } + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = operationRes.bodyAsJson as { [key: string]: any }; + try { + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = Mappers.Salmon; + operationRes.bodyAsJson = client.serializer.deserialize(resultMapper, parsedResponse, 'operationRes.bodyAsJson'); + } + } catch (error) { + let deserializationError = new msRest.RestError(`Error ${error} occurred in deserializing the responseBody - ${operationRes.bodyAsText}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return Promise.reject(deserializationError); + } + } + + } catch(err) { + return Promise.reject(err); + } + + return Promise.resolve(operationRes); + } + + /** + * Put complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {Salmon} complexBody + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + async putComplicatedWithHttpOperationResponse(complexBody: Models.Salmon, options?: msRest.RequestOptionsBase): Promise { + let client = this.client; + // Validate + try { + if (complexBody === null || complexBody === undefined) { + throw new Error('complexBody cannot be null or undefined.'); + } + } catch (error) { + return Promise.reject(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'complex/polymorphism/complicated'; + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PUT'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if(options && options.customHeaders) { + for(let headerName in options.customHeaders) { + if (options.customHeaders.hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options.customHeaders[headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (complexBody !== null && complexBody !== undefined) { + let requestModelMapper = Mappers.Salmon; + requestModel = client.serializer.serialize(requestModelMapper, complexBody, 'complexBody'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(complexBody, null, 2)}.`); + return Promise.reject(serializationError); + } + httpRequest.body = requestContent; + // Send Request + let operationRes: msRest.HttpOperationResponse; + try { + operationRes = await client.pipeline(httpRequest); + let response = operationRes.response; + let statusCode = response.status; + if (statusCode !== 200) { + let error = new msRest.RestError(operationRes.bodyAsText as string); + error.statusCode = response.status; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + let parsedErrorResponse = operationRes.bodyAsJson as { [key: string]: any }; + try { + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = Mappers.ErrorModel; + error.body = client.serializer.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${operationRes.bodyAsText}" for the default response.`; + return Promise.reject(error); + } + return Promise.reject(error); + } + + } catch(err) { + return Promise.reject(err); + } + + return Promise.resolve(operationRes); + } + /** * Put complex types that are polymorphic, attempting to omit required * 'birthday' field - the request should not be allowed from the client @@ -484,6 +667,99 @@ export class Polymorphism { } } + /** + * Get complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @param {ServiceCallback} callback - The callback. + * + * @returns {ServiceCallback} callback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {Models.Salmon} [result] - The deserialized result object if an error did not occur. + * See {@link Models.Salmon} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {Response} [response] - The HTTP Response stream if an error did not occur. + */ + getComplicated(): Promise; + getComplicated(options: msRest.RequestOptionsBase): Promise; + getComplicated(callback: msRest.ServiceCallback): void; + getComplicated(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getComplicated(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + if (!callback && typeof options === 'function') { + callback = options; + options = undefined; + } + let cb = callback as msRest.ServiceCallback; + if (!callback) { + return this.getComplicatedWithHttpOperationResponse(options).then((operationRes: msRest.HttpOperationResponse) => { + return Promise.resolve(operationRes.bodyAsJson as Models.Salmon); + }).catch((err: Error) => { + return Promise.reject(err); + }); + } else { + msRest.promiseToCallback(this.getComplicatedWithHttpOperationResponse(options))((err: Error, data: msRest.HttpOperationResponse) => { + if (err) { + return cb(err); + } + let result = data.bodyAsJson as Models.Salmon; + return cb(err, result, data.request, data.response); + }); + } + } + + /** + * Put complex types that are polymorphic, but not at the root of the + * hierarchy; also have additional properties + * + * @param {Salmon} complexBody + * + * @param {RequestOptionsBase} [options] Optional Parameters. + * + * @param {ServiceCallback} callback - The callback. + * + * @returns {ServiceCallback} callback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {void} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {Response} [response] - The HTTP Response stream if an error did not occur. + */ + putComplicated(complexBody: Models.Salmon): Promise; + putComplicated(complexBody: Models.Salmon, options: msRest.RequestOptionsBase): Promise; + putComplicated(complexBody: Models.Salmon, callback: msRest.ServiceCallback): void; + putComplicated(complexBody: Models.Salmon, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + putComplicated(complexBody: Models.Salmon, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + if (!callback && typeof options === 'function') { + callback = options; + options = undefined; + } + let cb = callback as msRest.ServiceCallback; + if (!callback) { + return this.putComplicatedWithHttpOperationResponse(complexBody, options).then((operationRes: msRest.HttpOperationResponse) => { + return Promise.resolve(operationRes.bodyAsJson as void); + }).catch((err: Error) => { + return Promise.reject(err); + }); + } else { + msRest.promiseToCallback(this.putComplicatedWithHttpOperationResponse(complexBody, options))((err: Error, data: msRest.HttpOperationResponse) => { + if (err) { + return cb(err); + } + let result = data.bodyAsJson as void; + return cb(err, result, data.request, data.response); + }); + } + } + /** * Put complex types that are polymorphic, attempting to omit required * 'birthday' field - the request should not be allowed from the client diff --git a/test/vanilla/Expected/AcceptanceTests/BodyString/models/index.ts b/test/vanilla/Expected/AcceptanceTests/BodyString/models/index.ts index 402dc3824c..7193c66189 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyString/models/index.ts +++ b/test/vanilla/Expected/AcceptanceTests/BodyString/models/index.ts @@ -46,9 +46,9 @@ export interface RefColorConstant { */ export interface StringPutNullOptionalParams extends RequestOptionsBase { /** - * @member {StringBody} [stringBody] Possible values include: '' + * @member {Enum} [stringBody] Possible values include: '' */ - stringBody?: StringBody; + stringBody?: Enum; } /** @@ -85,150 +85,3 @@ export enum Colors { */ BlueColor = "blue_color" } - -/** - * Defines values for GetNullOKResponse. - * Possible values include: '' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: GetNullOKResponse = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum GetNullOKResponse { - /** - * . - */ - EMPTY_STRING = "" -} - -/** - * Defines values for StringBody. - * Possible values include: '' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: StringBody = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum StringBody { - /** - * . - */ - EMPTY_STRING = "" -} - -/** - * Defines values for GetEmptyOKResponse. - * Possible values include: '' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: GetEmptyOKResponse = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum GetEmptyOKResponse { - /** - * . - */ - EMPTY_STRING = "" -} - -/** - * Defines values for StringBody1. - * Possible values include: '' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: StringBody1 = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum StringBody1 { - /** - * . - */ - EMPTY_STRING = "" -} - -/** - * Defines values for GetMbcsOKResponse. - * Possible values include: - * '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: GetMbcsOKResponse = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum GetMbcsOKResponse { - /** - * 啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€. - */ - 啊齄丂狛狜隣郎隣兀﨩ˊーぁんァヶΑАЯаяāɡㄅㄩɑɡ䜣 = "啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€" -} - -/** - * Defines values for StringBody2. - * Possible values include: - * '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: StringBody2 = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum StringBody2 { - /** - * 啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€. - */ - 啊齄丂狛狜隣郎隣兀﨩ˊーぁんァヶΑАЯаяāɡㄅㄩɑɡ䜣 = "啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€" -} - -/** - * Defines values for GetWhitespaceOKResponse. - * Possible values include: ' Now is the time for all good men to come to - * the aid of their country ' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: GetWhitespaceOKResponse = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum GetWhitespaceOKResponse { - /** - * Now is the time for all good men to come to the aid of their country . - */ - Nowisthetimeforallgoodmentocometotheaidoftheircountry = " Now is the time for all good men to come to the aid of their country " -} - -/** - * Defines values for StringBody3. - * Possible values include: ' Now is the time for all good men to come to - * the aid of their country ' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: StringBody3 = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum StringBody3 { - /** - * Now is the time for all good men to come to the aid of their country . - */ - Nowisthetimeforallgoodmentocometotheaidoftheircountry = " Now is the time for all good men to come to the aid of their country " -} diff --git a/test/vanilla/Expected/AcceptanceTests/BodyString/operations/string.ts b/test/vanilla/Expected/AcceptanceTests/BodyString/operations/string.ts index 7d082c949c..939e53e5c9 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyString/operations/string.ts +++ b/test/vanilla/Expected/AcceptanceTests/BodyString/operations/string.ts @@ -313,7 +313,7 @@ export class String { /** * Set string value empty '' * - * @param {StringBody1} stringBody Possible values include: '' + * @param {Enum} stringBody Possible values include: '' * * @param {RequestOptionsBase} [options] Optional Parameters. * @@ -323,7 +323,7 @@ export class String { * * @reject {Error|ServiceError} - The error object. */ - async putEmptyWithHttpOperationResponse(stringBody: Models.StringBody1, options?: msRest.RequestOptionsBase): Promise { + async putEmptyWithHttpOperationResponse(stringBody: Models.Enum, options?: msRest.RequestOptionsBase): Promise { let client = this.client; // Validate try { @@ -508,7 +508,7 @@ export class String { * Set string value mbcs * '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' * - * @param {StringBody2} stringBody Possible values include: + * @param {Enum} stringBody Possible values include: * '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' * * @param {RequestOptionsBase} [options] Optional Parameters. @@ -519,7 +519,7 @@ export class String { * * @reject {Error|ServiceError} - The error object. */ - async putMbcsWithHttpOperationResponse(stringBody: Models.StringBody2, options?: msRest.RequestOptionsBase): Promise { + async putMbcsWithHttpOperationResponse(stringBody: Models.Enum, options?: msRest.RequestOptionsBase): Promise { let client = this.client; // Validate try { @@ -706,8 +706,8 @@ export class String { * 'Now is the time for all good men to come to the aid of * their country' * - * @param {StringBody3} stringBody Possible values include: ' Now is the - * time for all good men to come to the aid of their country ' + * @param {Enum} stringBody Possible values include: ' Now is the time for + * all good men to come to the aid of their country ' * * @param {RequestOptionsBase} [options] Optional Parameters. * @@ -717,7 +717,7 @@ export class String { * * @reject {Error|ServiceError} - The error object. */ - async putWhitespaceWithHttpOperationResponse(stringBody: Models.StringBody3, options?: msRest.RequestOptionsBase): Promise { + async putWhitespaceWithHttpOperationResponse(stringBody: Models.Enum, options?: msRest.RequestOptionsBase): Promise { let client = this.client; // Validate try { @@ -1285,25 +1285,25 @@ export class String { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {Models.GetNullOKResponse} [result] - The deserialized result object if an error did not occur. + * {Models.Enum} [result] - The deserialized result object if an error did not occur. * * {WebResource} [request] - The HTTP Request object if an error did not occur. * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - getNull(): Promise; - getNull(options: msRest.RequestOptionsBase): Promise; - getNull(callback: msRest.ServiceCallback): void; - getNull(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - getNull(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + getNull(): Promise; + getNull(options: msRest.RequestOptionsBase): Promise; + getNull(callback: msRest.ServiceCallback): void; + getNull(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getNull(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; } - let cb = callback as msRest.ServiceCallback; + let cb = callback as msRest.ServiceCallback; if (!callback) { return this.getNullWithHttpOperationResponse(options).then((operationRes: msRest.HttpOperationResponse) => { - return Promise.resolve(operationRes.bodyAsJson as Models.GetNullOKResponse); + return Promise.resolve(operationRes.bodyAsJson as Models.Enum); }).catch((err: Error) => { return Promise.reject(err); }); @@ -1312,7 +1312,7 @@ export class String { if (err) { return cb(err); } - let result = data.bodyAsJson as Models.GetNullOKResponse; + let result = data.bodyAsJson as Models.Enum; return cb(err, result, data.request, data.response); }); } @@ -1373,25 +1373,25 @@ export class String { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {Models.GetEmptyOKResponse} [result] - The deserialized result object if an error did not occur. + * {Models.Enum} [result] - The deserialized result object if an error did not occur. * * {WebResource} [request] - The HTTP Request object if an error did not occur. * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - getEmpty(): Promise; - getEmpty(options: msRest.RequestOptionsBase): Promise; - getEmpty(callback: msRest.ServiceCallback): void; - getEmpty(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - getEmpty(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + getEmpty(): Promise; + getEmpty(options: msRest.RequestOptionsBase): Promise; + getEmpty(callback: msRest.ServiceCallback): void; + getEmpty(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getEmpty(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; } - let cb = callback as msRest.ServiceCallback; + let cb = callback as msRest.ServiceCallback; if (!callback) { return this.getEmptyWithHttpOperationResponse(options).then((operationRes: msRest.HttpOperationResponse) => { - return Promise.resolve(operationRes.bodyAsJson as Models.GetEmptyOKResponse); + return Promise.resolve(operationRes.bodyAsJson as Models.Enum); }).catch((err: Error) => { return Promise.reject(err); }); @@ -1400,7 +1400,7 @@ export class String { if (err) { return cb(err); } - let result = data.bodyAsJson as Models.GetEmptyOKResponse; + let result = data.bodyAsJson as Models.Enum; return cb(err, result, data.request, data.response); }); } @@ -1409,7 +1409,7 @@ export class String { /** * Set string value empty '' * - * @param {StringBody1} stringBody Possible values include: '' + * @param {Enum} stringBody Possible values include: '' * * @param {RequestOptionsBase} [options] Optional Parameters. * @@ -1425,11 +1425,11 @@ export class String { * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - putEmpty(stringBody: Models.StringBody1): Promise; - putEmpty(stringBody: Models.StringBody1, options: msRest.RequestOptionsBase): Promise; - putEmpty(stringBody: Models.StringBody1, callback: msRest.ServiceCallback): void; - putEmpty(stringBody: Models.StringBody1, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - putEmpty(stringBody: Models.StringBody1, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + putEmpty(stringBody: Models.Enum): Promise; + putEmpty(stringBody: Models.Enum, options: msRest.RequestOptionsBase): Promise; + putEmpty(stringBody: Models.Enum, callback: msRest.ServiceCallback): void; + putEmpty(stringBody: Models.Enum, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + putEmpty(stringBody: Models.Enum, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; @@ -1464,25 +1464,25 @@ export class String { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {Models.GetMbcsOKResponse} [result] - The deserialized result object if an error did not occur. + * {Models.Enum} [result] - The deserialized result object if an error did not occur. * * {WebResource} [request] - The HTTP Request object if an error did not occur. * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - getMbcs(): Promise; - getMbcs(options: msRest.RequestOptionsBase): Promise; - getMbcs(callback: msRest.ServiceCallback): void; - getMbcs(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - getMbcs(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + getMbcs(): Promise; + getMbcs(options: msRest.RequestOptionsBase): Promise; + getMbcs(callback: msRest.ServiceCallback): void; + getMbcs(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getMbcs(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; } - let cb = callback as msRest.ServiceCallback; + let cb = callback as msRest.ServiceCallback; if (!callback) { return this.getMbcsWithHttpOperationResponse(options).then((operationRes: msRest.HttpOperationResponse) => { - return Promise.resolve(operationRes.bodyAsJson as Models.GetMbcsOKResponse); + return Promise.resolve(operationRes.bodyAsJson as Models.Enum); }).catch((err: Error) => { return Promise.reject(err); }); @@ -1491,7 +1491,7 @@ export class String { if (err) { return cb(err); } - let result = data.bodyAsJson as Models.GetMbcsOKResponse; + let result = data.bodyAsJson as Models.Enum; return cb(err, result, data.request, data.response); }); } @@ -1501,7 +1501,7 @@ export class String { * Set string value mbcs * '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' * - * @param {StringBody2} stringBody Possible values include: + * @param {Enum} stringBody Possible values include: * '啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€' * * @param {RequestOptionsBase} [options] Optional Parameters. @@ -1518,11 +1518,11 @@ export class String { * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - putMbcs(stringBody: Models.StringBody2): Promise; - putMbcs(stringBody: Models.StringBody2, options: msRest.RequestOptionsBase): Promise; - putMbcs(stringBody: Models.StringBody2, callback: msRest.ServiceCallback): void; - putMbcs(stringBody: Models.StringBody2, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - putMbcs(stringBody: Models.StringBody2, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + putMbcs(stringBody: Models.Enum): Promise; + putMbcs(stringBody: Models.Enum, options: msRest.RequestOptionsBase): Promise; + putMbcs(stringBody: Models.Enum, callback: msRest.ServiceCallback): void; + putMbcs(stringBody: Models.Enum, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + putMbcs(stringBody: Models.Enum, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; @@ -1558,25 +1558,25 @@ export class String { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {Models.GetWhitespaceOKResponse} [result] - The deserialized result object if an error did not occur. + * {Models.Enum} [result] - The deserialized result object if an error did not occur. * * {WebResource} [request] - The HTTP Request object if an error did not occur. * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - getWhitespace(): Promise; - getWhitespace(options: msRest.RequestOptionsBase): Promise; - getWhitespace(callback: msRest.ServiceCallback): void; - getWhitespace(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - getWhitespace(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + getWhitespace(): Promise; + getWhitespace(options: msRest.RequestOptionsBase): Promise; + getWhitespace(callback: msRest.ServiceCallback): void; + getWhitespace(options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getWhitespace(options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; } - let cb = callback as msRest.ServiceCallback; + let cb = callback as msRest.ServiceCallback; if (!callback) { return this.getWhitespaceWithHttpOperationResponse(options).then((operationRes: msRest.HttpOperationResponse) => { - return Promise.resolve(operationRes.bodyAsJson as Models.GetWhitespaceOKResponse); + return Promise.resolve(operationRes.bodyAsJson as Models.Enum); }).catch((err: Error) => { return Promise.reject(err); }); @@ -1585,7 +1585,7 @@ export class String { if (err) { return cb(err); } - let result = data.bodyAsJson as Models.GetWhitespaceOKResponse; + let result = data.bodyAsJson as Models.Enum; return cb(err, result, data.request, data.response); }); } @@ -1596,8 +1596,8 @@ export class String { * 'Now is the time for all good men to come to the aid of * their country' * - * @param {StringBody3} stringBody Possible values include: ' Now is the - * time for all good men to come to the aid of their country ' + * @param {Enum} stringBody Possible values include: ' Now is the time for + * all good men to come to the aid of their country ' * * @param {RequestOptionsBase} [options] Optional Parameters. * @@ -1613,11 +1613,11 @@ export class String { * * {Response} [response] - The HTTP Response stream if an error did not occur. */ - putWhitespace(stringBody: Models.StringBody3): Promise; - putWhitespace(stringBody: Models.StringBody3, options: msRest.RequestOptionsBase): Promise; - putWhitespace(stringBody: Models.StringBody3, callback: msRest.ServiceCallback): void; - putWhitespace(stringBody: Models.StringBody3, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; - putWhitespace(stringBody: Models.StringBody3, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { + putWhitespace(stringBody: Models.Enum): Promise; + putWhitespace(stringBody: Models.Enum, options: msRest.RequestOptionsBase): Promise; + putWhitespace(stringBody: Models.Enum, callback: msRest.ServiceCallback): void; + putWhitespace(stringBody: Models.Enum, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + putWhitespace(stringBody: Models.Enum, options?: msRest.RequestOptionsBase, callback?: msRest.ServiceCallback): any { if (!callback && typeof options === 'function') { callback = options; options = undefined; diff --git a/test/vanilla/Expected/AcceptanceTests/Http/models/index.ts b/test/vanilla/Expected/AcceptanceTests/Http/models/index.ts index 2be67fb674..5645da1efe 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/models/index.ts +++ b/test/vanilla/Expected/AcceptanceTests/Http/models/index.ts @@ -658,258 +658,3 @@ export interface HttpRetryPatch504OptionalParams extends RequestOptionsBase { */ booleanValue?: boolean; } - -/** - * Defines values for Location. - * Possible values include: '/http/success/head/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location { - /** - * /http/success/head/200. - */ - Httpsuccesshead200 = "/http/success/head/200" -} - -/** - * Defines values for Location1. - * Possible values include: '/http/success/get/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location1 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location1 { - /** - * /http/success/get/200. - */ - Httpsuccessget200 = "/http/success/get/200" -} - -/** - * Defines values for Location2. - * Possible values include: '/http/success/head/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location2 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location2 { - /** - * /http/success/head/200. - */ - Httpsuccesshead200 = "/http/success/head/200" -} - -/** - * Defines values for Location3. - * Possible values include: '/http/success/get/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location3 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location3 { - /** - * /http/success/get/200. - */ - Httpsuccessget200 = "/http/success/get/200" -} - -/** - * Defines values for Location4. - * Possible values include: '/http/failure/500' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location4 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location4 { - /** - * /http/failure/500. - */ - Httpfailure500 = "/http/failure/500" -} - -/** - * Defines values for Location5. - * Possible values include: '/http/success/head/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location5 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location5 { - /** - * /http/success/head/200. - */ - Httpsuccesshead200 = "/http/success/head/200" -} - -/** - * Defines values for Location6. - * Possible values include: '/http/success/get/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location6 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location6 { - /** - * /http/success/get/200. - */ - Httpsuccessget200 = "/http/success/get/200" -} - -/** - * Defines values for Location7. - * Possible values include: '/http/failure/500' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location7 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location7 { - /** - * /http/failure/500. - */ - Httpfailure500 = "/http/failure/500" -} - -/** - * Defines values for Location8. - * Possible values include: '/http/success/get/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location8 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location8 { - /** - * /http/success/get/200. - */ - Httpsuccessget200 = "/http/success/get/200" -} - -/** - * Defines values for Location9. - * Possible values include: '/http/success/head/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location9 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location9 { - /** - * /http/success/head/200. - */ - Httpsuccesshead200 = "/http/success/head/200" -} - -/** - * Defines values for Location10. - * Possible values include: '/http/success/get/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location10 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location10 { - /** - * /http/success/get/200. - */ - Httpsuccessget200 = "/http/success/get/200" -} - -/** - * Defines values for Location11. - * Possible values include: '/http/success/put/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location11 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location11 { - /** - * /http/success/put/200. - */ - Httpsuccessput200 = "/http/success/put/200" -} - -/** - * Defines values for Location12. - * Possible values include: '/http/success/patch/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location12 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location12 { - /** - * /http/success/patch/200. - */ - Httpsuccesspatch200 = "/http/success/patch/200" -} - -/** - * Defines values for Location13. - * Possible values include: '/http/success/post/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location13 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location13 { - /** - * /http/success/post/200. - */ - Httpsuccesspost200 = "/http/success/post/200" -} - -/** - * Defines values for Location14. - * Possible values include: '/http/success/delete/200' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: Location14 = "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum Location14 { - /** - * /http/success/delete/200. - */ - Httpsuccessdelete200 = "/http/success/delete/200" -} diff --git a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/models/index.ts b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/models/index.ts index 0026a4bc0f..8b3c6f07e6 100644 --- a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/models/index.ts +++ b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/models/index.ts @@ -74,11 +74,11 @@ export interface FlattenedProduct extends Resource { */ flattenedProductType?: string; /** - * @member {PropertiesProvisioningStateValues} [provisioningStateValues] - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' + * @member {Enum} [provisioningStateValues] Possible values include: + * 'Succeeded', 'Failed', 'canceled', 'Accepted', 'Creating', 'Created', + * 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' */ - readonly provisioningStateValues?: PropertiesProvisioningStateValues; + readonly provisioningStateValues?: Enum; /** * @member {string} [provisioningState] */ @@ -314,62 +314,3 @@ export interface AutoRestResourceFlatteningTestServicePostFlattenedSimpleProduct */ odatavalue?: string; } - -/** - * Defines values for PropertiesProvisioningStateValues. - * Possible values include: 'Succeeded', 'Failed', 'canceled', 'Accepted', - * 'Creating', 'Created', 'Updating', 'Updated', 'Deleting', 'Deleted', 'OK' - * There could be more values for this enum apart from the ones defined here.If - * you want to set a value that is not from the known values then you can do - * the following: - * let param: PropertiesProvisioningStateValues = - * "someUnknownValueThatWillStillBeValid"; - * @readonly - * @enum {string} - */ -export enum PropertiesProvisioningStateValues { - /** - * Succeeded. - */ - Succeeded = "Succeeded", - /** - * Failed. - */ - Failed = "Failed", - /** - * canceled. - */ - Canceled = "canceled", - /** - * Accepted. - */ - Accepted = "Accepted", - /** - * Creating. - */ - Creating = "Creating", - /** - * Created. - */ - Created = "Created", - /** - * Updating. - */ - Updating = "Updating", - /** - * Updated. - */ - Updated = "Updated", - /** - * Deleting. - */ - Deleting = "Deleting", - /** - * Deleted. - */ - Deleted = "Deleted", - /** - * OK. - */ - OK = "OK" -} From 8c3b2fcaf6b5e899346be34eb59f67a93e9bae2a Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Fri, 20 Oct 2017 19:24:37 -0700 Subject: [PATCH 4/4] update README --- README.md | 4 ++-- src/azure/Templates/AzureReadmeTemplate.cshtml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 95b62dc023..594a1ef5e0 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ autorest --typescript --output-folder= --license-header=MICROSOFT_MIT_NO_VERSION -package-name= --package-version ``` -- If you want to generate metadata files (package.json, .npmignore, webpack.config.js, tsconfig.json), then provide `--generate-metadata=true`: +- If you want to generate metadata files **__(package.json, .npmignore, webpack.config.js, tsconfig.json, README.md(with a sample))__**, then provide `--generate-metadata=true`: -**NOTE: This will generate all the _metadata_ files one level above the output-folder.** +**NOTE: This will generate all the __metadata__ files one level above the output-folder.** ``` autorest --typescript --output-folder= --license-header=MICROSOFT_MIT_NO_VERSION --input-file= --package-name= --package-version --generate-metadata=true ``` diff --git a/src/azure/Templates/AzureReadmeTemplate.cshtml b/src/azure/Templates/AzureReadmeTemplate.cshtml index 726c425a9d..0b4e90693e 100644 --- a/src/azure/Templates/AzureReadmeTemplate.cshtml +++ b/src/azure/Templates/AzureReadmeTemplate.cshtml @@ -32,7 +32,7 @@ import { @(Model.Name), @(Model.ClientPrefix)Models, @(Model.ClientPrefix)Mapper const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; @EmptyLine msRestNodeAuth.interactiveLogin().then((creds) => { - const client = new @(Model.Name)(creds, undefined, subscriptionId); + const client = new @(Model.Name)(creds, subscriptionId); @(Model.GenerateSampleMethod()) }).catch((err) => { console.log('An error ocurred:');