From 609e9ed5fe876fffc63de43287510035c9974993 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Wed, 10 Aug 2016 21:58:33 +0200 Subject: [PATCH 01/11] Added support for ITemplateFactory --- .../NSwag.AspNet.Owin.csproj | 8 +- .../NSwag.AssemblyLoader.csproj | 8 +- .../NSwag.CodeGeneration.Tests.csproj | 16 +- .../CSharp/SwaggerToCSharpClientGenerator.cs | 8 +- .../CSharp/SwaggerToCSharpGeneratorBase.cs | 7 +- ...waggerToCSharpWebApiControllerGenerator.cs | 7 +- .../Templates/ClientTemplate.Extensions.cs | 12 +- .../ControllerTemplate.Extensions.cs | 19 + ...ollerTemplate.cs => ControllerTemplate.cs} | 1378 +++---- ...ollerTemplate.tt => ControllerTemplate.tt} | 78 +- .../Templates/FileTemplate.Extensions.cs | 10 +- .../WebApiControllerTemplate.Extensions.cs | 23 - .../ClientGeneratorBaseSettings.cs | 4 +- .../TypeScript/RequestBodyGenerator.cs | 3 +- .../SwaggerToTypeScriptClientGenerator.cs | 12 +- ...ggerToTypeScriptClientGeneratorSettings.cs | 18 +- .../Angular2ClientTemplate.Extensions.cs | 20 + ...Template1.cs => Angular2ClientTemplate.cs} | 2884 +++++++------- ...2Template.tt => Angular2ClientTemplate.tt} | 334 +- .../Templates/Angular2Template.Extensions.cs | 24 - .../AngularJSClientTemplate.Extensions.cs | 20 + ...emplate1.cs => AngularJSClientTemplate.cs} | 2884 +++++++------- ...Template.tt => AngularJSClientTemplate.tt} | 340 +- .../Templates/AngularJSTemplate.Extensions.cs | 24 - .../Templates/FileTemplate.Extensions.cs | 10 +- ...QueryCallbacksClientTemplate.Extensions.cs | 20 + ...e1.cs => JQueryCallbacksClientTemplate.cs} | 3176 ++++++++-------- ...te.tt => JQueryCallbacksClientTemplate.tt} | 402 +- .../JQueryCallbacksTemplate.Extensions.cs | 24 - ...JQueryPromisesClientTemplate.Extensions.cs | 20 + ...ate.cs => JQueryPromisesClientTemplate.cs} | 3352 ++++++++--------- ...ate.tt => JQueryPromisesClientTemplate.tt} | 414 +- .../JQueryPromisesTemplate.Extensions.cs | 24 - .../RequestBodyTemplate.Extensions.cs | 12 +- .../NSwag.CodeGeneration.csproj | 66 +- src/NSwag.Core/NSwag.Core.csproj | 10 +- .../NSwag.Demo.OwinWeb.csproj | 8 +- src/NSwag.Demo.Web/NSwag.Demo.Web.csproj | 8 +- src/NSwag.Tests/NSwag.Tests.csproj | 16 +- src/NSwag.sln | 38 +- src/NSwag/NSwag.csproj | 16 +- src/NSwagStudio/NSwagStudio.csproj | 16 +- 42 files changed, 7879 insertions(+), 7894 deletions(-) create mode 100644 src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.Extensions.cs rename src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/{WebApiControllerTemplate.cs => ControllerTemplate.cs} (97%) rename src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/{WebApiControllerTemplate.tt => ControllerTemplate.tt} (98%) delete mode 100644 src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.Extensions.cs create mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.Extensions.cs rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{Angular2Template1.cs => Angular2ClientTemplate.cs} (80%) rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{Angular2Template.tt => Angular2ClientTemplate.tt} (97%) delete mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.Extensions.cs create mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.Extensions.cs rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{AngularJSTemplate1.cs => AngularJSClientTemplate.cs} (80%) rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{AngularJSTemplate.tt => AngularJSClientTemplate.tt} (97%) delete mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.Extensions.cs create mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.Extensions.cs rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{JQueryCallbacksTemplate1.cs => JQueryCallbacksClientTemplate.cs} (79%) rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{JQueryCallbacksTemplate.tt => JQueryCallbacksClientTemplate.tt} (97%) delete mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.Extensions.cs create mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.Extensions.cs rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{JQueryPromisesTemplate.cs => JQueryPromisesClientTemplate.cs} (79%) rename src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/{JQueryPromisesTemplate.tt => JQueryPromisesClientTemplate.tt} (97%) delete mode 100644 src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.Extensions.cs diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index 26e9b78544..a89bef94e5 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -51,10 +51,6 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.3.3.6061.16591\lib\net45\NJsonSchema.dll - True - ..\packages\Owin.1.0\lib\net40\Owin.dll True @@ -92,6 +88,10 @@ + + {7B7A2E32-E808-4A19-98B1-37E766580F8C} + NJsonSchema + {75b3f91d-687e-4fb3-ad45-ccfa3c406db4} NSwag.CodeGeneration diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index c67d09a2ca..f479253f25 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -39,10 +39,6 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.3.3.6061.16591\lib\net45\NJsonSchema.dll - True - @@ -63,6 +59,10 @@ + + {7B7A2E32-E808-4A19-98B1-37E766580F8C} + NJsonSchema + {75B3F91D-687E-4FB3-AD45-CCFA3C406DB4} NSwag.CodeGeneration diff --git a/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj b/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj index ec16448536..f492135dc0 100644 --- a/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj +++ b/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj @@ -39,14 +39,6 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.3.3.6061.16591\lib\net45\NJsonSchema.dll - True - - - ..\packages\NJsonSchema.CodeGeneration.3.3.6061.16591\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll - True - @@ -91,6 +83,14 @@ + + {8A463FA0-DAAF-483C-813E-AE9C6153CBF7} + NJsonSchema.CodeGeneration + + + {7B7A2E32-E808-4A19-98B1-37E766580F8C} + NJsonSchema + {CA084154-E758-4A44-938D-7806AF2DD886} NSwag.Annotations diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpClientGenerator.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpClientGenerator.cs index dd0c02a087..80e020a613 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpClientGenerator.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpClientGenerator.cs @@ -12,7 +12,6 @@ using NJsonSchema; using NJsonSchema.CodeGeneration; using NSwag.CodeGeneration.CodeGenerators.CSharp.Models; -using NSwag.CodeGeneration.CodeGenerators.CSharp.Templates; using NSwag.CodeGeneration.CodeGenerators.Models; namespace NSwag.CodeGeneration.CodeGenerators.CSharp @@ -83,12 +82,13 @@ protected override string ResolveParameterType(SwaggerParameter parameter, IType internal override string GenerateClientClass(string controllerName, IList operations, ClientGeneratorOutputType outputType) { - var template = new ClientTemplate(); - template.Initialize(new ClientTemplateModel(controllerName, operations, _service, Settings) + var model = new ClientTemplateModel(controllerName, operations, _service, Settings) { GenerateContracts = outputType == ClientGeneratorOutputType.Full || outputType == ClientGeneratorOutputType.Contracts, GenerateImplementation = outputType == ClientGeneratorOutputType.Full || outputType == ClientGeneratorOutputType.Implementation, - }); + }; + + var template = Settings.CSharpGeneratorSettings.TemplateFactory.CreateTemplate("CSharp", "Client", model); return template.Render(); } } diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpGeneratorBase.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpGeneratorBase.cs index e62aab9267..286230817e 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpGeneratorBase.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpGeneratorBase.cs @@ -9,7 +9,6 @@ using System.Collections.Generic; using System.Linq; using NJsonSchema; -using NSwag.CodeGeneration.CodeGenerators.CSharp.Templates; namespace NSwag.CodeGeneration.CodeGenerators.CSharp { @@ -34,8 +33,7 @@ internal override string GenerateFile(string clientCode, IEnumerable cli var generateOnlyContracts = outputType == ClientGeneratorOutputType.Contracts; var generateImplementation = outputType == ClientGeneratorOutputType.Full || outputType == ClientGeneratorOutputType.Implementation; - var template = new FileTemplate(); - template.Initialize(new // TODO: Add typed class + var model = new // TODO: Add typed class { Namespace = _settings.CSharpGeneratorSettings.Namespace ?? string.Empty, NamespaceUsages = generateOnlyContracts || _settings.AdditionalNamespaceUsages == null ? new string[] { } : _settings.AdditionalNamespaceUsages, @@ -51,8 +49,9 @@ internal override string GenerateFile(string clientCode, IEnumerable cli o.Method == SwaggerOperationMethod.Options || o.Method == SwaggerOperationMethod.Head || o.Method == SwaggerOperationMethod.Patch) - }); + }; + var template = _settings.CodeGeneratorSettings.TemplateFactory.CreateTemplate("CSharp", "File", model); return template.Render(); } diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpWebApiControllerGenerator.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpWebApiControllerGenerator.cs index 02ee184408..5d5512d392 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpWebApiControllerGenerator.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/SwaggerToCSharpWebApiControllerGenerator.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Generic; using System.Linq; -using NSwag.CodeGeneration.CodeGenerators.CSharp.Templates; using NSwag.CodeGeneration.CodeGenerators.Models; namespace NSwag.CodeGeneration.CodeGenerators.CSharp @@ -56,8 +55,7 @@ internal override string GenerateClientClass(string controllerName, IListInitializes the template with a model. - /// The model. - public void Initialize(object model) + public ClientTemplate(ClientTemplateModel model) { - Model = (ClientTemplateModel)model; + Model = model; } - /// Renders the template. - /// The output. + public ClientTemplateModel Model { get; } + public string Render() { return ConversionUtilities.TrimWhiteSpaces(TransformText()); diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.Extensions.cs new file mode 100644 index 0000000000..cbf314270a --- /dev/null +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.Extensions.cs @@ -0,0 +1,19 @@ +using NJsonSchema.CodeGeneration; + +namespace NSwag.CodeGeneration.CodeGenerators.CSharp.Templates +{ + internal partial class ControllerTemplate : ITemplate + { + public ControllerTemplate(object model) + { + Model = model; + } + + public dynamic Model { get; } + + public string Render() + { + return ConversionUtilities.TrimWhiteSpaces(TransformText()); + } + } +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.cs similarity index 97% rename from src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.cs rename to src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.cs index 2d6da70cdd..6d9e64df93 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.cs @@ -1,689 +1,689 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 14.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace NSwag.CodeGeneration.CodeGenerators.CSharp.Templates -{ - using NJsonSchema.CodeGeneration; - using System; - - /// - /// Class to produce the template output - /// - - #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal partial class WebApiControllerTemplate : WebApiControllerTemplateBase - { -#line hidden - /// - /// Create the template output - /// - public virtual string TransformText() - { - this.Write("[GeneratedCode(\"NSwag\", \""); - - #line 4 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion)); - - #line default - #line hidden - this.Write("\")]\r\npublic interface I"); - - #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write("Controller\r\n{\r\n"); - - #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - - #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" /// "); - - #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - }foreach (var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - if(parameter.HasDescription){ - - #line default - #line hidden - this.Write(" /// "); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - }}if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" /// "); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - }if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" [Obsolete]\r\n"); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - } - - #line default - #line hidden - this.Write(" "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(" "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("Async("); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - this.Write(" "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -}} - - #line default - #line hidden - this.Write(");\r\n\r\n"); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n\r\n[GeneratedCode(\"NSwag\", \""); - - #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion)); - - #line default - #line hidden - this.Write("\")]\r\npublic class "); - - #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write("Controller : "); - - #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -if(Model.HasBaseClass){ - - #line default - #line hidden - - #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseClass)); - - #line default - #line hidden - - #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -}else{ - - #line default - #line hidden - this.Write("ApiController"); - - #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -} - - #line default - #line hidden - this.Write(" \r\n{\r\n private I"); - - #line 21 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write("Controller _implementation; \r\n\r\n public "); - - #line 23 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write("Controller(I"); - - #line 23 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write("Controller implementation)\r\n {\r\n _implementation = implementation; \r\n " + - " }\r\n"); - - #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - - #line 28 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" /// "); - - #line 28 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 29 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - }foreach (var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - if(parameter.HasDescription){ - - #line default - #line hidden - this.Write(" /// "); - - #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 31 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - }}if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" /// "); - - #line 31 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 32 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - }if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" [Obsolete]\r\n"); - - #line 33 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - } - - #line default - #line hidden - this.Write(" [Http"); - - #line 33 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodUpper)); - - #line default - #line hidden - this.Write(", Route(\""); - - #line 33 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); - - #line default - #line hidden - this.Write("\")]\r\n public "); - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(" "); - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("("); - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - this.Write(" "); - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -}} - - #line default - #line hidden - this.Write(")\r\n {\r\n return _implementation."); - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("Async("); - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -}} - - #line default - #line hidden - this.Write(");\r\n }\r\n\r\n"); - - #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" -} - - #line default - #line hidden - this.Write("}"); - return this.GenerationEnvironment.ToString(); - } - } - - #line default - #line hidden - #region Base class - /// - /// Base class for this transformation - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal class WebApiControllerTemplateBase - { - #region Fields - private global::System.Text.StringBuilder generationEnvironmentField; - private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; - private global::System.Collections.Generic.List indentLengthsField; - private string currentIndentField = ""; - private bool endsWithNewline; - private global::System.Collections.Generic.IDictionary sessionField; - #endregion - #region Properties - /// - /// The string builder that generation-time code is using to assemble generated output - /// - protected System.Text.StringBuilder GenerationEnvironment - { - get - { - if ((this.generationEnvironmentField == null)) - { - this.generationEnvironmentField = new global::System.Text.StringBuilder(); - } - return this.generationEnvironmentField; - } - set - { - this.generationEnvironmentField = value; - } - } - /// - /// The error collection for the generation process - /// - public System.CodeDom.Compiler.CompilerErrorCollection Errors - { - get - { - if ((this.errorsField == null)) - { - this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); - } - return this.errorsField; - } - } - /// - /// A list of the lengths of each indent that was added with PushIndent - /// - private System.Collections.Generic.List indentLengths - { - get - { - if ((this.indentLengthsField == null)) - { - this.indentLengthsField = new global::System.Collections.Generic.List(); - } - return this.indentLengthsField; - } - } - /// - /// Gets the current indent we use when adding lines to the output - /// - public string CurrentIndent - { - get - { - return this.currentIndentField; - } - } - /// - /// Current transformation session - /// - public virtual global::System.Collections.Generic.IDictionary Session - { - get - { - return this.sessionField; - } - set - { - this.sessionField = value; - } - } - #endregion - #region Transform-time helpers - /// - /// Write text directly into the generated output - /// - public void Write(string textToAppend) - { - if (string.IsNullOrEmpty(textToAppend)) - { - return; - } - // If we're starting off, or if the previous text ended with a newline, - // we have to append the current indent first. - if (((this.GenerationEnvironment.Length == 0) - || this.endsWithNewline)) - { - this.GenerationEnvironment.Append(this.currentIndentField); - this.endsWithNewline = false; - } - // Check if the current text ends with a newline - if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) - { - this.endsWithNewline = true; - } - // This is an optimization. If the current indent is "", then we don't have to do any - // of the more complex stuff further down. - if ((this.currentIndentField.Length == 0)) - { - this.GenerationEnvironment.Append(textToAppend); - return; - } - // Everywhere there is a newline in the text, add an indent after it - textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); - // If the text ends with a newline, then we should strip off the indent added at the very end - // because the appropriate indent will be added when the next time Write() is called - if (this.endsWithNewline) - { - this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); - } - else - { - this.GenerationEnvironment.Append(textToAppend); - } - } - /// - /// Write text directly into the generated output - /// - public void WriteLine(string textToAppend) - { - this.Write(textToAppend); - this.GenerationEnvironment.AppendLine(); - this.endsWithNewline = true; - } - /// - /// Write formatted text directly into the generated output - /// - public void Write(string format, params object[] args) - { - this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Write formatted text directly into the generated output - /// - public void WriteLine(string format, params object[] args) - { - this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Raise an error - /// - public void Error(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - this.Errors.Add(error); - } - /// - /// Raise a warning - /// - public void Warning(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - error.IsWarning = true; - this.Errors.Add(error); - } - /// - /// Increase the indent - /// - public void PushIndent(string indent) - { - if ((indent == null)) - { - throw new global::System.ArgumentNullException("indent"); - } - this.currentIndentField = (this.currentIndentField + indent); - this.indentLengths.Add(indent.Length); - } - /// - /// Remove the last indent that was added with PushIndent - /// - public string PopIndent() - { - string returnValue = ""; - if ((this.indentLengths.Count > 0)) - { - int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; - this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); - if ((indentLength > 0)) - { - returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); - this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); - } - } - return returnValue; - } - /// - /// Remove any indentation - /// - public void ClearIndent() - { - this.indentLengths.Clear(); - this.currentIndentField = ""; - } - #endregion - #region ToString Helpers - /// - /// Utility class to produce culture-oriented representation of an object as a string. - /// - public class ToStringInstanceHelper - { - private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; - /// - /// Gets or sets format provider to be used by ToStringWithCulture method. - /// - public System.IFormatProvider FormatProvider - { - get - { - return this.formatProviderField ; - } - set - { - if ((value != null)) - { - this.formatProviderField = value; - } - } - } - /// - /// This is called from the compile/run appdomain to convert objects within an expression block to a string - /// - public string ToStringWithCulture(object objectToConvert) - { - if ((objectToConvert == null)) - { - throw new global::System.ArgumentNullException("objectToConvert"); - } - System.Type t = objectToConvert.GetType(); - System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { - typeof(System.IFormatProvider)}); - if ((method == null)) - { - return objectToConvert.ToString(); - } - else - { - return ((string)(method.Invoke(objectToConvert, new object[] { - this.formatProviderField }))); - } - } - } - private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); - /// - /// Helper to produce culture-oriented representation of an object as a string - /// - public ToStringInstanceHelper ToStringHelper - { - get - { - return this.toStringHelperField; - } - } - #endregion - } - #endregion -} +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 14.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace NSwag.CodeGeneration.CodeGenerators.CSharp.Templates +{ + using NJsonSchema.CodeGeneration; + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal partial class ControllerTemplate : WebApiControllerTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + this.Write("[GeneratedCode(\"NSwag\", \""); + + #line 4 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion)); + + #line default + #line hidden + this.Write("\")]\r\npublic interface I"); + + #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write("Controller\r\n{\r\n"); + + #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + + #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" /// "); + + #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + }foreach (var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + if(parameter.HasDescription){ + + #line default + #line hidden + this.Write(" /// "); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + }}if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" /// "); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + }if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" [Obsolete]\r\n"); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + } + + #line default + #line hidden + this.Write(" "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(" "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("Async("); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + this.Write(" "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +}} + + #line default + #line hidden + this.Write(");\r\n\r\n"); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n\r\n[GeneratedCode(\"NSwag\", \""); + + #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion)); + + #line default + #line hidden + this.Write("\")]\r\npublic class "); + + #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write("Controller : "); + + #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +if(Model.HasBaseClass){ + + #line default + #line hidden + + #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseClass)); + + #line default + #line hidden + + #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +}else{ + + #line default + #line hidden + this.Write("ApiController"); + + #line 19 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +} + + #line default + #line hidden + this.Write(" \r\n{\r\n private I"); + + #line 21 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write("Controller _implementation; \r\n\r\n public "); + + #line 23 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write("Controller(I"); + + #line 23 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write("Controller implementation)\r\n {\r\n _implementation = implementation; \r\n " + + " }\r\n"); + + #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + + #line 28 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" /// "); + + #line 28 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 29 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + }foreach (var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + if(parameter.HasDescription){ + + #line default + #line hidden + this.Write(" /// "); + + #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 31 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + }}if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" /// "); + + #line 31 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 32 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + }if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" [Obsolete]\r\n"); + + #line 33 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + } + + #line default + #line hidden + this.Write(" [Http"); + + #line 33 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodUpper)); + + #line default + #line hidden + this.Write(", Route(\""); + + #line 33 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); + + #line default + #line hidden + this.Write("\")]\r\n public "); + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(" "); + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("("); + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + this.Write(" "); + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 34 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +}} + + #line default + #line hidden + this.Write(")\r\n {\r\n return _implementation."); + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("Async("); + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +}} + + #line default + #line hidden + this.Write(");\r\n }\r\n\r\n"); + + #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\WebApiControllerTemplate.tt" +} + + #line default + #line hidden + this.Write("}"); + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal class WebApiControllerTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + protected System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.tt b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.tt similarity index 98% rename from src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.tt rename to src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.tt index 830b3ce804..ac1b51b6d3 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.tt +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/ControllerTemplate.tt @@ -1,40 +1,40 @@ -<#@ template visibility="internal" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="NJsonSchema.CodeGeneration" #> -[GeneratedCode("NSwag", "<#=SwaggerService.ToolchainVersion#>")] -public interface I<#=Model.Class#>Controller -{ -<#foreach(var operation in Model.Operations){#> -<# if(operation.HasSummary){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1)#> -<# }foreach (var parameter in operation.Parameters){#> -<# if(parameter.HasDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1)#> -<# }}if(operation.HasResultDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1)#> -<# }if(operation.IsDeprecated){#> [Obsolete] -<# }#> <#=operation.ResultType#> <#=operation.OperationNameUpper#>Async(<#foreach(var parameter in operation.Parameters){#><#=parameter.Type#> <#=parameter.VariableNameLower#><#if(!parameter.IsLast){#>, <#}}#>); - -<#}#> -} - -[GeneratedCode("NSwag", "<#=SwaggerService.ToolchainVersion#>")] -public class <#=Model.Class#>Controller : <#if(Model.HasBaseClass){#><#=Model.BaseClass#><#}else{#>ApiController<#}#> -{ - private I<#=Model.Class#>Controller _implementation; - - public <#=Model.Class#>Controller(I<#=Model.Class#>Controller implementation) - { - _implementation = implementation; - } -<#foreach(var operation in Model.Operations){#> -<# if(operation.HasSummary){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1)#> -<# }foreach (var parameter in operation.Parameters){#> -<# if(parameter.HasDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1)#> -<# }}if(operation.HasResultDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1)#> -<# }if(operation.IsDeprecated){#> [Obsolete] -<# }#> [Http<#=operation.HttpMethodUpper#>, Route("<#=operation.Path#>")] - public <#=operation.ResultType#> <#=operation.OperationNameUpper#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.Type#> <#=parameter.VariableNameLower#><#if(!parameter.IsLast){#>, <#}}#>) - { - return _implementation.<#=operation.OperationNameUpper#>Async(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#><#if(!parameter.IsLast){#>, <#}}#>); - } - -<#}#> +<#@ template visibility="internal" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="NJsonSchema.CodeGeneration" #> +[GeneratedCode("NSwag", "<#=SwaggerService.ToolchainVersion#>")] +public interface I<#=Model.Class#>Controller +{ +<#foreach(var operation in Model.Operations){#> +<# if(operation.HasSummary){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1)#> +<# }foreach (var parameter in operation.Parameters){#> +<# if(parameter.HasDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1)#> +<# }}if(operation.HasResultDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1)#> +<# }if(operation.IsDeprecated){#> [Obsolete] +<# }#> <#=operation.ResultType#> <#=operation.OperationNameUpper#>Async(<#foreach(var parameter in operation.Parameters){#><#=parameter.Type#> <#=parameter.VariableNameLower#><#if(!parameter.IsLast){#>, <#}}#>); + +<#}#> +} + +[GeneratedCode("NSwag", "<#=SwaggerService.ToolchainVersion#>")] +public class <#=Model.Class#>Controller : <#if(Model.HasBaseClass){#><#=Model.BaseClass#><#}else{#>ApiController<#}#> +{ + private I<#=Model.Class#>Controller _implementation; + + public <#=Model.Class#>Controller(I<#=Model.Class#>Controller implementation) + { + _implementation = implementation; + } +<#foreach(var operation in Model.Operations){#> +<# if(operation.HasSummary){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.Summary, 1)#> +<# }foreach (var parameter in operation.Parameters){#> +<# if(parameter.HasDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(parameter.Description, 1)#> +<# }}if(operation.HasResultDescription){#> /// <#=ConversionUtilities.ConvertCSharpDocBreaks(operation.ResultDescription, 1)#> +<# }if(operation.IsDeprecated){#> [Obsolete] +<# }#> [Http<#=operation.HttpMethodUpper#>, Route("<#=operation.Path#>")] + public <#=operation.ResultType#> <#=operation.OperationNameUpper#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.Type#> <#=parameter.VariableNameLower#><#if(!parameter.IsLast){#>, <#}}#>) + { + return _implementation.<#=operation.OperationNameUpper#>Async(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#><#if(!parameter.IsLast){#>, <#}}#>); + } + +<#}#> } \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/FileTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/FileTemplate.Extensions.cs index 236b92ad47..c43cdf0fdf 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/FileTemplate.Extensions.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/FileTemplate.Extensions.cs @@ -4,17 +4,13 @@ namespace NSwag.CodeGeneration.CodeGenerators.CSharp.Templates { internal partial class FileTemplate : ITemplate { - public dynamic Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) + public FileTemplate(object model) { Model = model; } - /// Renders the template. - /// The output. + public dynamic Model { get; } + public string Render() { return ConversionUtilities.TrimWhiteSpaces(TransformText()); diff --git a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.Extensions.cs deleted file mode 100644 index e82b3df6a0..0000000000 --- a/src/NSwag.CodeGeneration/CodeGenerators/CSharp/Templates/WebApiControllerTemplate.Extensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using NJsonSchema.CodeGeneration; - -namespace NSwag.CodeGeneration.CodeGenerators.CSharp.Templates -{ - internal partial class WebApiControllerTemplate : ITemplate - { - public dynamic Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) - { - Model = model; - } - - /// Renders the template. - /// The output. - public string Render() - { - return ConversionUtilities.TrimWhiteSpaces(TransformText()); - } - } -} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/ClientGeneratorBaseSettings.cs b/src/NSwag.CodeGeneration/CodeGenerators/ClientGeneratorBaseSettings.cs index 6593cfe2a7..915d1f1ad1 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/ClientGeneratorBaseSettings.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/ClientGeneratorBaseSettings.cs @@ -18,7 +18,7 @@ public abstract class ClientGeneratorBaseSettings /// Initializes a new instance of the class. protected ClientGeneratorBaseSettings() { - GenerateClientClasses = true; + GenerateClientClasses = true; GenerateDtoTypes = true; OperationGenerationMode = OperationGenerationMode.MultipleClientsFromOperationId; } @@ -34,7 +34,7 @@ protected ClientGeneratorBaseSettings() /// Gets or sets a value indicating whether to generate DTO classes (default: true). public bool GenerateDtoTypes { get; set; } - + /// Gets or sets a value indicating whether to generate interfaces for the client classes. public bool GenerateClientInterfaces { get; set; } diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/RequestBodyGenerator.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/RequestBodyGenerator.cs index e49a1b9ac5..8ef29efafd 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/RequestBodyGenerator.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/RequestBodyGenerator.cs @@ -8,8 +8,7 @@ internal class RequestBodyGenerator { internal static string Render(ParameterModel model, int tabCount = 0) { - var tpl = new RequestBodyTemplate(); - tpl.Initialize(model); + var tpl = new RequestBodyTemplate(model); return ConversionUtilities.Tab(tpl.Render(), tabCount); } } diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs index 65cb30ebc4..d01945cb53 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/SwaggerToTypeScriptClientGenerator.cs @@ -10,10 +10,10 @@ using System.Collections.Generic; using System.Linq; using NJsonSchema; +using NJsonSchema.CodeGeneration; using NJsonSchema.CodeGeneration.TypeScript; using NSwag.CodeGeneration.CodeGenerators.Models; using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; -using NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates; namespace NSwag.CodeGeneration.CodeGenerators.TypeScript { @@ -60,8 +60,7 @@ public override string GenerateFile() internal override string GenerateFile(string clientCode, IEnumerable clientClasses, ClientGeneratorOutputType outputType) { - var template = new FileTemplate(); - template.Initialize(new + var model = new { IsAngular2 = Settings.GenerateClientClasses && Settings.Template == TypeScriptTemplate.Angular2, @@ -73,7 +72,8 @@ internal override string GenerateFile(string clientCode, IEnumerable cli HasModuleName = !string.IsNullOrEmpty(Settings.TypeScriptGeneratorSettings.ModuleName), ModuleName = Settings.TypeScriptGeneratorSettings.ModuleName - }); + }; + var template = BaseSettings.CodeGeneratorSettings.TemplateFactory.CreateTemplate("TypeScript", "File", model); return template.Render(); } @@ -81,8 +81,8 @@ internal override string GenerateClientClass(string controllerName, IListRico Suter, mail@rsuter.com //----------------------------------------------------------------------- -using System; using NJsonSchema; using NJsonSchema.CodeGeneration; using NJsonSchema.CodeGeneration.TypeScript; -using NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates; namespace NSwag.CodeGeneration.CodeGenerators.TypeScript { @@ -41,21 +39,9 @@ public SwaggerToTypeScriptClientGeneratorSettings() /// Gets or sets the promise type. public PromiseType PromiseType { get; set; } - internal ITemplate CreateTemplate() + internal ITemplate CreateTemplate(object model) { - if (Template == TypeScriptTemplate.Angular2) - return new Angular2Template(); - - if (Template == TypeScriptTemplate.AngularJS) - return new AngularJSTemplate(); - - if (Template == TypeScriptTemplate.JQueryCallbacks) - return new JQueryCallbacksTemplate(); - - if (Template == TypeScriptTemplate.JQueryPromises) - return new JQueryPromisesTemplate(); - - throw new NotImplementedException(); + return CodeGeneratorSettings.TemplateFactory.CreateTemplate("TypeScript", Template + "Client", model); } } } \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.Extensions.cs new file mode 100644 index 0000000000..24a44808b9 --- /dev/null +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.Extensions.cs @@ -0,0 +1,20 @@ +using NJsonSchema.CodeGeneration; +using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; + +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + internal partial class Angular2ClientTemplate : ITemplate + { + public Angular2ClientTemplate(ClientTemplateModel model) + { + Model = model; + } + + public ClientTemplateModel Model { get; } + + public string Render() + { + return ConversionUtilities.TrimWhiteSpaces(TransformText()); + } + } +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template1.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.cs similarity index 80% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template1.cs rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.cs index a16df32710..5721867d75 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template1.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.cs @@ -1,1442 +1,1442 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 14.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - using NJsonSchema.CodeGeneration; - using NSwag.CodeGeneration.CodeGenerators.TypeScript; - using System; - - /// - /// Class to produce the template output - /// - - #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal partial class Angular2Template : Angular2TemplateBase - { -#line hidden - /// - /// Create the template output - /// - public virtual string TransformText() - { - - #line 4 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.HasOperations){ - - #line default - #line hidden - - #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("export interface I"); - - #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - - #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(parameter.HasDescription){ - - #line default - #line hidden - this.Write(" * @"); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" "); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("): Observable<"); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(">;\r\n"); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("\r\n@Injectable()\r\nexport class "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("implements I"); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(@"{ - private http: Http = null; - private baseUrl: string = undefined; - private jsonParseReviver: (key: string, value: any) => any = undefined; - - constructor(@Inject(Http) http: Http, @Optional() @Inject(API_BASE_URL) baseUrl?: string, @Optional() @Inject(JSON_PARSE_REVIVER) jsonParseReviver?: (key: string, value: any) => any) { - this.http = http; - this.baseUrl = baseUrl ? baseUrl : """); - - #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); - - #line default - #line hidden - this.Write("\"; \r\n this.jsonParseReviver = jsonParseReviver;\r\n }\r\n"); - - #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("\r\n protected transformOptions(options: RequestOptionsArgs) {\r\n return o" + - "ptions; \r\n }\r\n\r\n protected transformResult(url: string, response: Response" + - ", processor: (response: Response) => any) {\r\n return processor(response);" + - "\r\n }\r\n"); - - #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - this.Write("\r\n"); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(parameter.HasDescription){ - - #line default - #line hidden - this.Write(" * @"); - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" "); - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("): Observable<"); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write("> {\r\n var url = this.baseUrl + \"/"); - - #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); - - #line default - #line hidden - this.Write("?\"; \r\n\r\n"); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.PathParameters){ - - #line default - #line hidden - this.Write(" if ("); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 54 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n"); - - #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); - - #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON())); \r\n"); - - #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".join())); \r\n"); - - #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(")); \r\n"); - - #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - - #line default - #line hidden - - #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("\r\n"); - - #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.QueryParameters){ - - #line default - #line hidden - - #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if (parameter.IsRequired) { - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); - - #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n else\r\n"); - - #line 72 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 74 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); - - #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - }else{ - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 80 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 81 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 82 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' cannot be null.\");\r\n else if ("); - - #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - } - - #line default - #line hidden - - #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" "); - - #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); - - #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url += \""); - - #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON()) + \"&\"; \r\n"); - - #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" "); - - #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); - - #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" url += \""); - - #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(") + \"&\"; \r\n"); - - #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } -} - - #line default - #line hidden - this.Write("\r\n "); - - #line 97 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); - - #line default - #line hidden - this.Write("\r\n \r\n return this.http.request(url, "); - - #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("this.transformOptions("); - - #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("{\r\n body: content,\r\n method: \""); - - #line 101 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodLower)); - - #line default - #line hidden - this.Write("\",\r\n headers: new Headers({\r\n"); - - #line 103 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var parameter in operation.HeaderParameters){ - - #line default - #line hidden - this.Write(" \""); - - #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("\": "); - - #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(", \r\n"); - - #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n })" + - "\r\n }"); - - #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(")"); - - #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(").map((response) => {\r\n"); - - #line 108 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(" return this.transformResult(url, response, (response) => this.process" + - ""); - - #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(response));\r\n"); - - #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -}else{ - - #line default - #line hidden - this.Write(" return this.process"); - - #line 111 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(response);\r\n"); - - #line 112 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" });\r\n }\r\n\r\n private process"); - - #line 116 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(response: Response) {\r\n var data = response.text();\r\n var status =" + - " response.status.toString(); \r\n\r\n"); - - #line 120 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -foreach(var response in operation.Responses){ - - #line default - #line hidden - this.Write(" if (status === \""); - - #line 121 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("\") {\r\n"); - - #line 122 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(response.HasType){ - - #line default - #line hidden - this.Write(" var result"); - - #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(": "); - - #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n"); - - #line 124 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(response.IsDate){ - - #line default - #line hidden - this.Write(" result"); - - #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = new Date(data);\r\n"); - - #line 126 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - - #line 127 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(response.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData"); - - #line 128 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : JSON.parse(data, this.jsonParseReviver);\r\n "); - - #line 129 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 3))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 130 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" result"); - - #line 131 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : <"); - - #line 131 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); - - #line 132 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - - #line default - #line hidden - - #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - - #line default - #line hidden - - #line 134 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(response.IsSuccess){ - - #line default - #line hidden - this.Write(" return result"); - - #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("; \r\n"); - - #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" throw result"); - - #line 137 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("; \r\n"); - - #line 138 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } -} - - #line default - #line hidden - this.Write(" }\r\n else\r\n"); - - #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 143 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -if(operation.HasDefaultResponse){ - - #line default - #line hidden - this.Write(" var result: "); - - #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n"); - - #line 145 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(operation.DefaultResponse.IsDate){ - - #line default - #line hidden - this.Write(" result = new Date(data);\r\n"); - - #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - - #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(operation.DefaultResponse.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData = data === \"\" ? null : JSON.parse(data, this.jsonParse" + - "Reviver);\r\n "); - - #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 151 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" result = data === \"\" ? null : <"); - - #line 152 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); - - #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - - #line default - #line hidden - - #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } - - #line default - #line hidden - - #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - if(operation.DefaultResponse.IsSuccess){ - - #line default - #line hidden - this.Write(" return result; \r\n"); - - #line 157 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - }else{ - - #line default - #line hidden - this.Write(" throw result; \r\n"); - - #line 159 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" - } -}else{ - - #line default - #line hidden - this.Write(" throw \"error_no_callback_for_the_received_http_status\"; \r\n"); - - #line 162 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write(" }\r\n }\r\n"); - - #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 166 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2Template.tt" -} - - #line default - #line hidden - this.Write("\r\n"); - return this.GenerationEnvironment.ToString(); - } - } - - #line default - #line hidden - #region Base class - /// - /// Base class for this transformation - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal class Angular2TemplateBase - { - #region Fields - private global::System.Text.StringBuilder generationEnvironmentField; - private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; - private global::System.Collections.Generic.List indentLengthsField; - private string currentIndentField = ""; - private bool endsWithNewline; - private global::System.Collections.Generic.IDictionary sessionField; - #endregion - #region Properties - /// - /// The string builder that generation-time code is using to assemble generated output - /// - protected System.Text.StringBuilder GenerationEnvironment - { - get - { - if ((this.generationEnvironmentField == null)) - { - this.generationEnvironmentField = new global::System.Text.StringBuilder(); - } - return this.generationEnvironmentField; - } - set - { - this.generationEnvironmentField = value; - } - } - /// - /// The error collection for the generation process - /// - public System.CodeDom.Compiler.CompilerErrorCollection Errors - { - get - { - if ((this.errorsField == null)) - { - this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); - } - return this.errorsField; - } - } - /// - /// A list of the lengths of each indent that was added with PushIndent - /// - private System.Collections.Generic.List indentLengths - { - get - { - if ((this.indentLengthsField == null)) - { - this.indentLengthsField = new global::System.Collections.Generic.List(); - } - return this.indentLengthsField; - } - } - /// - /// Gets the current indent we use when adding lines to the output - /// - public string CurrentIndent - { - get - { - return this.currentIndentField; - } - } - /// - /// Current transformation session - /// - public virtual global::System.Collections.Generic.IDictionary Session - { - get - { - return this.sessionField; - } - set - { - this.sessionField = value; - } - } - #endregion - #region Transform-time helpers - /// - /// Write text directly into the generated output - /// - public void Write(string textToAppend) - { - if (string.IsNullOrEmpty(textToAppend)) - { - return; - } - // If we're starting off, or if the previous text ended with a newline, - // we have to append the current indent first. - if (((this.GenerationEnvironment.Length == 0) - || this.endsWithNewline)) - { - this.GenerationEnvironment.Append(this.currentIndentField); - this.endsWithNewline = false; - } - // Check if the current text ends with a newline - if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) - { - this.endsWithNewline = true; - } - // This is an optimization. If the current indent is "", then we don't have to do any - // of the more complex stuff further down. - if ((this.currentIndentField.Length == 0)) - { - this.GenerationEnvironment.Append(textToAppend); - return; - } - // Everywhere there is a newline in the text, add an indent after it - textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); - // If the text ends with a newline, then we should strip off the indent added at the very end - // because the appropriate indent will be added when the next time Write() is called - if (this.endsWithNewline) - { - this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); - } - else - { - this.GenerationEnvironment.Append(textToAppend); - } - } - /// - /// Write text directly into the generated output - /// - public void WriteLine(string textToAppend) - { - this.Write(textToAppend); - this.GenerationEnvironment.AppendLine(); - this.endsWithNewline = true; - } - /// - /// Write formatted text directly into the generated output - /// - public void Write(string format, params object[] args) - { - this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Write formatted text directly into the generated output - /// - public void WriteLine(string format, params object[] args) - { - this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Raise an error - /// - public void Error(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - this.Errors.Add(error); - } - /// - /// Raise a warning - /// - public void Warning(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - error.IsWarning = true; - this.Errors.Add(error); - } - /// - /// Increase the indent - /// - public void PushIndent(string indent) - { - if ((indent == null)) - { - throw new global::System.ArgumentNullException("indent"); - } - this.currentIndentField = (this.currentIndentField + indent); - this.indentLengths.Add(indent.Length); - } - /// - /// Remove the last indent that was added with PushIndent - /// - public string PopIndent() - { - string returnValue = ""; - if ((this.indentLengths.Count > 0)) - { - int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; - this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); - if ((indentLength > 0)) - { - returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); - this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); - } - } - return returnValue; - } - /// - /// Remove any indentation - /// - public void ClearIndent() - { - this.indentLengths.Clear(); - this.currentIndentField = ""; - } - #endregion - #region ToString Helpers - /// - /// Utility class to produce culture-oriented representation of an object as a string. - /// - public class ToStringInstanceHelper - { - private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; - /// - /// Gets or sets format provider to be used by ToStringWithCulture method. - /// - public System.IFormatProvider FormatProvider - { - get - { - return this.formatProviderField ; - } - set - { - if ((value != null)) - { - this.formatProviderField = value; - } - } - } - /// - /// This is called from the compile/run appdomain to convert objects within an expression block to a string - /// - public string ToStringWithCulture(object objectToConvert) - { - if ((objectToConvert == null)) - { - throw new global::System.ArgumentNullException("objectToConvert"); - } - System.Type t = objectToConvert.GetType(); - System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { - typeof(System.IFormatProvider)}); - if ((method == null)) - { - return objectToConvert.ToString(); - } - else - { - return ((string)(method.Invoke(objectToConvert, new object[] { - this.formatProviderField }))); - } - } - } - private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); - /// - /// Helper to produce culture-oriented representation of an object as a string - /// - public ToStringInstanceHelper ToStringHelper - { - get - { - return this.toStringHelperField; - } - } - #endregion - } - #endregion -} +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 14.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + using NJsonSchema.CodeGeneration; + using NSwag.CodeGeneration.CodeGenerators.TypeScript; + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal partial class Angular2ClientTemplate : Angular2ClientTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + + #line 4 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.HasOperations){ + + #line default + #line hidden + + #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("export interface I"); + + #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + + #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(parameter.HasDescription){ + + #line default + #line hidden + this.Write(" * @"); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" "); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("): Observable<"); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(">;\r\n"); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n@Injectable()\r\nexport class "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("implements I"); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(@"{ + private http: Http = null; + private baseUrl: string = undefined; + private jsonParseReviver: (key: string, value: any) => any = undefined; + + constructor(@Inject(Http) http: Http, @Optional() @Inject(API_BASE_URL) baseUrl?: string, @Optional() @Inject(JSON_PARSE_REVIVER) jsonParseReviver?: (key: string, value: any) => any) { + this.http = http; + this.baseUrl = baseUrl ? baseUrl : """); + + #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); + + #line default + #line hidden + this.Write("\"; \r\n this.jsonParseReviver = jsonParseReviver;\r\n }\r\n"); + + #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("\r\n protected transformOptions(options: RequestOptionsArgs) {\r\n return o" + + "ptions; \r\n }\r\n\r\n protected transformResult(url: string, response: Response" + + ", processor: (response: Response) => any) {\r\n return processor(response);" + + "\r\n }\r\n"); + + #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + this.Write("\r\n"); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(parameter.HasDescription){ + + #line default + #line hidden + this.Write(" * @"); + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" "); + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("): Observable<"); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write("> {\r\n var url = this.baseUrl + \"/"); + + #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); + + #line default + #line hidden + this.Write("?\"; \r\n\r\n"); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.PathParameters){ + + #line default + #line hidden + this.Write(" if ("); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 54 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n"); + + #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); + + #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON())); \r\n"); + + #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".join())); \r\n"); + + #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(")); \r\n"); + + #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + + #line default + #line hidden + + #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n"); + + #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.QueryParameters){ + + #line default + #line hidden + + #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if (parameter.IsRequired) { + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); + + #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n else\r\n"); + + #line 72 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 74 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); + + #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + }else{ + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 80 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 81 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 82 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' cannot be null.\");\r\n else if ("); + + #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + } + + #line default + #line hidden + + #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" "); + + #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); + + #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url += \""); + + #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON()) + \"&\"; \r\n"); + + #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" "); + + #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); + + #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url += \""); + + #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(") + \"&\"; \r\n"); + + #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } +} + + #line default + #line hidden + this.Write("\r\n "); + + #line 97 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); + + #line default + #line hidden + this.Write("\r\n \r\n return this.http.request(url, "); + + #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("this.transformOptions("); + + #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("{\r\n body: content,\r\n method: \""); + + #line 101 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodLower)); + + #line default + #line hidden + this.Write("\",\r\n headers: new Headers({\r\n"); + + #line 103 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var parameter in operation.HeaderParameters){ + + #line default + #line hidden + this.Write(" \""); + + #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("\": "); + + #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(", \r\n"); + + #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n })" + + "\r\n }"); + + #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(")"); + + #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(").map((response) => {\r\n"); + + #line 108 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(" return this.transformResult(url, response, (response) => this.process" + + ""); + + #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(response));\r\n"); + + #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +}else{ + + #line default + #line hidden + this.Write(" return this.process"); + + #line 111 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(response);\r\n"); + + #line 112 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" });\r\n }\r\n\r\n private process"); + + #line 116 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(response: Response) {\r\n var data = response.text();\r\n var status =" + + " response.status.toString(); \r\n\r\n"); + + #line 120 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +foreach(var response in operation.Responses){ + + #line default + #line hidden + this.Write(" if (status === \""); + + #line 121 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("\") {\r\n"); + + #line 122 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(response.HasType){ + + #line default + #line hidden + this.Write(" var result"); + + #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(": "); + + #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n"); + + #line 124 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(response.IsDate){ + + #line default + #line hidden + this.Write(" result"); + + #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = new Date(data);\r\n"); + + #line 126 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 127 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(response.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData"); + + #line 128 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : JSON.parse(data, this.jsonParseReviver);\r\n "); + + #line 129 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 3))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 130 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result"); + + #line 131 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : <"); + + #line 131 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); + + #line 132 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + + #line default + #line hidden + + #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + + #line default + #line hidden + + #line 134 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(response.IsSuccess){ + + #line default + #line hidden + this.Write(" return result"); + + #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("; \r\n"); + + #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" throw result"); + + #line 137 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("; \r\n"); + + #line 138 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } +} + + #line default + #line hidden + this.Write(" }\r\n else\r\n"); + + #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 143 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +if(operation.HasDefaultResponse){ + + #line default + #line hidden + this.Write(" var result: "); + + #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n"); + + #line 145 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(operation.DefaultResponse.IsDate){ + + #line default + #line hidden + this.Write(" result = new Date(data);\r\n"); + + #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(operation.DefaultResponse.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData = data === \"\" ? null : JSON.parse(data, this.jsonParse" + + "Reviver);\r\n "); + + #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 151 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result = data === \"\" ? null : <"); + + #line 152 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); + + #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + + #line default + #line hidden + + #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } + + #line default + #line hidden + + #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + if(operation.DefaultResponse.IsSuccess){ + + #line default + #line hidden + this.Write(" return result; \r\n"); + + #line 157 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" throw result; \r\n"); + + #line 159 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" + } +}else{ + + #line default + #line hidden + this.Write(" throw \"error_no_callback_for_the_received_http_status\"; \r\n"); + + #line 162 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" }\r\n }\r\n"); + + #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 166 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\Angular2ClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n"); + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal class Angular2ClientTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + protected System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.tt b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.tt similarity index 97% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.tt rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.tt index b679d06880..9a8c5aa365 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.tt +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2ClientTemplate.tt @@ -1,167 +1,167 @@ -<#@ template visibility="internal" #> -<#@ import namespace="NJsonSchema.CodeGeneration" #> -<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> -<#if(Model.HasOperations){#> -<#if(Model.GenerateClientInterfaces){#> -export interface I<#=Model.Class#> { -<#foreach(var operation in Model.Operations){#> -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): Observable<<#=operation.ResultType#>>; -<#}#>} -<#}#> - -@Injectable() -export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ - private http: Http = null; - private baseUrl: string = undefined; - private jsonParseReviver: (key: string, value: any) => any = undefined; - - constructor(@Inject(Http) http: Http, @Optional() @Inject(API_BASE_URL) baseUrl?: string, @Optional() @Inject(JSON_PARSE_REVIVER) jsonParseReviver?: (key: string, value: any) => any) { - this.http = http; - this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>"; - this.jsonParseReviver = jsonParseReviver; - } -<#if(Model.IsExtended){#> - - protected transformOptions(options: RequestOptionsArgs) { - return options; - } - - protected transformResult(url: string, response: Response, processor: (response: Response) => any) { - return processor(response); - } -<#}#> -<#foreach(var operation in Model.Operations){#> - -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): Observable<<#=operation.ResultType#>> { - var url = this.baseUrl + "/<#=operation.Path#>?"; - -<#foreach(var parameter in operation.PathParameters){#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); -<# if(parameter.IsDateArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); -<# }else if(parameter.IsDate){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); -<# }else if(parameter.IsArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); -<# }else{#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); -<# }#> -<#}#> - -<#foreach(var parameter in operation.QueryParameters){#> -<# if (parameter.IsRequired) { - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> === undefined) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); - else -<# }else{#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); - else -<# } - }else{ - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> !== undefined) -<# }else{#> - if (<#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); - else if (<#=parameter.VariableNameLower#> !== undefined) -<# } - }#> -<# if(parameter.IsDateArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); -<# }else if(parameter.IsDate){#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; -<# }else if(parameter.IsArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); -<# }else{#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; -<# } -}#> - - <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> - - return this.http.request(url, <#if(Model.IsExtended){#>this.transformOptions(<#}#>{ - body: content, - method: "<#=operation.HttpMethodLower#>", - headers: new Headers({ -<#foreach(var parameter in operation.HeaderParameters){#> - "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, -<#}#> "Content-Type": "application/json; charset=UTF-8" - }) - }<#if(Model.IsExtended){#>)<#}#>).map((response) => { -<#if(Model.IsExtended){#> - return this.transformResult(url, response, (response) => this.process<#=operation.OperationNameUpper#>(response)); -<#}else{#> - return this.process<#=operation.OperationNameUpper#>(response); -<#}#> - }); - } - - private process<#=operation.OperationNameUpper#>(response: Response) { - var data = response.text(); - var status = response.status.toString(); - -<#foreach(var response in operation.Responses){#> - if (status === "<#=response.StatusCode#>") { -<#if(response.HasType){#> - var result<#=response.StatusCode#>: <#=response.Type#> = null; -<# if(response.IsDate){#> - result<#=response.StatusCode#> = new Date(data); -<# }else{#> -<# if(response.UseDtoClass){#> - var resultData<#=response.StatusCode#> = data === "" ? null : JSON.parse(data, this.jsonParseReviver); - <#=ConversionUtilities.Tab(response.DataConversionCode, 3)#> -<# }else{#> - result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>JSON.parse(data, this.jsonParseReviver); -<# }#> -<# }#> -<# if(response.IsSuccess){#> - return result<#=response.StatusCode#>; -<# }else{#> - throw result<#=response.StatusCode#>; -<# } -}#> - } - else -<#}#> { -<#if(operation.HasDefaultResponse){#> - var result: <#=operation.DefaultResponse.Type#> = null; -<# if(operation.DefaultResponse.IsDate){#> - result = new Date(data); -<# }else{#> -<# if(operation.DefaultResponse.UseDtoClass){#> - var resultData = data === "" ? null : JSON.parse(data, this.jsonParseReviver); - <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3)#> -<# }else{#> - result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>JSON.parse(data, this.jsonParseReviver); -<# }#> -<# }#> -<# if(operation.DefaultResponse.IsSuccess){#> - return result; -<# }else{#> - throw result; -<# } -}else{#> - throw "error_no_callback_for_the_received_http_status"; -<#}#> - } - } -<#}#>} -<#}#> - +<#@ template visibility="internal" #> +<#@ import namespace="NJsonSchema.CodeGeneration" #> +<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> +<#if(Model.HasOperations){#> +<#if(Model.GenerateClientInterfaces){#> +export interface I<#=Model.Class#> { +<#foreach(var operation in Model.Operations){#> +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): Observable<<#=operation.ResultType#>>; +<#}#>} +<#}#> + +@Injectable() +export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ + private http: Http = null; + private baseUrl: string = undefined; + private jsonParseReviver: (key: string, value: any) => any = undefined; + + constructor(@Inject(Http) http: Http, @Optional() @Inject(API_BASE_URL) baseUrl?: string, @Optional() @Inject(JSON_PARSE_REVIVER) jsonParseReviver?: (key: string, value: any) => any) { + this.http = http; + this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>"; + this.jsonParseReviver = jsonParseReviver; + } +<#if(Model.IsExtended){#> + + protected transformOptions(options: RequestOptionsArgs) { + return options; + } + + protected transformResult(url: string, response: Response, processor: (response: Response) => any) { + return processor(response); + } +<#}#> +<#foreach(var operation in Model.Operations){#> + +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): Observable<<#=operation.ResultType#>> { + var url = this.baseUrl + "/<#=operation.Path#>?"; + +<#foreach(var parameter in operation.PathParameters){#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); +<# if(parameter.IsDateArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); +<# }else if(parameter.IsDate){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); +<# }else if(parameter.IsArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); +<# }else{#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); +<# }#> +<#}#> + +<#foreach(var parameter in operation.QueryParameters){#> +<# if (parameter.IsRequired) { + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> === undefined) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); + else +<# }else{#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); + else +<# } + }else{ + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> !== undefined) +<# }else{#> + if (<#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); + else if (<#=parameter.VariableNameLower#> !== undefined) +<# } + }#> +<# if(parameter.IsDateArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); +<# }else if(parameter.IsDate){#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; +<# }else if(parameter.IsArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); +<# }else{#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; +<# } +}#> + + <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> + + return this.http.request(url, <#if(Model.IsExtended){#>this.transformOptions(<#}#>{ + body: content, + method: "<#=operation.HttpMethodLower#>", + headers: new Headers({ +<#foreach(var parameter in operation.HeaderParameters){#> + "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, +<#}#> "Content-Type": "application/json; charset=UTF-8" + }) + }<#if(Model.IsExtended){#>)<#}#>).map((response) => { +<#if(Model.IsExtended){#> + return this.transformResult(url, response, (response) => this.process<#=operation.OperationNameUpper#>(response)); +<#}else{#> + return this.process<#=operation.OperationNameUpper#>(response); +<#}#> + }); + } + + private process<#=operation.OperationNameUpper#>(response: Response) { + var data = response.text(); + var status = response.status.toString(); + +<#foreach(var response in operation.Responses){#> + if (status === "<#=response.StatusCode#>") { +<#if(response.HasType){#> + var result<#=response.StatusCode#>: <#=response.Type#> = null; +<# if(response.IsDate){#> + result<#=response.StatusCode#> = new Date(data); +<# }else{#> +<# if(response.UseDtoClass){#> + var resultData<#=response.StatusCode#> = data === "" ? null : JSON.parse(data, this.jsonParseReviver); + <#=ConversionUtilities.Tab(response.DataConversionCode, 3)#> +<# }else{#> + result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>JSON.parse(data, this.jsonParseReviver); +<# }#> +<# }#> +<# if(response.IsSuccess){#> + return result<#=response.StatusCode#>; +<# }else{#> + throw result<#=response.StatusCode#>; +<# } +}#> + } + else +<#}#> { +<#if(operation.HasDefaultResponse){#> + var result: <#=operation.DefaultResponse.Type#> = null; +<# if(operation.DefaultResponse.IsDate){#> + result = new Date(data); +<# }else{#> +<# if(operation.DefaultResponse.UseDtoClass){#> + var resultData = data === "" ? null : JSON.parse(data, this.jsonParseReviver); + <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3)#> +<# }else{#> + result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>JSON.parse(data, this.jsonParseReviver); +<# }#> +<# }#> +<# if(operation.DefaultResponse.IsSuccess){#> + return result; +<# }else{#> + throw result; +<# } +}else{#> + throw "error_no_callback_for_the_received_http_status"; +<#}#> + } + } +<#}#>} +<#}#> + diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.Extensions.cs deleted file mode 100644 index 01b18199d2..0000000000 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2Template.Extensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using NJsonSchema.CodeGeneration; -using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; - -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - internal partial class Angular2Template : ITemplate - { - public ClientTemplateModel Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) - { - Model = (ClientTemplateModel)model; - } - - /// Renders the template. - /// The output. - public string Render() - { - return ConversionUtilities.TrimWhiteSpaces(TransformText()); - } - } -} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.Extensions.cs new file mode 100644 index 0000000000..b8d8bd1b03 --- /dev/null +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.Extensions.cs @@ -0,0 +1,20 @@ +using NJsonSchema.CodeGeneration; +using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; + +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + internal partial class AngularJSClientTemplate : ITemplate + { + public AngularJSClientTemplate(ClientTemplateModel model) + { + Model = model; + } + + public ClientTemplateModel Model { get; } + + public string Render() + { + return ConversionUtilities.TrimWhiteSpaces(TransformText()); + } + } +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate1.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.cs similarity index 80% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate1.cs rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.cs index 7cbd9d9243..eff87dd30c 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate1.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.cs @@ -1,1442 +1,1442 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 14.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - using NJsonSchema.CodeGeneration; - using NSwag.CodeGeneration.CodeGenerators.TypeScript; - using System; - - /// - /// Class to produce the template output - /// - - #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal partial class AngularJSTemplate : AngularJSTemplateBase - { -#line hidden - /// - /// Create the template output - /// - public virtual string TransformText() - { - - #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.HasOperations){ - - #line default - #line hidden - - #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("export interface I"); - - #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - - #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(parameter.HasDescription){ - - #line default - #line hidden - this.Write(" * @"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" "); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("): ng.IPromise<"); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(">;\r\n"); - - #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\nexport class "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("implements I"); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(@"{ - private baseUrl: string = undefined; - private http: ng.IHttpService = null; - private jsonParseReviver: (key: string, value: any) => any = undefined; - - constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) { - this.http = $http; - this.baseUrl = baseUrl !== undefined ? baseUrl : """); - - #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); - - #line default - #line hidden - this.Write("\"; \r\n this.jsonParseReviver = jsonParseReviver;\r\n }\r\n"); - - #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("\r\n protected transformOptions(options: any) {\r\n return options; \r\n }" + - "\r\n\r\n protected transformResult(url: string, response: any, processor: (respon" + - "se: any) => any) {\r\n return processor(response);\r\n }\r\n"); - - #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - this.Write("\r\n"); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(parameter.HasDescription){ - - #line default - #line hidden - this.Write(" * @"); - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" "); - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("): ng.IPromise<"); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write("> {\r\n var url = this.baseUrl + \"/"); - - #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); - - #line default - #line hidden - this.Write("?\"; \r\n\r\n"); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.PathParameters){ - - #line default - #line hidden - this.Write(" if ("); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 54 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n"); - - #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); - - #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON())); \r\n"); - - #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".join())); \r\n"); - - #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(")); \r\n"); - - #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - - #line default - #line hidden - - #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\n"); - - #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.QueryParameters){ - - #line default - #line hidden - - #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if (parameter.IsRequired) { - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); - - #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n else\r\n"); - - #line 72 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 74 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); - - #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - }else{ - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 80 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 81 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 82 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' cannot be null.\");\r\n else if ("); - - #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - } - - #line default - #line hidden - - #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" "); - - #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); - - #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url += \""); - - #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON()) + \"&\"; \r\n"); - - #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" "); - - #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); - - #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" url += \""); - - #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(") + \"&\"; \r\n"); - - #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } -} - - #line default - #line hidden - this.Write("\r\n "); - - #line 97 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); - - #line default - #line hidden - this.Write("\r\n\r\n return this.http("); - - #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("this.transformOptions("); - - #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("{\r\n url: url,\r\n method: \""); - - #line 101 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodUpper)); - - #line default - #line hidden - this.Write("\",\r\n data: content,\r\n transformResponse: [], \r\n " + - "headers: {\r\n"); - - #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var parameter in operation.HeaderParameters){ - - #line default - #line hidden - this.Write(" \""); - - #line 106 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("\": "); - - #line 106 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(", \r\n"); - - #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n }\r" + - "\n }"); - - #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(")"); - - #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(").then((response) => {\r\n"); - - #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(" return this.transformResult(url, response, (response) => this.process" + - ""); - - #line 111 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(response));\r\n"); - - #line 112 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -}else{ - - #line default - #line hidden - this.Write(" return this.process"); - - #line 113 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(response);\r\n"); - - #line 114 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" });\r\n }\r\n\r\n private process"); - - #line 118 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(response: any) {\r\n var data = response.data;\r\n var status = respon" + - "se.status; \r\n\r\n"); - - #line 122 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -foreach(var response in operation.Responses){ - - #line default - #line hidden - this.Write(" if (status === "); - - #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(") {\r\n"); - - #line 124 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(response.HasType){ - - #line default - #line hidden - this.Write(" var result"); - - #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(": "); - - #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n"); - - #line 126 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(response.IsDate){ - - #line default - #line hidden - this.Write(" result"); - - #line 127 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = new Date(data);\r\n"); - - #line 128 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - - #line 129 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(response.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData"); - - #line 130 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : JSON.parse(data, this.jsonParseReviver);\r\n "); - - #line 131 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 3))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 132 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" result"); - - #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : <"); - - #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); - - #line 134 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - - #line default - #line hidden - - #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - - #line default - #line hidden - - #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(response.IsSuccess){ - - #line default - #line hidden - this.Write(" return result"); - - #line 137 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("; \r\n"); - - #line 138 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" throw result"); - - #line 139 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("; \r\n"); - - #line 140 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } -} - - #line default - #line hidden - this.Write(" }\r\n else\r\n"); - - #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 146 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -if(operation.HasDefaultResponse){ - - #line default - #line hidden - this.Write(" var result: "); - - #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n"); - - #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(operation.DefaultResponse.IsDate){ - - #line default - #line hidden - this.Write(" result = new Date(data);\r\n"); - - #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - - #line 151 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(operation.DefaultResponse.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData = data === \"\" ? null : JSON.parse(data, this.jsonParse" + - "Reviver);\r\n "); - - #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" result = data === \"\" ? null : <"); - - #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); - - #line 156 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - - #line default - #line hidden - - #line 157 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } - - #line default - #line hidden - - #line 158 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - if(operation.DefaultResponse.IsSuccess){ - - #line default - #line hidden - this.Write(" return result; \r\n"); - - #line 160 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" throw result; \r\n"); - - #line 162 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" - } -}else{ - - #line default - #line hidden - this.Write(" throw \"error_no_callback_for_the_received_http_status\"; \r\n"); - - #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write(" }\r\n }\r\n"); - - #line 168 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 169 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\n"); - return this.GenerationEnvironment.ToString(); - } - } - - #line default - #line hidden - #region Base class - /// - /// Base class for this transformation - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal class AngularJSTemplateBase - { - #region Fields - private global::System.Text.StringBuilder generationEnvironmentField; - private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; - private global::System.Collections.Generic.List indentLengthsField; - private string currentIndentField = ""; - private bool endsWithNewline; - private global::System.Collections.Generic.IDictionary sessionField; - #endregion - #region Properties - /// - /// The string builder that generation-time code is using to assemble generated output - /// - protected System.Text.StringBuilder GenerationEnvironment - { - get - { - if ((this.generationEnvironmentField == null)) - { - this.generationEnvironmentField = new global::System.Text.StringBuilder(); - } - return this.generationEnvironmentField; - } - set - { - this.generationEnvironmentField = value; - } - } - /// - /// The error collection for the generation process - /// - public System.CodeDom.Compiler.CompilerErrorCollection Errors - { - get - { - if ((this.errorsField == null)) - { - this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); - } - return this.errorsField; - } - } - /// - /// A list of the lengths of each indent that was added with PushIndent - /// - private System.Collections.Generic.List indentLengths - { - get - { - if ((this.indentLengthsField == null)) - { - this.indentLengthsField = new global::System.Collections.Generic.List(); - } - return this.indentLengthsField; - } - } - /// - /// Gets the current indent we use when adding lines to the output - /// - public string CurrentIndent - { - get - { - return this.currentIndentField; - } - } - /// - /// Current transformation session - /// - public virtual global::System.Collections.Generic.IDictionary Session - { - get - { - return this.sessionField; - } - set - { - this.sessionField = value; - } - } - #endregion - #region Transform-time helpers - /// - /// Write text directly into the generated output - /// - public void Write(string textToAppend) - { - if (string.IsNullOrEmpty(textToAppend)) - { - return; - } - // If we're starting off, or if the previous text ended with a newline, - // we have to append the current indent first. - if (((this.GenerationEnvironment.Length == 0) - || this.endsWithNewline)) - { - this.GenerationEnvironment.Append(this.currentIndentField); - this.endsWithNewline = false; - } - // Check if the current text ends with a newline - if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) - { - this.endsWithNewline = true; - } - // This is an optimization. If the current indent is "", then we don't have to do any - // of the more complex stuff further down. - if ((this.currentIndentField.Length == 0)) - { - this.GenerationEnvironment.Append(textToAppend); - return; - } - // Everywhere there is a newline in the text, add an indent after it - textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); - // If the text ends with a newline, then we should strip off the indent added at the very end - // because the appropriate indent will be added when the next time Write() is called - if (this.endsWithNewline) - { - this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); - } - else - { - this.GenerationEnvironment.Append(textToAppend); - } - } - /// - /// Write text directly into the generated output - /// - public void WriteLine(string textToAppend) - { - this.Write(textToAppend); - this.GenerationEnvironment.AppendLine(); - this.endsWithNewline = true; - } - /// - /// Write formatted text directly into the generated output - /// - public void Write(string format, params object[] args) - { - this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Write formatted text directly into the generated output - /// - public void WriteLine(string format, params object[] args) - { - this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Raise an error - /// - public void Error(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - this.Errors.Add(error); - } - /// - /// Raise a warning - /// - public void Warning(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - error.IsWarning = true; - this.Errors.Add(error); - } - /// - /// Increase the indent - /// - public void PushIndent(string indent) - { - if ((indent == null)) - { - throw new global::System.ArgumentNullException("indent"); - } - this.currentIndentField = (this.currentIndentField + indent); - this.indentLengths.Add(indent.Length); - } - /// - /// Remove the last indent that was added with PushIndent - /// - public string PopIndent() - { - string returnValue = ""; - if ((this.indentLengths.Count > 0)) - { - int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; - this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); - if ((indentLength > 0)) - { - returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); - this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); - } - } - return returnValue; - } - /// - /// Remove any indentation - /// - public void ClearIndent() - { - this.indentLengths.Clear(); - this.currentIndentField = ""; - } - #endregion - #region ToString Helpers - /// - /// Utility class to produce culture-oriented representation of an object as a string. - /// - public class ToStringInstanceHelper - { - private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; - /// - /// Gets or sets format provider to be used by ToStringWithCulture method. - /// - public System.IFormatProvider FormatProvider - { - get - { - return this.formatProviderField ; - } - set - { - if ((value != null)) - { - this.formatProviderField = value; - } - } - } - /// - /// This is called from the compile/run appdomain to convert objects within an expression block to a string - /// - public string ToStringWithCulture(object objectToConvert) - { - if ((objectToConvert == null)) - { - throw new global::System.ArgumentNullException("objectToConvert"); - } - System.Type t = objectToConvert.GetType(); - System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { - typeof(System.IFormatProvider)}); - if ((method == null)) - { - return objectToConvert.ToString(); - } - else - { - return ((string)(method.Invoke(objectToConvert, new object[] { - this.formatProviderField }))); - } - } - } - private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); - /// - /// Helper to produce culture-oriented representation of an object as a string - /// - public ToStringInstanceHelper ToStringHelper - { - get - { - return this.toStringHelperField; - } - } - #endregion - } - #endregion -} +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 14.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + using NJsonSchema.CodeGeneration; + using NSwag.CodeGeneration.CodeGenerators.TypeScript; + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal partial class AngularJSClientTemplate : AngularJSClientTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + + #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.HasOperations){ + + #line default + #line hidden + + #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("export interface I"); + + #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + + #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(parameter.HasDescription){ + + #line default + #line hidden + this.Write(" * @"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" "); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("): ng.IPromise<"); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(">;\r\n"); + + #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\nexport class "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("implements I"); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(@"{ + private baseUrl: string = undefined; + private http: ng.IHttpService = null; + private jsonParseReviver: (key: string, value: any) => any = undefined; + + constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) { + this.http = $http; + this.baseUrl = baseUrl !== undefined ? baseUrl : """); + + #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); + + #line default + #line hidden + this.Write("\"; \r\n this.jsonParseReviver = jsonParseReviver;\r\n }\r\n"); + + #line 30 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("\r\n protected transformOptions(options: any) {\r\n return options; \r\n }" + + "\r\n\r\n protected transformResult(url: string, response: any, processor: (respon" + + "se: any) => any) {\r\n return processor(response);\r\n }\r\n"); + + #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + this.Write("\r\n"); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(parameter.HasDescription){ + + #line default + #line hidden + this.Write(" * @"); + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" "); + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("): ng.IPromise<"); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write("> {\r\n var url = this.baseUrl + \"/"); + + #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); + + #line default + #line hidden + this.Write("?\"; \r\n\r\n"); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.PathParameters){ + + #line default + #line hidden + this.Write(" if ("); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 54 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n"); + + #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); + + #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON())); \r\n"); + + #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".join())); \r\n"); + + #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(")); \r\n"); + + #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + + #line default + #line hidden + + #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n"); + + #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.QueryParameters){ + + #line default + #line hidden + + #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if (parameter.IsRequired) { + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); + + #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n else\r\n"); + + #line 72 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 74 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); + + #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + }else{ + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 80 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 81 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 82 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' cannot be null.\");\r\n else if ("); + + #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + } + + #line default + #line hidden + + #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" "); + + #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); + + #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url += \""); + + #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON()) + \"&\"; \r\n"); + + #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" "); + + #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); + + #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url += \""); + + #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(") + \"&\"; \r\n"); + + #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } +} + + #line default + #line hidden + this.Write("\r\n "); + + #line 97 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); + + #line default + #line hidden + this.Write("\r\n\r\n return this.http("); + + #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("this.transformOptions("); + + #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("{\r\n url: url,\r\n method: \""); + + #line 101 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodUpper)); + + #line default + #line hidden + this.Write("\",\r\n data: content,\r\n transformResponse: [], \r\n " + + "headers: {\r\n"); + + #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var parameter in operation.HeaderParameters){ + + #line default + #line hidden + this.Write(" \""); + + #line 106 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("\": "); + + #line 106 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(", \r\n"); + + #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n }\r" + + "\n }"); + + #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(")"); + + #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(").then((response) => {\r\n"); + + #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(" return this.transformResult(url, response, (response) => this.process" + + ""); + + #line 111 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(response));\r\n"); + + #line 112 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +}else{ + + #line default + #line hidden + this.Write(" return this.process"); + + #line 113 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(response);\r\n"); + + #line 114 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" });\r\n }\r\n\r\n private process"); + + #line 118 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(response: any) {\r\n var data = response.data;\r\n var status = respon" + + "se.status; \r\n\r\n"); + + #line 122 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +foreach(var response in operation.Responses){ + + #line default + #line hidden + this.Write(" if (status === "); + + #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(") {\r\n"); + + #line 124 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(response.HasType){ + + #line default + #line hidden + this.Write(" var result"); + + #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(": "); + + #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n"); + + #line 126 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(response.IsDate){ + + #line default + #line hidden + this.Write(" result"); + + #line 127 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = new Date(data);\r\n"); + + #line 128 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 129 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(response.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData"); + + #line 130 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : JSON.parse(data, this.jsonParseReviver);\r\n "); + + #line 131 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 3))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 132 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result"); + + #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : <"); + + #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); + + #line 134 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + + #line default + #line hidden + + #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + + #line default + #line hidden + + #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(response.IsSuccess){ + + #line default + #line hidden + this.Write(" return result"); + + #line 137 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("; \r\n"); + + #line 138 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" throw result"); + + #line 139 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("; \r\n"); + + #line 140 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } +} + + #line default + #line hidden + this.Write(" }\r\n else\r\n"); + + #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 146 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +if(operation.HasDefaultResponse){ + + #line default + #line hidden + this.Write(" var result: "); + + #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n"); + + #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(operation.DefaultResponse.IsDate){ + + #line default + #line hidden + this.Write(" result = new Date(data);\r\n"); + + #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 151 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(operation.DefaultResponse.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData = data === \"\" ? null : JSON.parse(data, this.jsonParse" + + "Reviver);\r\n "); + + #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result = data === \"\" ? null : <"); + + #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(">JSON.parse(data, this.jsonParseReviver);\r\n"); + + #line 156 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + + #line default + #line hidden + + #line 157 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } + + #line default + #line hidden + + #line 158 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + if(operation.DefaultResponse.IsSuccess){ + + #line default + #line hidden + this.Write(" return result; \r\n"); + + #line 160 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" throw result; \r\n"); + + #line 162 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" + } +}else{ + + #line default + #line hidden + this.Write(" throw \"error_no_callback_for_the_received_http_status\"; \r\n"); + + #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" }\r\n }\r\n"); + + #line 168 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 169 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\AngularJSClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n"); + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal class AngularJSClientTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + protected System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.tt b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.tt similarity index 97% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.tt rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.tt index b203d6c12b..65ff53855a 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.tt +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSClientTemplate.tt @@ -1,170 +1,170 @@ -<#@ template visibility="internal" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="NJsonSchema.CodeGeneration" #> -<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> -<#if(Model.HasOperations){#> -<#if(Model.GenerateClientInterfaces){#> -export interface I<#=Model.Class#> { -<#foreach(var operation in Model.Operations){#> -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): ng.IPromise<<#=operation.ResultType#>>; -<#}#>} -<#}#> - -export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ - private baseUrl: string = undefined; - private http: ng.IHttpService = null; - private jsonParseReviver: (key: string, value: any) => any = undefined; - - constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) { - this.http = $http; - this.baseUrl = baseUrl !== undefined ? baseUrl : "<#=Model.BaseUrl#>"; - this.jsonParseReviver = jsonParseReviver; - } -<#if(Model.IsExtended){#> - - protected transformOptions(options: any) { - return options; - } - - protected transformResult(url: string, response: any, processor: (response: any) => any) { - return processor(response); - } -<#}#> -<#foreach(var operation in Model.Operations){#> - -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): ng.IPromise<<#=operation.ResultType#>> { - var url = this.baseUrl + "/<#=operation.Path#>?"; - -<#foreach(var parameter in operation.PathParameters){#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); -<# if(parameter.IsDateArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); -<# }else if(parameter.IsDate){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); -<# }else if(parameter.IsArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); -<# }else{#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); -<# }#> -<#}#> - -<#foreach(var parameter in operation.QueryParameters){#> -<# if (parameter.IsRequired) { - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> === undefined) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); - else -<# }else{#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); - else -<# } - }else{ - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> !== undefined) -<# }else{#> - if (<#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); - else if (<#=parameter.VariableNameLower#> !== undefined) -<# } - }#> -<# if(parameter.IsDateArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); -<# }else if(parameter.IsDate){#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; -<# }else if(parameter.IsArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); -<# }else{#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; -<# } -}#> - - <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> - - return this.http(<#if(Model.IsExtended){#>this.transformOptions(<#}#>{ - url: url, - method: "<#=operation.HttpMethodUpper#>", - data: content, - transformResponse: [], - headers: { -<#foreach(var parameter in operation.HeaderParameters){#> - "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, -<#}#> "Content-Type": "application/json; charset=UTF-8" - } - }<#if(Model.IsExtended){#>)<#}#>).then((response) => { -<#if(Model.IsExtended){#> - return this.transformResult(url, response, (response) => this.process<#=operation.OperationNameUpper#>(response)); -<#}else{#> - return this.process<#=operation.OperationNameUpper#>(response); -<#}#> - }); - } - - private process<#=operation.OperationNameUpper#>(response: any) { - var data = response.data; - var status = response.status; - -<#foreach(var response in operation.Responses){#> - if (status === <#=response.StatusCode#>) { -<#if(response.HasType){#> - var result<#=response.StatusCode#>: <#=response.Type#> = null; -<# if(response.IsDate){#> - result<#=response.StatusCode#> = new Date(data); -<# }else{#> -<# if(response.UseDtoClass){#> - var resultData<#=response.StatusCode#> = data === "" ? null : JSON.parse(data, this.jsonParseReviver); - <#=ConversionUtilities.Tab(response.DataConversionCode, 3)#> -<# }else{#> - result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>JSON.parse(data, this.jsonParseReviver); -<# }#> -<# }#> -<# if(response.IsSuccess){#> - return result<#=response.StatusCode#>; -<# }else{#> - throw result<#=response.StatusCode#>; -<# } -}#> - } - else -<#}#> - { -<#if(operation.HasDefaultResponse){#> - var result: <#=operation.DefaultResponse.Type#> = null; -<# if(operation.DefaultResponse.IsDate){#> - result = new Date(data); -<# }else{#> -<# if(operation.DefaultResponse.UseDtoClass){#> - var resultData = data === "" ? null : JSON.parse(data, this.jsonParseReviver); - <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3)#> -<# }else{#> - result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>JSON.parse(data, this.jsonParseReviver); -<# }#> -<# }#> -<# if(operation.DefaultResponse.IsSuccess){#> - return result; -<# }else{#> - throw result; -<# } -}else{#> - throw "error_no_callback_for_the_received_http_status"; -<#}#> - } - } -<#}#>} -<#}#> - +<#@ template visibility="internal" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="NJsonSchema.CodeGeneration" #> +<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> +<#if(Model.HasOperations){#> +<#if(Model.GenerateClientInterfaces){#> +export interface I<#=Model.Class#> { +<#foreach(var operation in Model.Operations){#> +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): ng.IPromise<<#=operation.ResultType#>>; +<#}#>} +<#}#> + +export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ + private baseUrl: string = undefined; + private http: ng.IHttpService = null; + private jsonParseReviver: (key: string, value: any) => any = undefined; + + constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) { + this.http = $http; + this.baseUrl = baseUrl !== undefined ? baseUrl : "<#=Model.BaseUrl#>"; + this.jsonParseReviver = jsonParseReviver; + } +<#if(Model.IsExtended){#> + + protected transformOptions(options: any) { + return options; + } + + protected transformResult(url: string, response: any, processor: (response: any) => any) { + return processor(response); + } +<#}#> +<#foreach(var operation in Model.Operations){#> + +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescription){#> * @<#=parameter.VariableNameLower#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): ng.IPromise<<#=operation.ResultType#>> { + var url = this.baseUrl + "/<#=operation.Path#>?"; + +<#foreach(var parameter in operation.PathParameters){#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); +<# if(parameter.IsDateArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); +<# }else if(parameter.IsDate){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); +<# }else if(parameter.IsArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); +<# }else{#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); +<# }#> +<#}#> + +<#foreach(var parameter in operation.QueryParameters){#> +<# if (parameter.IsRequired) { + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> === undefined) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); + else +<# }else{#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); + else +<# } + }else{ + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> !== undefined) +<# }else{#> + if (<#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); + else if (<#=parameter.VariableNameLower#> !== undefined) +<# } + }#> +<# if(parameter.IsDateArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); +<# }else if(parameter.IsDate){#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; +<# }else if(parameter.IsArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); +<# }else{#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; +<# } +}#> + + <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> + + return this.http(<#if(Model.IsExtended){#>this.transformOptions(<#}#>{ + url: url, + method: "<#=operation.HttpMethodUpper#>", + data: content, + transformResponse: [], + headers: { +<#foreach(var parameter in operation.HeaderParameters){#> + "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, +<#}#> "Content-Type": "application/json; charset=UTF-8" + } + }<#if(Model.IsExtended){#>)<#}#>).then((response) => { +<#if(Model.IsExtended){#> + return this.transformResult(url, response, (response) => this.process<#=operation.OperationNameUpper#>(response)); +<#}else{#> + return this.process<#=operation.OperationNameUpper#>(response); +<#}#> + }); + } + + private process<#=operation.OperationNameUpper#>(response: any) { + var data = response.data; + var status = response.status; + +<#foreach(var response in operation.Responses){#> + if (status === <#=response.StatusCode#>) { +<#if(response.HasType){#> + var result<#=response.StatusCode#>: <#=response.Type#> = null; +<# if(response.IsDate){#> + result<#=response.StatusCode#> = new Date(data); +<# }else{#> +<# if(response.UseDtoClass){#> + var resultData<#=response.StatusCode#> = data === "" ? null : JSON.parse(data, this.jsonParseReviver); + <#=ConversionUtilities.Tab(response.DataConversionCode, 3)#> +<# }else{#> + result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>JSON.parse(data, this.jsonParseReviver); +<# }#> +<# }#> +<# if(response.IsSuccess){#> + return result<#=response.StatusCode#>; +<# }else{#> + throw result<#=response.StatusCode#>; +<# } +}#> + } + else +<#}#> + { +<#if(operation.HasDefaultResponse){#> + var result: <#=operation.DefaultResponse.Type#> = null; +<# if(operation.DefaultResponse.IsDate){#> + result = new Date(data); +<# }else{#> +<# if(operation.DefaultResponse.UseDtoClass){#> + var resultData = data === "" ? null : JSON.parse(data, this.jsonParseReviver); + <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 3)#> +<# }else{#> + result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>JSON.parse(data, this.jsonParseReviver); +<# }#> +<# }#> +<# if(operation.DefaultResponse.IsSuccess){#> + return result; +<# }else{#> + throw result; +<# } +}else{#> + throw "error_no_callback_for_the_received_http_status"; +<#}#> + } + } +<#}#>} +<#}#> + diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.Extensions.cs deleted file mode 100644 index c10482c9d7..0000000000 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/AngularJSTemplate.Extensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using NJsonSchema.CodeGeneration; -using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; - -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - internal partial class AngularJSTemplate : ITemplate - { - public ClientTemplateModel Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) - { - Model = (ClientTemplateModel)model; - } - - /// Renders the template. - /// The output. - public string Render() - { - return ConversionUtilities.TrimWhiteSpaces(TransformText()); - } - } -} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/FileTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/FileTemplate.Extensions.cs index e6b376b855..22ff9d7f94 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/FileTemplate.Extensions.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/FileTemplate.Extensions.cs @@ -4,17 +4,13 @@ namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates { internal partial class FileTemplate : ITemplate { - public dynamic Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) + public FileTemplate(object model) { Model = model; } - /// Renders the template. - /// The output. + public dynamic Model { get; } + public string Render() { return ConversionUtilities.TrimWhiteSpaces(TransformText()); diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.Extensions.cs new file mode 100644 index 0000000000..04ed7c31b2 --- /dev/null +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.Extensions.cs @@ -0,0 +1,20 @@ +using NJsonSchema.CodeGeneration; +using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; + +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + internal partial class JQueryCallbacksClientTemplate : ITemplate + { + public JQueryCallbacksClientTemplate(ClientTemplateModel model) + { + Model = model; + } + + public ClientTemplateModel Model { get; } + + public string Render() + { + return ConversionUtilities.TrimWhiteSpaces(TransformText()); + } + } +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate1.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.cs similarity index 79% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate1.cs rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.cs index 27ed077f27..70538327e9 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate1.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.cs @@ -1,1588 +1,1588 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 14.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - using NJsonSchema.CodeGeneration; - using NSwag.CodeGeneration.CodeGenerators.TypeScript; - using System; - - /// - /// Class to produce the template output - /// - - #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal partial class JQueryCallbacksTemplate : JQueryCallbacksTemplateBase - { -#line hidden - /// - /// Create the template output - /// - public virtual string TransformText() - { - - #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.HasOperations){ - - #line default - #line hidden - - #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("export interface I"); - - #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - - #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(parameter.HasDescriptionOrIsOptional){ - - #line default - #line hidden - this.Write(" * @"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(parameter.IsOptional){ - - #line default - #line hidden - this.Write(" (optional)"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - this.Write(", "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("onSuccess?: ("); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasResultType){ - - #line default - #line hidden - this.Write("result: "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(") => void, onFail?: (exception: "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ExceptionType)); - - #line default - #line hidden - this.Write(", reason: string) => void): void;\r\n"); - - #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\nexport class "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("implements I"); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("{\r\n baseUrl: string = undefined; \r\n beforeSend: any = undefined; \r\n\r\n co" + - "nstructor(baseUrl?: string) {\r\n this.baseUrl = baseUrl !== undefined ? ba" + - "seUrl : \""); - - #line 25 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); - - #line default - #line hidden - this.Write("\"; \r\n }\r\n"); - - #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("\r\n protected transformOptions(options: any) {\r\n return options; \r\n }" + - "\r\n\r\n protected transformResult(url: string, xhr: any, processor: (xhr: any) =" + - "> any) {\r\n return processor(xhr);\r\n }\r\n"); - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 37 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - this.Write("\r\n"); - - #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(parameter.HasDescriptionOrIsOptional){ - - #line default - #line hidden - this.Write(" * @"); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(parameter.IsOptional){ - - #line default - #line hidden - this.Write(" (optional)"); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - this.Write(", "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("onSuccess?: ("); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasResultType){ - - #line default - #line hidden - this.Write("result: "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(") => void, onFail?: (exception: "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ExceptionType)); - - #line default - #line hidden - this.Write(", reason: string) => void) {\r\n var url = this.baseUrl + \"/"); - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); - - #line default - #line hidden - this.Write("?\"; \r\n\r\n"); - - #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.PathParameters){ - - #line default - #line hidden - this.Write(" if ("); - - #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 51 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n"); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); - - #line 54 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON())); \r\n"); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".join())); \r\n"); - - #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(")); \r\n"); - - #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - - #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\n"); - - #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.QueryParameters){ - - #line default - #line hidden - - #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if (parameter.IsRequired) { - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); - - #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n else\r\n"); - - #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 71 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); - - #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - }else{ - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 77 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 78 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' cannot be null.\");\r\n else if ("); - - #line 80 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 81 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - } - - #line default - #line hidden - - #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" "); - - #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); - - #line 85 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url += \""); - - #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON()) + \"&\"; \r\n"); - - #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" "); - - #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); - - #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" url += \""); - - #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(") + \"&\"; \r\n"); - - #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } -} - - #line default - #line hidden - this.Write("\r\n "); - - #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); - - #line default - #line hidden - this.Write("\r\n\r\n jQuery.ajax("); - - #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("this.transformOptions("); - - #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("{\r\n url: url,\r\n beforeSend: this.beforeSend,\r\n t" + - "ype: \""); - - #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodLower)); - - #line default - #line hidden - this.Write("\",\r\n data: content,\r\n dataType: \"text\",\r\n header" + - "s: {\r\n"); - - #line 103 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var parameter in operation.HeaderParameters){ - - #line default - #line hidden - this.Write(" \""); - - #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("\": "); - - #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(", \r\n"); - - #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n }\r" + - "\n }"); - - #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(")"); - - #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(").done((data, textStatus, xhr) => {\r\n this.process"); - - #line 108 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n }).fail((xhr) => {\r\n " + - " this.process"); - - #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n });\r\n }\r\n\r\n private pr" + - "ocess"); - - #line 114 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) {\r\n tr" + - "y {\r\n"); - - #line 116 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(" var result = this.transformResult(url, xhr, (xhr) => this.process"); - - #line 117 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(xhr));\r\n"); - - #line 118 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -}else{ - - #line default - #line hidden - this.Write(" var result = this.process"); - - #line 119 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(xhr);\r\n"); - - #line 120 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" if (onSuccess !== undefined)\r\n onSuccess(result);\r\n " + - " } catch (e) {\r\n if (onFail !== undefined)\r\n onFai" + - "l(e, \"http_service_exception\");\r\n }\r\n }\r\n\r\n private process"); - - #line 129 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(xhr: any) {\r\n var data = xhr.responseText; \r\n var status = xhr.sta" + - "tus.toString(); \r\n\r\n"); - - #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -foreach(var response in operation.Responses){ - - #line default - #line hidden - this.Write(" if (status === \""); - - #line 134 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("\") {\r\n"); - - #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(response.HasType){ - - #line default - #line hidden - this.Write(" var result"); - - #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(": "); - - #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + - "\n"); - - #line 138 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(response.IsDate){ - - #line default - #line hidden - this.Write(" result"); - - #line 139 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = new Date(data);\r\n"); - - #line 140 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - - #line 141 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(response.IsFile){ - - #line default - #line hidden - this.Write(" result"); - - #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data;\r\n"); - - #line 143 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - - #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(response.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData"); - - #line 145 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : jQuery.parseJSON(data);\r\n "); - - #line 146 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 4))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" result"); - - #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : <"); - - #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(">jQuery.parseJSON(data);\r\n"); - - #line 149 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - - #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - } - - #line default - #line hidden - this.Write(" }\r\n"); - - #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" var result"); - - #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(": any = undefined; \r\n"); - - #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - - #line 156 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(response.IsSuccess){ - - #line default - #line hidden - this.Write(" return result"); - - #line 157 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(";\r\n"); - - #line 158 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" throw result"); - - #line 159 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(";\r\n"); - - #line 160 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - this.Write(" }\r\n else\r\n"); - - #line 163 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -if(operation.HasDefaultResponse){ - - #line default - #line hidden - - #line 166 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(operation.DefaultResponse.HasType){ - - #line default - #line hidden - this.Write(" var result: "); - - #line 167 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + - "\n"); - - #line 169 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(operation.DefaultResponse.IsDate){ - - #line default - #line hidden - this.Write(" result = new Date(data);\r\n"); - - #line 171 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - - #line 172 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(operation.DefaultResponse.IsFile){ - - #line default - #line hidden - this.Write(" result = data;\r\n"); - - #line 174 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - - #line 175 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(operation.DefaultResponse.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData = data === \"\" ? null : jQuery.parseJSON(data);\r\n " + - " "); - - #line 177 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 178 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" result = data === \"\" ? null : <"); - - #line 179 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(">jQuery.parseJSON(data);\r\n"); - - #line 180 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - - #line 181 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - - #line 182 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - this.Write(" }\r\n"); - - #line 184 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" var result: any = undefined; \r\n"); - - #line 186 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } - - #line default - #line hidden - this.Write("\r\n"); - - #line 188 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - if(operation.HasOnlyDefaultResponse){ - - #line default - #line hidden - this.Write(" if (status.length === 3 && status.indexOf(\"2\") === 0)\r\n " + - " return result;\r\n else\r\n throw result;\r\n"); - - #line 193 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" return result; \r\n"); - - #line 195 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" - } -}else{ - - #line default - #line hidden - this.Write(" throw new Error(\"error_no_callback_for_the_received_http_status\");\r\n"); - - #line 198 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write(" }\r\n }\r\n"); - - #line 201 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 202 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksTemplate.tt" -} - - #line default - #line hidden - return this.GenerationEnvironment.ToString(); - } - } - - #line default - #line hidden - #region Base class - /// - /// Base class for this transformation - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal class JQueryCallbacksTemplateBase - { - #region Fields - private global::System.Text.StringBuilder generationEnvironmentField; - private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; - private global::System.Collections.Generic.List indentLengthsField; - private string currentIndentField = ""; - private bool endsWithNewline; - private global::System.Collections.Generic.IDictionary sessionField; - #endregion - #region Properties - /// - /// The string builder that generation-time code is using to assemble generated output - /// - protected System.Text.StringBuilder GenerationEnvironment - { - get - { - if ((this.generationEnvironmentField == null)) - { - this.generationEnvironmentField = new global::System.Text.StringBuilder(); - } - return this.generationEnvironmentField; - } - set - { - this.generationEnvironmentField = value; - } - } - /// - /// The error collection for the generation process - /// - public System.CodeDom.Compiler.CompilerErrorCollection Errors - { - get - { - if ((this.errorsField == null)) - { - this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); - } - return this.errorsField; - } - } - /// - /// A list of the lengths of each indent that was added with PushIndent - /// - private System.Collections.Generic.List indentLengths - { - get - { - if ((this.indentLengthsField == null)) - { - this.indentLengthsField = new global::System.Collections.Generic.List(); - } - return this.indentLengthsField; - } - } - /// - /// Gets the current indent we use when adding lines to the output - /// - public string CurrentIndent - { - get - { - return this.currentIndentField; - } - } - /// - /// Current transformation session - /// - public virtual global::System.Collections.Generic.IDictionary Session - { - get - { - return this.sessionField; - } - set - { - this.sessionField = value; - } - } - #endregion - #region Transform-time helpers - /// - /// Write text directly into the generated output - /// - public void Write(string textToAppend) - { - if (string.IsNullOrEmpty(textToAppend)) - { - return; - } - // If we're starting off, or if the previous text ended with a newline, - // we have to append the current indent first. - if (((this.GenerationEnvironment.Length == 0) - || this.endsWithNewline)) - { - this.GenerationEnvironment.Append(this.currentIndentField); - this.endsWithNewline = false; - } - // Check if the current text ends with a newline - if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) - { - this.endsWithNewline = true; - } - // This is an optimization. If the current indent is "", then we don't have to do any - // of the more complex stuff further down. - if ((this.currentIndentField.Length == 0)) - { - this.GenerationEnvironment.Append(textToAppend); - return; - } - // Everywhere there is a newline in the text, add an indent after it - textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); - // If the text ends with a newline, then we should strip off the indent added at the very end - // because the appropriate indent will be added when the next time Write() is called - if (this.endsWithNewline) - { - this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); - } - else - { - this.GenerationEnvironment.Append(textToAppend); - } - } - /// - /// Write text directly into the generated output - /// - public void WriteLine(string textToAppend) - { - this.Write(textToAppend); - this.GenerationEnvironment.AppendLine(); - this.endsWithNewline = true; - } - /// - /// Write formatted text directly into the generated output - /// - public void Write(string format, params object[] args) - { - this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Write formatted text directly into the generated output - /// - public void WriteLine(string format, params object[] args) - { - this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Raise an error - /// - public void Error(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - this.Errors.Add(error); - } - /// - /// Raise a warning - /// - public void Warning(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - error.IsWarning = true; - this.Errors.Add(error); - } - /// - /// Increase the indent - /// - public void PushIndent(string indent) - { - if ((indent == null)) - { - throw new global::System.ArgumentNullException("indent"); - } - this.currentIndentField = (this.currentIndentField + indent); - this.indentLengths.Add(indent.Length); - } - /// - /// Remove the last indent that was added with PushIndent - /// - public string PopIndent() - { - string returnValue = ""; - if ((this.indentLengths.Count > 0)) - { - int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; - this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); - if ((indentLength > 0)) - { - returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); - this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); - } - } - return returnValue; - } - /// - /// Remove any indentation - /// - public void ClearIndent() - { - this.indentLengths.Clear(); - this.currentIndentField = ""; - } - #endregion - #region ToString Helpers - /// - /// Utility class to produce culture-oriented representation of an object as a string. - /// - public class ToStringInstanceHelper - { - private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; - /// - /// Gets or sets format provider to be used by ToStringWithCulture method. - /// - public System.IFormatProvider FormatProvider - { - get - { - return this.formatProviderField ; - } - set - { - if ((value != null)) - { - this.formatProviderField = value; - } - } - } - /// - /// This is called from the compile/run appdomain to convert objects within an expression block to a string - /// - public string ToStringWithCulture(object objectToConvert) - { - if ((objectToConvert == null)) - { - throw new global::System.ArgumentNullException("objectToConvert"); - } - System.Type t = objectToConvert.GetType(); - System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { - typeof(System.IFormatProvider)}); - if ((method == null)) - { - return objectToConvert.ToString(); - } - else - { - return ((string)(method.Invoke(objectToConvert, new object[] { - this.formatProviderField }))); - } - } - } - private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); - /// - /// Helper to produce culture-oriented representation of an object as a string - /// - public ToStringInstanceHelper ToStringHelper - { - get - { - return this.toStringHelperField; - } - } - #endregion - } - #endregion -} +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 14.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + using NJsonSchema.CodeGeneration; + using NSwag.CodeGeneration.CodeGenerators.TypeScript; + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal partial class JQueryCallbacksClientTemplate : JQueryCallbacksClientTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + + #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.HasOperations){ + + #line default + #line hidden + + #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("export interface I"); + + #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + + #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(parameter.HasDescriptionOrIsOptional){ + + #line default + #line hidden + this.Write(" * @"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(parameter.IsOptional){ + + #line default + #line hidden + this.Write(" (optional)"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + this.Write(", "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("onSuccess?: ("); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasResultType){ + + #line default + #line hidden + this.Write("result: "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(") => void, onFail?: (exception: "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ExceptionType)); + + #line default + #line hidden + this.Write(", reason: string) => void): void;\r\n"); + + #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\nexport class "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("implements I"); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("{\r\n baseUrl: string = undefined; \r\n beforeSend: any = undefined; \r\n\r\n co" + + "nstructor(baseUrl?: string) {\r\n this.baseUrl = baseUrl !== undefined ? ba" + + "seUrl : \""); + + #line 25 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); + + #line default + #line hidden + this.Write("\"; \r\n }\r\n"); + + #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("\r\n protected transformOptions(options: any) {\r\n return options; \r\n }" + + "\r\n\r\n protected transformResult(url: string, xhr: any, processor: (xhr: any) =" + + "> any) {\r\n return processor(xhr);\r\n }\r\n"); + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 37 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + this.Write("\r\n"); + + #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(parameter.HasDescriptionOrIsOptional){ + + #line default + #line hidden + this.Write(" * @"); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(parameter.IsOptional){ + + #line default + #line hidden + this.Write(" (optional)"); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + this.Write(", "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("onSuccess?: ("); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasResultType){ + + #line default + #line hidden + this.Write("result: "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(") => void, onFail?: (exception: "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ExceptionType)); + + #line default + #line hidden + this.Write(", reason: string) => void) {\r\n var url = this.baseUrl + \"/"); + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); + + #line default + #line hidden + this.Write("?\"; \r\n\r\n"); + + #line 49 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.PathParameters){ + + #line default + #line hidden + this.Write(" if ("); + + #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 50 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 51 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n"); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); + + #line 54 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON())); \r\n"); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".join())); \r\n"); + + #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(")); \r\n"); + + #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + + #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n"); + + #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.QueryParameters){ + + #line default + #line hidden + + #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if (parameter.IsRequired) { + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); + + #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n else\r\n"); + + #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 71 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); + + #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + }else{ + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 77 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 78 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' cannot be null.\");\r\n else if ("); + + #line 80 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 81 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + } + + #line default + #line hidden + + #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" "); + + #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); + + #line 85 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url += \""); + + #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON()) + \"&\"; \r\n"); + + #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" "); + + #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 88 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); + + #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url += \""); + + #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(") + \"&\"; \r\n"); + + #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } +} + + #line default + #line hidden + this.Write("\r\n "); + + #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); + + #line default + #line hidden + this.Write("\r\n\r\n jQuery.ajax("); + + #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("this.transformOptions("); + + #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("{\r\n url: url,\r\n beforeSend: this.beforeSend,\r\n t" + + "ype: \""); + + #line 99 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodLower)); + + #line default + #line hidden + this.Write("\",\r\n data: content,\r\n dataType: \"text\",\r\n header" + + "s: {\r\n"); + + #line 103 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var parameter in operation.HeaderParameters){ + + #line default + #line hidden + this.Write(" \""); + + #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("\": "); + + #line 104 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(", \r\n"); + + #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n }\r" + + "\n }"); + + #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(")"); + + #line 107 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(").done((data, textStatus, xhr) => {\r\n this.process"); + + #line 108 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n }).fail((xhr) => {\r\n " + + " this.process"); + + #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n });\r\n }\r\n\r\n private pr" + + "ocess"); + + #line 114 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) {\r\n tr" + + "y {\r\n"); + + #line 116 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(" var result = this.transformResult(url, xhr, (xhr) => this.process"); + + #line 117 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(xhr));\r\n"); + + #line 118 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +}else{ + + #line default + #line hidden + this.Write(" var result = this.process"); + + #line 119 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(xhr);\r\n"); + + #line 120 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" if (onSuccess !== undefined)\r\n onSuccess(result);\r\n " + + " } catch (e) {\r\n if (onFail !== undefined)\r\n onFai" + + "l(e, \"http_service_exception\");\r\n }\r\n }\r\n\r\n private process"); + + #line 129 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(xhr: any) {\r\n var data = xhr.responseText; \r\n var status = xhr.sta" + + "tus.toString(); \r\n\r\n"); + + #line 133 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +foreach(var response in operation.Responses){ + + #line default + #line hidden + this.Write(" if (status === \""); + + #line 134 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("\") {\r\n"); + + #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(response.HasType){ + + #line default + #line hidden + this.Write(" var result"); + + #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(": "); + + #line 136 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + + "\n"); + + #line 138 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(response.IsDate){ + + #line default + #line hidden + this.Write(" result"); + + #line 139 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = new Date(data);\r\n"); + + #line 140 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 141 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(response.IsFile){ + + #line default + #line hidden + this.Write(" result"); + + #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data;\r\n"); + + #line 143 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(response.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData"); + + #line 145 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : jQuery.parseJSON(data);\r\n "); + + #line 146 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 4))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result"); + + #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : <"); + + #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(">jQuery.parseJSON(data);\r\n"); + + #line 149 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + + #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + } + + #line default + #line hidden + this.Write(" }\r\n"); + + #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" var result"); + + #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(": any = undefined; \r\n"); + + #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + + #line 156 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(response.IsSuccess){ + + #line default + #line hidden + this.Write(" return result"); + + #line 157 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(";\r\n"); + + #line 158 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" throw result"); + + #line 159 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(";\r\n"); + + #line 160 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + this.Write(" }\r\n else\r\n"); + + #line 163 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +if(operation.HasDefaultResponse){ + + #line default + #line hidden + + #line 166 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(operation.DefaultResponse.HasType){ + + #line default + #line hidden + this.Write(" var result: "); + + #line 167 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + + "\n"); + + #line 169 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(operation.DefaultResponse.IsDate){ + + #line default + #line hidden + this.Write(" result = new Date(data);\r\n"); + + #line 171 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 172 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(operation.DefaultResponse.IsFile){ + + #line default + #line hidden + this.Write(" result = data;\r\n"); + + #line 174 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 175 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(operation.DefaultResponse.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData = data === \"\" ? null : jQuery.parseJSON(data);\r\n " + + " "); + + #line 177 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 178 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result = data === \"\" ? null : <"); + + #line 179 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(">jQuery.parseJSON(data);\r\n"); + + #line 180 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + + #line 181 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + + #line 182 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + this.Write(" }\r\n"); + + #line 184 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" var result: any = undefined; \r\n"); + + #line 186 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } + + #line default + #line hidden + this.Write("\r\n"); + + #line 188 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + if(operation.HasOnlyDefaultResponse){ + + #line default + #line hidden + this.Write(" if (status.length === 3 && status.indexOf(\"2\") === 0)\r\n " + + " return result;\r\n else\r\n throw result;\r\n"); + + #line 193 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" return result; \r\n"); + + #line 195 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" + } +}else{ + + #line default + #line hidden + this.Write(" throw new Error(\"error_no_callback_for_the_received_http_status\");\r\n"); + + #line 198 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" }\r\n }\r\n"); + + #line 201 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 202 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryCallbacksClientTemplate.tt" +} + + #line default + #line hidden + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal class JQueryCallbacksClientTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + protected System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.tt b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.tt similarity index 97% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.tt rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.tt index 3b8d2c0410..9ab953abef 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.tt +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksClientTemplate.tt @@ -1,202 +1,202 @@ -<#@ template visibility="internal" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="NJsonSchema.CodeGeneration" #> -<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> -<#if(Model.HasOperations){#> -<#if(Model.GenerateClientInterfaces){#> -export interface I<#=Model.Class#> { -<#foreach(var operation in Model.Operations){#> -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#>, <#}#>onSuccess?: (<#if(operation.HasResultType){#>result: <#=operation.ResultType#><#}#>) => void, onFail?: (exception: <#=operation.ExceptionType#>, reason: string) => void): void; -<#}#>} -<#}#> - -export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ - baseUrl: string = undefined; - beforeSend: any = undefined; - - constructor(baseUrl?: string) { - this.baseUrl = baseUrl !== undefined ? baseUrl : "<#=Model.BaseUrl#>"; - } -<#if(Model.IsExtended){#> - - protected transformOptions(options: any) { - return options; - } - - protected transformResult(url: string, xhr: any, processor: (xhr: any) => any) { - return processor(xhr); - } -<#}#> -<#foreach(var operation in Model.Operations){#> - -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#>, <#}#>onSuccess?: (<#if(operation.HasResultType){#>result: <#=operation.ResultType#><#}#>) => void, onFail?: (exception: <#=operation.ExceptionType#>, reason: string) => void) { - var url = this.baseUrl + "/<#=operation.Path#>?"; - -<#foreach(var parameter in operation.PathParameters){#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); -<# if(parameter.IsDateArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); -<# }else if(parameter.IsDate){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); -<# }else if(parameter.IsArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); -<# }else{#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); -<# }#> -<#}#> - -<#foreach(var parameter in operation.QueryParameters){#> -<# if (parameter.IsRequired) { - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> === undefined) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); - else -<# }else{#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); - else -<# } - }else{ - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> !== undefined) -<# }else{#> - if (<#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); - else if (<#=parameter.VariableNameLower#> !== undefined) -<# } - }#> -<# if(parameter.IsDateArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); -<# }else if(parameter.IsDate){#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; -<# }else if(parameter.IsArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); -<# }else{#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; -<# } -}#> - - <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> - - jQuery.ajax(<#if(Model.IsExtended){#>this.transformOptions(<#}#>{ - url: url, - beforeSend: this.beforeSend, - type: "<#=operation.HttpMethodLower#>", - data: content, - dataType: "text", - headers: { -<#foreach(var parameter in operation.HeaderParameters){#> - "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, -<#}#> "Content-Type": "application/json; charset=UTF-8" - } - }<#if(Model.IsExtended){#>)<#}#>).done((data, textStatus, xhr) => { - this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); - }).fail((xhr) => { - this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); - }); - } - - private process<#=operation.OperationNameUpper#>WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) { - try { -<#if(Model.IsExtended){#> - var result = this.transformResult(url, xhr, (xhr) => this.process<#=operation.OperationNameUpper#>(xhr)); -<#}else{#> - var result = this.process<#=operation.OperationNameUpper#>(xhr); -<#}#> - if (onSuccess !== undefined) - onSuccess(result); - } catch (e) { - if (onFail !== undefined) - onFail(e, "http_service_exception"); - } - } - - private process<#=operation.OperationNameUpper#>(xhr: any) { - var data = xhr.responseText; - var status = xhr.status.toString(); - -<#foreach(var response in operation.Responses){#> - if (status === "<#=response.StatusCode#>") { -<# if(response.HasType){#> - var result<#=response.StatusCode#>: <#=response.Type#> = null; - if (data !== undefined && data !== null && data !== "") { -<# if(response.IsDate){#> - result<#=response.StatusCode#> = new Date(data); -<# }else{#> -<# if(response.IsFile){#> - result<#=response.StatusCode#> = data; -<# }else{#> -<# if(response.UseDtoClass){#> - var resultData<#=response.StatusCode#> = data === "" ? null : jQuery.parseJSON(data); - <#=ConversionUtilities.Tab(response.DataConversionCode, 4)#> -<# }else{#> - result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>jQuery.parseJSON(data); -<# }#> -<# } - }#> - } -<# }else{#> - var result<#=response.StatusCode#>: any = undefined; -<# }#> -<# if(response.IsSuccess){#> - return result<#=response.StatusCode#>; -<# }else{#> - throw result<#=response.StatusCode#>; -<# }#> - } - else -<#}#> - { -<#if(operation.HasDefaultResponse){#> -<# if(operation.DefaultResponse.HasType){#> - var result: <#=operation.DefaultResponse.Type#> = null; - if (data !== undefined && data !== null && data !== "") { -<# if(operation.DefaultResponse.IsDate){#> - result = new Date(data); -<# }else{#> -<# if(operation.DefaultResponse.IsFile){#> - result = data; -<# }else{#> -<# if(operation.DefaultResponse.UseDtoClass){#> - var resultData = data === "" ? null : jQuery.parseJSON(data); - <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4)#> -<# }else{#> - result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>jQuery.parseJSON(data); -<# }#> -<# }#> -<# }#> - } -<# }else{#> - var result: any = undefined; -<# }#> - -<# if(operation.HasOnlyDefaultResponse){#> - if (status.length === 3 && status.indexOf("2") === 0) - return result; - else - throw result; -<# }else{#> - return result; -<# } -}else{#> - throw new Error("error_no_callback_for_the_received_http_status"); -<#}#> - } - } -<#}#>} +<#@ template visibility="internal" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="NJsonSchema.CodeGeneration" #> +<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> +<#if(Model.HasOperations){#> +<#if(Model.GenerateClientInterfaces){#> +export interface I<#=Model.Class#> { +<#foreach(var operation in Model.Operations){#> +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#>, <#}#>onSuccess?: (<#if(operation.HasResultType){#>result: <#=operation.ResultType#><#}#>) => void, onFail?: (exception: <#=operation.ExceptionType#>, reason: string) => void): void; +<#}#>} +<#}#> + +export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ + baseUrl: string = undefined; + beforeSend: any = undefined; + + constructor(baseUrl?: string) { + this.baseUrl = baseUrl !== undefined ? baseUrl : "<#=Model.BaseUrl#>"; + } +<#if(Model.IsExtended){#> + + protected transformOptions(options: any) { + return options; + } + + protected transformResult(url: string, xhr: any, processor: (xhr: any) => any) { + return processor(xhr); + } +<#}#> +<#foreach(var operation in Model.Operations){#> + +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#>, <#}#>onSuccess?: (<#if(operation.HasResultType){#>result: <#=operation.ResultType#><#}#>) => void, onFail?: (exception: <#=operation.ExceptionType#>, reason: string) => void) { + var url = this.baseUrl + "/<#=operation.Path#>?"; + +<#foreach(var parameter in operation.PathParameters){#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); +<# if(parameter.IsDateArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); +<# }else if(parameter.IsDate){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); +<# }else if(parameter.IsArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); +<# }else{#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); +<# }#> +<#}#> + +<#foreach(var parameter in operation.QueryParameters){#> +<# if (parameter.IsRequired) { + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> === undefined) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); + else +<# }else{#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); + else +<# } + }else{ + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> !== undefined) +<# }else{#> + if (<#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); + else if (<#=parameter.VariableNameLower#> !== undefined) +<# } + }#> +<# if(parameter.IsDateArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); +<# }else if(parameter.IsDate){#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; +<# }else if(parameter.IsArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); +<# }else{#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; +<# } +}#> + + <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> + + jQuery.ajax(<#if(Model.IsExtended){#>this.transformOptions(<#}#>{ + url: url, + beforeSend: this.beforeSend, + type: "<#=operation.HttpMethodLower#>", + data: content, + dataType: "text", + headers: { +<#foreach(var parameter in operation.HeaderParameters){#> + "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, +<#}#> "Content-Type": "application/json; charset=UTF-8" + } + }<#if(Model.IsExtended){#>)<#}#>).done((data, textStatus, xhr) => { + this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); + }).fail((xhr) => { + this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); + }); + } + + private process<#=operation.OperationNameUpper#>WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) { + try { +<#if(Model.IsExtended){#> + var result = this.transformResult(url, xhr, (xhr) => this.process<#=operation.OperationNameUpper#>(xhr)); +<#}else{#> + var result = this.process<#=operation.OperationNameUpper#>(xhr); +<#}#> + if (onSuccess !== undefined) + onSuccess(result); + } catch (e) { + if (onFail !== undefined) + onFail(e, "http_service_exception"); + } + } + + private process<#=operation.OperationNameUpper#>(xhr: any) { + var data = xhr.responseText; + var status = xhr.status.toString(); + +<#foreach(var response in operation.Responses){#> + if (status === "<#=response.StatusCode#>") { +<# if(response.HasType){#> + var result<#=response.StatusCode#>: <#=response.Type#> = null; + if (data !== undefined && data !== null && data !== "") { +<# if(response.IsDate){#> + result<#=response.StatusCode#> = new Date(data); +<# }else{#> +<# if(response.IsFile){#> + result<#=response.StatusCode#> = data; +<# }else{#> +<# if(response.UseDtoClass){#> + var resultData<#=response.StatusCode#> = data === "" ? null : jQuery.parseJSON(data); + <#=ConversionUtilities.Tab(response.DataConversionCode, 4)#> +<# }else{#> + result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>jQuery.parseJSON(data); +<# }#> +<# } + }#> + } +<# }else{#> + var result<#=response.StatusCode#>: any = undefined; +<# }#> +<# if(response.IsSuccess){#> + return result<#=response.StatusCode#>; +<# }else{#> + throw result<#=response.StatusCode#>; +<# }#> + } + else +<#}#> + { +<#if(operation.HasDefaultResponse){#> +<# if(operation.DefaultResponse.HasType){#> + var result: <#=operation.DefaultResponse.Type#> = null; + if (data !== undefined && data !== null && data !== "") { +<# if(operation.DefaultResponse.IsDate){#> + result = new Date(data); +<# }else{#> +<# if(operation.DefaultResponse.IsFile){#> + result = data; +<# }else{#> +<# if(operation.DefaultResponse.UseDtoClass){#> + var resultData = data === "" ? null : jQuery.parseJSON(data); + <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4)#> +<# }else{#> + result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>jQuery.parseJSON(data); +<# }#> +<# }#> +<# }#> + } +<# }else{#> + var result: any = undefined; +<# }#> + +<# if(operation.HasOnlyDefaultResponse){#> + if (status.length === 3 && status.indexOf("2") === 0) + return result; + else + throw result; +<# }else{#> + return result; +<# } +}else{#> + throw new Error("error_no_callback_for_the_received_http_status"); +<#}#> + } + } +<#}#>} <#}#> \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.Extensions.cs deleted file mode 100644 index 9491163b5a..0000000000 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacksTemplate.Extensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using NJsonSchema.CodeGeneration; -using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; - -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - internal partial class JQueryCallbacksTemplate : ITemplate - { - public ClientTemplateModel Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) - { - Model = (ClientTemplateModel)model; - } - - /// Renders the template. - /// The output. - public string Render() - { - return ConversionUtilities.TrimWhiteSpaces(TransformText()); - } - } -} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.Extensions.cs new file mode 100644 index 0000000000..8f9253ea01 --- /dev/null +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.Extensions.cs @@ -0,0 +1,20 @@ +using NJsonSchema.CodeGeneration; +using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; + +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + internal partial class JQueryPromisesClientTemplate : ITemplate + { + public JQueryPromisesClientTemplate(ClientTemplateModel model) + { + Model = model; + } + + public ClientTemplateModel Model { get; } + + public string Render() + { + return ConversionUtilities.TrimWhiteSpaces(TransformText()); + } + } +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.cs similarity index 79% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.cs rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.cs index d6fc9704ad..b2d9ad6f90 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.cs @@ -1,1676 +1,1676 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 14.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - using NJsonSchema.CodeGeneration; - using NSwag.CodeGeneration.CodeGenerators.TypeScript; - using System; - - /// - /// Class to produce the template output - /// - - #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal partial class JQueryPromisesTemplate : JQueryPromisesTemplateBase - { -#line hidden - /// - /// Create the template output - /// - public virtual string TransformText() - { - - #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.HasOperations){ - - #line default - #line hidden - - #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("export interface I"); - - #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - - #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(parameter.HasDescriptionOrIsOptional){ - - #line default - #line hidden - this.Write(" * @"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(parameter.IsOptional){ - - #line default - #line hidden - this.Write(" (optional)"); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("): "); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.PromiseType)); - - #line default - #line hidden - this.Write("<"); - - #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(">;\r\n"); - - #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\nexport class "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.GenerateClientInterfaces){ - - #line default - #line hidden - this.Write("implements I"); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); - - #line default - #line hidden - this.Write(" "); - - #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("{\r\n baseUrl: string = undefined; \r\n beforeSend: any = undefined; \r\n\r\n co" + - "nstructor(baseUrl?: string) {\r\n this.baseUrl = baseUrl !== undefined ? ba" + - "seUrl : \""); - - #line 25 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); - - #line default - #line hidden - this.Write("\"; \r\n }\r\n"); - - #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("\r\n protected transformOptions(options: any) {\r\n return options; \r\n }" + - "\r\n\r\n protected transformResult(url: string, xhr: any, processor: (xhr: any) =" + - "> any) {\r\n return processor(xhr);\r\n }\r\n"); - - #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 37 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var operation in Model.Operations){ - - #line default - #line hidden - this.Write("\r\n"); - - #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasDocumentation){ - - #line default - #line hidden - this.Write(" /**\r\n"); - - #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasSummary){ - - #line default - #line hidden - this.Write(" * "); - - #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(parameter.HasDescriptionOrIsOptional){ - - #line default - #line hidden - this.Write(" * @"); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(parameter.IsOptional){ - - #line default - #line hidden - this.Write(" (optional)"); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); - - #line default - #line hidden - this.Write("\r\n"); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasResultDescription){ - - #line default - #line hidden - this.Write(" * @return "); - - #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); - - #line default - #line hidden - this.Write("\r\n"); - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.IsDeprecated){ - - #line default - #line hidden - this.Write(" * @deprecated\r\n"); - - #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" */\r\n"); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("("); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(!parameter.IsLast){ - - #line default - #line hidden - this.Write(", "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("): "); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.PromiseType)); - - #line default - #line hidden - this.Write("<"); - - #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write("> {\r\n return "); - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(Model.PromiseConstructor)); - - #line default - #line hidden - this.Write("<"); - - #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(">((resolve, reject) => {\r\n this."); - - #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("WithCallbacks("); - - #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(", "); - - #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("(result) => resolve(result), (exception, reason) => reject(exception));\r\n " + - "});\r\n }\r\n \r\n private "); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); - - #line default - #line hidden - this.Write("WithCallbacks("); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.Parameters){ - - #line default - #line hidden - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(": "); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); - - #line default - #line hidden - this.Write(", "); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("onSuccess?: (result: "); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); - - #line default - #line hidden - this.Write(") => void, onFail?: (exception: "); - - #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.ExceptionType)); - - #line default - #line hidden - this.Write(", reason: string) => void) {\r\n var url = this.baseUrl + \"/"); - - #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); - - #line default - #line hidden - this.Write("?\"; \r\n\r\n"); - - #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.PathParameters){ - - #line default - #line hidden - this.Write(" if ("); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n"); - - #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); - - #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON())); \r\n"); - - #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent("); - - #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".join())); \r\n"); - - #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" url = url.replace(\"{"); - - #line 65 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("}\", encodeURIComponent(\"\" + "); - - #line 65 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(")); \r\n"); - - #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - - #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("\r\n"); - - #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.QueryParameters){ - - #line default - #line hidden - - #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if (parameter.IsRequired) { - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 72 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); - - #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined.\");\r\n else\r\n"); - - #line 75 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === undefined || "); - - #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 77 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); - - #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - }else{ - if(parameter.IsNullable){ - - #line default - #line hidden - this.Write(" if ("); - - #line 82 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" if ("); - - #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" === null)\r\n throw new Error(\"The parameter \'"); - - #line 85 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write("\' cannot be null.\");\r\n else if ("); - - #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(" !== undefined)\r\n"); - - #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - } - - #line default - #line hidden - - #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(parameter.IsDateArray){ - - #line default - #line hidden - this.Write(" "); - - #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); - - #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else if(parameter.IsDate){ - - #line default - #line hidden - this.Write(" url += \""); - - #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".toJSON()) + \"&\"; \r\n"); - - #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else if(parameter.IsArray){ - - #line default - #line hidden - this.Write(" "); - - #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(".forEach(item => { url += \""); - - #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); - - #line 95 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" url += \""); - - #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("=\" + encodeURIComponent(\"\" + "); - - #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(") + \"&\"; \r\n"); - - #line 97 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } -} - - #line default - #line hidden - this.Write("\r\n "); - - #line 100 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); - - #line default - #line hidden - this.Write("\r\n\r\n jQuery.ajax("); - - #line 102 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write("this.transformOptions("); - - #line 102 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("{\r\n url: url,\r\n beforeSend: this.beforeSend,\r\n t" + - "ype: \""); - - #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodLower)); - - #line default - #line hidden - this.Write("\",\r\n data: content,\r\n dataType: \"text\",\r\n header" + - "s: {\r\n"); - - #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var parameter in operation.HeaderParameters){ - - #line default - #line hidden - this.Write(" \""); - - #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); - - #line default - #line hidden - this.Write("\": "); - - #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); - - #line default - #line hidden - this.Write(", \r\n"); - - #line 111 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n }\r" + - "\n }"); - - #line 113 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(")"); - - #line 113 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(").done((data, textStatus, xhr) => {\r\n this.process"); - - #line 114 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n }).fail((xhr) => {\r\n " + - " this.process"); - - #line 116 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n });\r\n }\r\n\r\n private pr" + - "ocess"); - - #line 120 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) {\r\n tr" + - "y {\r\n"); - - #line 122 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(Model.IsExtended){ - - #line default - #line hidden - this.Write(" var result = this.transformResult(url, xhr, (xhr) => this.process"); - - #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(xhr));\r\n"); - - #line 124 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -}else{ - - #line default - #line hidden - this.Write(" var result = this.process"); - - #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(xhr);\r\n"); - - #line 126 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" if (onSuccess !== undefined)\r\n onSuccess(result);\r\n " + - " } catch (e) {\r\n if (onFail !== undefined)\r\n onFai" + - "l(e, \"http_service_exception\");\r\n }\r\n }\r\n\r\n private process"); - - #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); - - #line default - #line hidden - this.Write("(xhr: any) {\r\n var data = xhr.responseText; \r\n var status = xhr.sta" + - "tus.toString(); \r\n\r\n"); - - #line 139 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -foreach(var response in operation.Responses){ - - #line default - #line hidden - this.Write(" if (status === \""); - - #line 140 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write("\") {\r\n"); - - #line 141 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(response.HasType){ - - #line default - #line hidden - this.Write(" var result"); - - #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(": "); - - #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + - "\n"); - - #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(response.IsDate){ - - #line default - #line hidden - this.Write(" result"); - - #line 145 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = new Date(data);\r\n"); - - #line 146 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - - #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(response.IsFile){ - - #line default - #line hidden - this.Write(" result"); - - #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data;\r\n"); - - #line 149 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - - #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(response.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData"); - - #line 151 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : jQuery.parseJSON(data);\r\n "); - - #line 152 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 4))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" result"); - - #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(" = data === \"\" ? null : <"); - - #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); - - #line default - #line hidden - this.Write(">jQuery.parseJSON(data);\r\n"); - - #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - - #line 156 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - } - - #line default - #line hidden - this.Write(" }\r\n"); - - #line 159 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" var result"); - - #line 160 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(": any = undefined; \r\n"); - - #line 161 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - - #line 162 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(response.IsSuccess){ - - #line default - #line hidden - this.Write(" return result"); - - #line 163 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(";\r\n"); - - #line 164 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" throw result"); - - #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); - - #line default - #line hidden - this.Write(";\r\n"); - - #line 166 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - this.Write(" }\r\n else\r\n"); - - #line 169 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" {\r\n"); - - #line 171 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -if(operation.HasDefaultResponse){ - - #line default - #line hidden - - #line 172 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(operation.DefaultResponse.HasType){ - - #line default - #line hidden - this.Write(" var result: "); - - #line 173 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + - "\n"); - - #line 175 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(operation.DefaultResponse.IsDate){ - - #line default - #line hidden - this.Write(" result = new Date(data);\r\n"); - - #line 177 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - - #line 178 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(operation.DefaultResponse.IsFile){ - - #line default - #line hidden - this.Write(" result = data;\r\n"); - - #line 180 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - - #line 181 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(operation.DefaultResponse.UseDtoClass){ - - #line default - #line hidden - this.Write(" var resultData = data === \"\" ? null : jQuery.parseJSON(data);\r\n " + - " "); - - #line 183 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4))); - - #line default - #line hidden - this.Write("\r\n"); - - #line 184 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" result = data === \"\" ? null : <"); - - #line 185 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); - - #line default - #line hidden - this.Write(">jQuery.parseJSON(data);\r\n"); - - #line 186 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - - #line 187 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - - #line 188 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - this.Write(" }\r\n"); - - #line 190 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" var result: any = undefined; \r\n"); - - #line 192 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } - - #line default - #line hidden - this.Write("\r\n"); - - #line 194 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - if(operation.HasOnlyDefaultResponse){ - - #line default - #line hidden - this.Write(" if (status.length === 3 && status.indexOf(\"2\") === 0)\r\n " + - " return result;\r\n else\r\n throw result;\r\n"); - - #line 199 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - }else{ - - #line default - #line hidden - this.Write(" return result; \r\n"); - - #line 201 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" - } -}else{ - - #line default - #line hidden - this.Write(" throw new Error(\"error_no_callback_for_the_received_http_status\");\r\n"); - - #line 204 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write(" }\r\n }\r\n"); - - #line 207 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - this.Write("}\r\n"); - - #line 208 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesTemplate.tt" -} - - #line default - #line hidden - return this.GenerationEnvironment.ToString(); - } - } - - #line default - #line hidden - #region Base class - /// - /// Base class for this transformation - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] - internal class JQueryPromisesTemplateBase - { - #region Fields - private global::System.Text.StringBuilder generationEnvironmentField; - private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; - private global::System.Collections.Generic.List indentLengthsField; - private string currentIndentField = ""; - private bool endsWithNewline; - private global::System.Collections.Generic.IDictionary sessionField; - #endregion - #region Properties - /// - /// The string builder that generation-time code is using to assemble generated output - /// - protected System.Text.StringBuilder GenerationEnvironment - { - get - { - if ((this.generationEnvironmentField == null)) - { - this.generationEnvironmentField = new global::System.Text.StringBuilder(); - } - return this.generationEnvironmentField; - } - set - { - this.generationEnvironmentField = value; - } - } - /// - /// The error collection for the generation process - /// - public System.CodeDom.Compiler.CompilerErrorCollection Errors - { - get - { - if ((this.errorsField == null)) - { - this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); - } - return this.errorsField; - } - } - /// - /// A list of the lengths of each indent that was added with PushIndent - /// - private System.Collections.Generic.List indentLengths - { - get - { - if ((this.indentLengthsField == null)) - { - this.indentLengthsField = new global::System.Collections.Generic.List(); - } - return this.indentLengthsField; - } - } - /// - /// Gets the current indent we use when adding lines to the output - /// - public string CurrentIndent - { - get - { - return this.currentIndentField; - } - } - /// - /// Current transformation session - /// - public virtual global::System.Collections.Generic.IDictionary Session - { - get - { - return this.sessionField; - } - set - { - this.sessionField = value; - } - } - #endregion - #region Transform-time helpers - /// - /// Write text directly into the generated output - /// - public void Write(string textToAppend) - { - if (string.IsNullOrEmpty(textToAppend)) - { - return; - } - // If we're starting off, or if the previous text ended with a newline, - // we have to append the current indent first. - if (((this.GenerationEnvironment.Length == 0) - || this.endsWithNewline)) - { - this.GenerationEnvironment.Append(this.currentIndentField); - this.endsWithNewline = false; - } - // Check if the current text ends with a newline - if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) - { - this.endsWithNewline = true; - } - // This is an optimization. If the current indent is "", then we don't have to do any - // of the more complex stuff further down. - if ((this.currentIndentField.Length == 0)) - { - this.GenerationEnvironment.Append(textToAppend); - return; - } - // Everywhere there is a newline in the text, add an indent after it - textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); - // If the text ends with a newline, then we should strip off the indent added at the very end - // because the appropriate indent will be added when the next time Write() is called - if (this.endsWithNewline) - { - this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); - } - else - { - this.GenerationEnvironment.Append(textToAppend); - } - } - /// - /// Write text directly into the generated output - /// - public void WriteLine(string textToAppend) - { - this.Write(textToAppend); - this.GenerationEnvironment.AppendLine(); - this.endsWithNewline = true; - } - /// - /// Write formatted text directly into the generated output - /// - public void Write(string format, params object[] args) - { - this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Write formatted text directly into the generated output - /// - public void WriteLine(string format, params object[] args) - { - this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); - } - /// - /// Raise an error - /// - public void Error(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - this.Errors.Add(error); - } - /// - /// Raise a warning - /// - public void Warning(string message) - { - System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); - error.ErrorText = message; - error.IsWarning = true; - this.Errors.Add(error); - } - /// - /// Increase the indent - /// - public void PushIndent(string indent) - { - if ((indent == null)) - { - throw new global::System.ArgumentNullException("indent"); - } - this.currentIndentField = (this.currentIndentField + indent); - this.indentLengths.Add(indent.Length); - } - /// - /// Remove the last indent that was added with PushIndent - /// - public string PopIndent() - { - string returnValue = ""; - if ((this.indentLengths.Count > 0)) - { - int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; - this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); - if ((indentLength > 0)) - { - returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); - this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); - } - } - return returnValue; - } - /// - /// Remove any indentation - /// - public void ClearIndent() - { - this.indentLengths.Clear(); - this.currentIndentField = ""; - } - #endregion - #region ToString Helpers - /// - /// Utility class to produce culture-oriented representation of an object as a string. - /// - public class ToStringInstanceHelper - { - private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; - /// - /// Gets or sets format provider to be used by ToStringWithCulture method. - /// - public System.IFormatProvider FormatProvider - { - get - { - return this.formatProviderField ; - } - set - { - if ((value != null)) - { - this.formatProviderField = value; - } - } - } - /// - /// This is called from the compile/run appdomain to convert objects within an expression block to a string - /// - public string ToStringWithCulture(object objectToConvert) - { - if ((objectToConvert == null)) - { - throw new global::System.ArgumentNullException("objectToConvert"); - } - System.Type t = objectToConvert.GetType(); - System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { - typeof(System.IFormatProvider)}); - if ((method == null)) - { - return objectToConvert.ToString(); - } - else - { - return ((string)(method.Invoke(objectToConvert, new object[] { - this.formatProviderField }))); - } - } - } - private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); - /// - /// Helper to produce culture-oriented representation of an object as a string - /// - public ToStringInstanceHelper ToStringHelper - { - get - { - return this.toStringHelperField; - } - } - #endregion - } - #endregion -} +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 14.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates +{ + using NJsonSchema.CodeGeneration; + using NSwag.CodeGeneration.CodeGenerators.TypeScript; + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal partial class JQueryPromisesClientTemplate : JQueryPromisesClientTemplateBase + { +#line hidden + /// + /// Create the template output + /// + public virtual string TransformText() + { + + #line 5 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.HasOperations){ + + #line default + #line hidden + + #line 6 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("export interface I"); + + #line 7 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 8 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + + #line 9 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 10 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 11 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(parameter.HasDescriptionOrIsOptional){ + + #line default + #line hidden + this.Write(" * @"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(parameter.IsOptional){ + + #line default + #line hidden + this.Write(" (optional)"); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 12 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 13 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 14 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 15 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("): "); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.PromiseType)); + + #line default + #line hidden + this.Write("<"); + + #line 16 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(">;\r\n"); + + #line 17 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 18 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\nexport class "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.GenerateClientInterfaces){ + + #line default + #line hidden + this.Write("implements I"); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.Class)); + + #line default + #line hidden + this.Write(" "); + + #line 20 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("{\r\n baseUrl: string = undefined; \r\n beforeSend: any = undefined; \r\n\r\n co" + + "nstructor(baseUrl?: string) {\r\n this.baseUrl = baseUrl !== undefined ? ba" + + "seUrl : \""); + + #line 25 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.BaseUrl)); + + #line default + #line hidden + this.Write("\"; \r\n }\r\n"); + + #line 27 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("\r\n protected transformOptions(options: any) {\r\n return options; \r\n }" + + "\r\n\r\n protected transformResult(url: string, xhr: any, processor: (xhr: any) =" + + "> any) {\r\n return processor(xhr);\r\n }\r\n"); + + #line 36 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 37 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var operation in Model.Operations){ + + #line default + #line hidden + this.Write("\r\n"); + + #line 39 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasDocumentation){ + + #line default + #line hidden + this.Write(" /**\r\n"); + + #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasSummary){ + + #line default + #line hidden + this.Write(" * "); + + #line 40 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Summary)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 41 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(parameter.HasDescriptionOrIsOptional){ + + #line default + #line hidden + this.Write(" * @"); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(parameter.IsOptional){ + + #line default + #line hidden + this.Write(" (optional)"); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 42 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Description ?? "")); + + #line default + #line hidden + this.Write("\r\n"); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasResultDescription){ + + #line default + #line hidden + this.Write(" * @return "); + + #line 43 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultDescription)); + + #line default + #line hidden + this.Write("\r\n"); + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 44 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.IsDeprecated){ + + #line default + #line hidden + this.Write(" * @deprecated\r\n"); + + #line 45 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" */\r\n"); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("("); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(!parameter.IsLast){ + + #line default + #line hidden + this.Write(", "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("): "); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.PromiseType)); + + #line default + #line hidden + this.Write("<"); + + #line 46 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write("> {\r\n return "); + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(Model.PromiseConstructor)); + + #line default + #line hidden + this.Write("<"); + + #line 47 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(">((resolve, reject) => {\r\n this."); + + #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("WithCallbacks("); + + #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(", "); + + #line 48 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("(result) => resolve(result), (exception, reason) => reject(exception));\r\n " + + "});\r\n }\r\n \r\n private "); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameLower)); + + #line default + #line hidden + this.Write("WithCallbacks("); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.Parameters){ + + #line default + #line hidden + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(": "); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Type)); + + #line default + #line hidden + this.Write(", "); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("onSuccess?: (result: "); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ResultType)); + + #line default + #line hidden + this.Write(") => void, onFail?: (exception: "); + + #line 52 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.ExceptionType)); + + #line default + #line hidden + this.Write(", reason: string) => void) {\r\n var url = this.baseUrl + \"/"); + + #line 53 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.Path)); + + #line default + #line hidden + this.Write("?\"; \r\n\r\n"); + + #line 55 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.PathParameters){ + + #line default + #line hidden + this.Write(" if ("); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 56 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 57 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n"); + + #line 58 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 59 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".map(s_ => s_.toJSON()).join())); \r\n"); + + #line 60 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 61 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON())); \r\n"); + + #line 62 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent("); + + #line 63 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".join())); \r\n"); + + #line 64 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url = url.replace(\"{"); + + #line 65 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("}\", encodeURIComponent(\"\" + "); + + #line 65 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(")); \r\n"); + + #line 66 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + + #line 67 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("\r\n"); + + #line 69 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.QueryParameters){ + + #line default + #line hidden + + #line 70 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if (parameter.IsRequired) { + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 72 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined)\r\n throw new Error(\"The parameter \'"); + + #line 73 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined.\");\r\n else\r\n"); + + #line 75 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === undefined || "); + + #line 76 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 77 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' must be defined and cannot be null.\");\r\n else\r\n"); + + #line 79 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + }else{ + if(parameter.IsNullable){ + + #line default + #line hidden + this.Write(" if ("); + + #line 82 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 83 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" if ("); + + #line 84 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" === null)\r\n throw new Error(\"The parameter \'"); + + #line 85 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write("\' cannot be null.\");\r\n else if ("); + + #line 86 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(" !== undefined)\r\n"); + + #line 87 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + } + + #line default + #line hidden + + #line 89 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(parameter.IsDateArray){ + + #line default + #line hidden + this.Write(" "); + + #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 90 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item.toJSON()) + \"&\"; });\r\n"); + + #line 91 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else if(parameter.IsDate){ + + #line default + #line hidden + this.Write(" url += \""); + + #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 92 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".toJSON()) + \"&\"; \r\n"); + + #line 93 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else if(parameter.IsArray){ + + #line default + #line hidden + this.Write(" "); + + #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(".forEach(item => { url += \""); + + #line 94 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + item) + \"&\"; });\r\n"); + + #line 95 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" url += \""); + + #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("=\" + encodeURIComponent(\"\" + "); + + #line 96 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(") + \"&\"; \r\n"); + + #line 97 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } +} + + #line default + #line hidden + this.Write("\r\n "); + + #line 100 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(RequestBodyGenerator.Render(operation.ContentParameter, 2))); + + #line default + #line hidden + this.Write("\r\n\r\n jQuery.ajax("); + + #line 102 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write("this.transformOptions("); + + #line 102 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("{\r\n url: url,\r\n beforeSend: this.beforeSend,\r\n t" + + "ype: \""); + + #line 105 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.HttpMethodLower)); + + #line default + #line hidden + this.Write("\",\r\n data: content,\r\n dataType: \"text\",\r\n header" + + "s: {\r\n"); + + #line 109 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var parameter in operation.HeaderParameters){ + + #line default + #line hidden + this.Write(" \""); + + #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name)); + + #line default + #line hidden + this.Write("\": "); + + #line 110 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(parameter.VariableNameLower)); + + #line default + #line hidden + this.Write(", \r\n"); + + #line 111 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" \"Content-Type\": \"application/json; charset=UTF-8\"\r\n }\r" + + "\n }"); + + #line 113 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(")"); + + #line 113 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(").done((data, textStatus, xhr) => {\r\n this.process"); + + #line 114 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n }).fail((xhr) => {\r\n " + + " this.process"); + + #line 116 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("WithCallbacks(url, xhr, onSuccess, onFail);\r\n });\r\n }\r\n\r\n private pr" + + "ocess"); + + #line 120 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) {\r\n tr" + + "y {\r\n"); + + #line 122 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(Model.IsExtended){ + + #line default + #line hidden + this.Write(" var result = this.transformResult(url, xhr, (xhr) => this.process"); + + #line 123 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(xhr));\r\n"); + + #line 124 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +}else{ + + #line default + #line hidden + this.Write(" var result = this.process"); + + #line 125 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(xhr);\r\n"); + + #line 126 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" if (onSuccess !== undefined)\r\n onSuccess(result);\r\n " + + " } catch (e) {\r\n if (onFail !== undefined)\r\n onFai" + + "l(e, \"http_service_exception\");\r\n }\r\n }\r\n\r\n private process"); + + #line 135 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.OperationNameUpper)); + + #line default + #line hidden + this.Write("(xhr: any) {\r\n var data = xhr.responseText; \r\n var status = xhr.sta" + + "tus.toString(); \r\n\r\n"); + + #line 139 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +foreach(var response in operation.Responses){ + + #line default + #line hidden + this.Write(" if (status === \""); + + #line 140 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write("\") {\r\n"); + + #line 141 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(response.HasType){ + + #line default + #line hidden + this.Write(" var result"); + + #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(": "); + + #line 142 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + + "\n"); + + #line 144 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(response.IsDate){ + + #line default + #line hidden + this.Write(" result"); + + #line 145 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = new Date(data);\r\n"); + + #line 146 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 147 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(response.IsFile){ + + #line default + #line hidden + this.Write(" result"); + + #line 148 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data;\r\n"); + + #line 149 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 150 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(response.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData"); + + #line 151 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : jQuery.parseJSON(data);\r\n "); + + #line 152 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(response.DataConversionCode, 4))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 153 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result"); + + #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(" = data === \"\" ? null : <"); + + #line 154 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.Type)); + + #line default + #line hidden + this.Write(">jQuery.parseJSON(data);\r\n"); + + #line 155 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + + #line 156 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + } + + #line default + #line hidden + this.Write(" }\r\n"); + + #line 159 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" var result"); + + #line 160 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(": any = undefined; \r\n"); + + #line 161 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + + #line 162 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(response.IsSuccess){ + + #line default + #line hidden + this.Write(" return result"); + + #line 163 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(";\r\n"); + + #line 164 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" throw result"); + + #line 165 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(response.StatusCode)); + + #line default + #line hidden + this.Write(";\r\n"); + + #line 166 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + this.Write(" }\r\n else\r\n"); + + #line 169 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" {\r\n"); + + #line 171 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +if(operation.HasDefaultResponse){ + + #line default + #line hidden + + #line 172 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(operation.DefaultResponse.HasType){ + + #line default + #line hidden + this.Write(" var result: "); + + #line 173 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(" = null; \r\n if (data !== undefined && data !== null && data !== \"\") {\r" + + "\n"); + + #line 175 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(operation.DefaultResponse.IsDate){ + + #line default + #line hidden + this.Write(" result = new Date(data);\r\n"); + + #line 177 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 178 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(operation.DefaultResponse.IsFile){ + + #line default + #line hidden + this.Write(" result = data;\r\n"); + + #line 180 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + + #line 181 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(operation.DefaultResponse.UseDtoClass){ + + #line default + #line hidden + this.Write(" var resultData = data === \"\" ? null : jQuery.parseJSON(data);\r\n " + + " "); + + #line 183 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4))); + + #line default + #line hidden + this.Write("\r\n"); + + #line 184 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" result = data === \"\" ? null : <"); + + #line 185 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(operation.DefaultResponse.Type)); + + #line default + #line hidden + this.Write(">jQuery.parseJSON(data);\r\n"); + + #line 186 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + + #line 187 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + + #line 188 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + this.Write(" }\r\n"); + + #line 190 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" var result: any = undefined; \r\n"); + + #line 192 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } + + #line default + #line hidden + this.Write("\r\n"); + + #line 194 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + if(operation.HasOnlyDefaultResponse){ + + #line default + #line hidden + this.Write(" if (status.length === 3 && status.indexOf(\"2\") === 0)\r\n " + + " return result;\r\n else\r\n throw result;\r\n"); + + #line 199 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + }else{ + + #line default + #line hidden + this.Write(" return result; \r\n"); + + #line 201 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" + } +}else{ + + #line default + #line hidden + this.Write(" throw new Error(\"error_no_callback_for_the_received_http_status\");\r\n"); + + #line 204 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write(" }\r\n }\r\n"); + + #line 207 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + this.Write("}\r\n"); + + #line 208 "C:\Data\Projects\NSwag\src\NSwag.CodeGeneration\CodeGenerators\TypeScript\Templates\JQueryPromisesClientTemplate.tt" +} + + #line default + #line hidden + return this.GenerationEnvironment.ToString(); + } + } + + #line default + #line hidden + #region Base class + /// + /// Base class for this transformation + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] + internal class JQueryPromisesClientTemplateBase + { + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + protected System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion + } + #endregion +} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.tt b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.tt similarity index 97% rename from src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.tt rename to src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.tt index 691ef803df..d49e5fe708 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.tt +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesClientTemplate.tt @@ -1,208 +1,208 @@ -<#@ template visibility="internal" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="NJsonSchema.CodeGeneration" #> -<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> -<#if(Model.HasOperations){#> -<#if(Model.GenerateClientInterfaces){#> -export interface I<#=Model.Class#> { -<#foreach(var operation in Model.Operations){#> -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): <#=Model.PromiseType#><<#=operation.ResultType#>>; -<#}#>} -<#}#> - -export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ - baseUrl: string = undefined; - beforeSend: any = undefined; - - constructor(baseUrl?: string) { - this.baseUrl = baseUrl !== undefined ? baseUrl : "<#=Model.BaseUrl#>"; - } -<#if(Model.IsExtended){#> - - protected transformOptions(options: any) { - return options; - } - - protected transformResult(url: string, xhr: any, processor: (xhr: any) => any) { - return processor(xhr); - } -<#}#> -<#foreach(var operation in Model.Operations){#> - -<#if(operation.HasDocumentation){#> /** -<#if(operation.HasSummary){#> * <#=operation.Summary#> -<#}#><#foreach(var parameter in operation.Parameters){#> -<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> -<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> -<#}#><#if(operation.IsDeprecated){#> * @deprecated -<#}#> */ -<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): <#=Model.PromiseType#><<#=operation.ResultType#>> { - return <#=Model.PromiseConstructor#><<#=operation.ResultType#>>((resolve, reject) => { - this.<#=operation.OperationNameLower#>WithCallbacks(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>, <#}#>(result) => resolve(result), (exception, reason) => reject(exception)); - }); - } - - private <#=operation.OperationNameLower#>WithCallbacks(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#>, <#}#>onSuccess?: (result: <#=operation.ResultType#>) => void, onFail?: (exception: <#=operation.ExceptionType#>, reason: string) => void) { - var url = this.baseUrl + "/<#=operation.Path#>?"; - -<#foreach(var parameter in operation.PathParameters){#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); -<# if(parameter.IsDateArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); -<# }else if(parameter.IsDate){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); -<# }else if(parameter.IsArray){#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); -<# }else{#> - url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); -<# }#> -<#}#> - -<#foreach(var parameter in operation.QueryParameters){#> -<# if (parameter.IsRequired) { - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> === undefined) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); - else -<# }else{#> - if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); - else -<# } - }else{ - if(parameter.IsNullable){#> - if (<#=parameter.VariableNameLower#> !== undefined) -<# }else{#> - if (<#=parameter.VariableNameLower#> === null) - throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); - else if (<#=parameter.VariableNameLower#> !== undefined) -<# } - }#> -<# if(parameter.IsDateArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); -<# }else if(parameter.IsDate){#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; -<# }else if(parameter.IsArray){#> - <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); -<# }else{#> - url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; -<# } -}#> - - <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> - - jQuery.ajax(<#if(Model.IsExtended){#>this.transformOptions(<#}#>{ - url: url, - beforeSend: this.beforeSend, - type: "<#=operation.HttpMethodLower#>", - data: content, - dataType: "text", - headers: { -<#foreach(var parameter in operation.HeaderParameters){#> - "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, -<#}#> "Content-Type": "application/json; charset=UTF-8" - } - }<#if(Model.IsExtended){#>)<#}#>).done((data, textStatus, xhr) => { - this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); - }).fail((xhr) => { - this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); - }); - } - - private process<#=operation.OperationNameUpper#>WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) { - try { -<#if(Model.IsExtended){#> - var result = this.transformResult(url, xhr, (xhr) => this.process<#=operation.OperationNameUpper#>(xhr)); -<#}else{#> - var result = this.process<#=operation.OperationNameUpper#>(xhr); -<#}#> - if (onSuccess !== undefined) - onSuccess(result); - } catch (e) { - if (onFail !== undefined) - onFail(e, "http_service_exception"); - } - } - - private process<#=operation.OperationNameUpper#>(xhr: any) { - var data = xhr.responseText; - var status = xhr.status.toString(); - -<#foreach(var response in operation.Responses){#> - if (status === "<#=response.StatusCode#>") { -<# if(response.HasType){#> - var result<#=response.StatusCode#>: <#=response.Type#> = null; - if (data !== undefined && data !== null && data !== "") { -<# if(response.IsDate){#> - result<#=response.StatusCode#> = new Date(data); -<# }else{#> -<# if(response.IsFile){#> - result<#=response.StatusCode#> = data; -<# }else{#> -<# if(response.UseDtoClass){#> - var resultData<#=response.StatusCode#> = data === "" ? null : jQuery.parseJSON(data); - <#=ConversionUtilities.Tab(response.DataConversionCode, 4)#> -<# }else{#> - result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>jQuery.parseJSON(data); -<# }#> -<# } - }#> - } -<# }else{#> - var result<#=response.StatusCode#>: any = undefined; -<# }#> -<# if(response.IsSuccess){#> - return result<#=response.StatusCode#>; -<# }else{#> - throw result<#=response.StatusCode#>; -<# }#> - } - else -<#}#> - { -<#if(operation.HasDefaultResponse){#> -<# if(operation.DefaultResponse.HasType){#> - var result: <#=operation.DefaultResponse.Type#> = null; - if (data !== undefined && data !== null && data !== "") { -<# if(operation.DefaultResponse.IsDate){#> - result = new Date(data); -<# }else{#> -<# if(operation.DefaultResponse.IsFile){#> - result = data; -<# }else{#> -<# if(operation.DefaultResponse.UseDtoClass){#> - var resultData = data === "" ? null : jQuery.parseJSON(data); - <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4)#> -<# }else{#> - result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>jQuery.parseJSON(data); -<# }#> -<# }#> -<# }#> - } -<# }else{#> - var result: any = undefined; -<# }#> - -<# if(operation.HasOnlyDefaultResponse){#> - if (status.length === 3 && status.indexOf("2") === 0) - return result; - else - throw result; -<# }else{#> - return result; -<# } -}else{#> - throw new Error("error_no_callback_for_the_received_http_status"); -<#}#> - } - } -<#}#>} +<#@ template visibility="internal" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="NJsonSchema.CodeGeneration" #> +<#@ import namespace="NSwag.CodeGeneration.CodeGenerators.TypeScript" #> +<#if(Model.HasOperations){#> +<#if(Model.GenerateClientInterfaces){#> +export interface I<#=Model.Class#> { +<#foreach(var operation in Model.Operations){#> +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): <#=Model.PromiseType#><<#=operation.ResultType#>>; +<#}#>} +<#}#> + +export class <#=Model.Class#> <#if(Model.GenerateClientInterfaces){#>implements I<#=Model.Class#> <#}#>{ + baseUrl: string = undefined; + beforeSend: any = undefined; + + constructor(baseUrl?: string) { + this.baseUrl = baseUrl !== undefined ? baseUrl : "<#=Model.BaseUrl#>"; + } +<#if(Model.IsExtended){#> + + protected transformOptions(options: any) { + return options; + } + + protected transformResult(url: string, xhr: any, processor: (xhr: any) => any) { + return processor(xhr); + } +<#}#> +<#foreach(var operation in Model.Operations){#> + +<#if(operation.HasDocumentation){#> /** +<#if(operation.HasSummary){#> * <#=operation.Summary#> +<#}#><#foreach(var parameter in operation.Parameters){#> +<#if(parameter.HasDescriptionOrIsOptional){#> * @<#=parameter.VariableNameLower#><#if(parameter.IsOptional){#> (optional)<#}#> <#=parameter.Description ?? ""#> +<#}#><#}#><#if(operation.HasResultDescription){#> * @return <#=operation.ResultDescription#> +<#}#><#if(operation.IsDeprecated){#> * @deprecated +<#}#> */ +<#}#> <#=operation.OperationNameLower#>(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#><#if(!parameter.IsLast){#>, <#}#><#}#>): <#=Model.PromiseType#><<#=operation.ResultType#>> { + return <#=Model.PromiseConstructor#><<#=operation.ResultType#>>((resolve, reject) => { + this.<#=operation.OperationNameLower#>WithCallbacks(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>, <#}#>(result) => resolve(result), (exception, reason) => reject(exception)); + }); + } + + private <#=operation.OperationNameLower#>WithCallbacks(<#foreach(var parameter in operation.Parameters){#><#=parameter.VariableNameLower#>: <#=parameter.Type#>, <#}#>onSuccess?: (result: <#=operation.ResultType#>) => void, onFail?: (exception: <#=operation.ExceptionType#>, reason: string) => void) { + var url = this.baseUrl + "/<#=operation.Path#>?"; + +<#foreach(var parameter in operation.PathParameters){#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); +<# if(parameter.IsDateArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.map(s_ => s_.toJSON()).join())); +<# }else if(parameter.IsDate){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON())); +<# }else if(parameter.IsArray){#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent(<#=parameter.VariableNameLower#>.join())); +<# }else{#> + url = url.replace("{<#=parameter.Name#>}", encodeURIComponent("" + <#=parameter.VariableNameLower#>)); +<# }#> +<#}#> + +<#foreach(var parameter in operation.QueryParameters){#> +<# if (parameter.IsRequired) { + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> === undefined) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined."); + else +<# }else{#> + if (<#=parameter.VariableNameLower#> === undefined || <#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' must be defined and cannot be null."); + else +<# } + }else{ + if(parameter.IsNullable){#> + if (<#=parameter.VariableNameLower#> !== undefined) +<# }else{#> + if (<#=parameter.VariableNameLower#> === null) + throw new Error("The parameter '<#=parameter.VariableNameLower#>' cannot be null."); + else if (<#=parameter.VariableNameLower#> !== undefined) +<# } + }#> +<# if(parameter.IsDateArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item.toJSON()) + "&"; }); +<# }else if(parameter.IsDate){#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>.toJSON()) + "&"; +<# }else if(parameter.IsArray){#> + <#=parameter.VariableNameLower#>.forEach(item => { url += "<#=parameter.Name#>=" + encodeURIComponent("" + item) + "&"; }); +<# }else{#> + url += "<#=parameter.Name#>=" + encodeURIComponent("" + <#=parameter.VariableNameLower#>) + "&"; +<# } +}#> + + <#=RequestBodyGenerator.Render(operation.ContentParameter, 2)#> + + jQuery.ajax(<#if(Model.IsExtended){#>this.transformOptions(<#}#>{ + url: url, + beforeSend: this.beforeSend, + type: "<#=operation.HttpMethodLower#>", + data: content, + dataType: "text", + headers: { +<#foreach(var parameter in operation.HeaderParameters){#> + "<#=parameter.Name#>": <#=parameter.VariableNameLower#>, +<#}#> "Content-Type": "application/json; charset=UTF-8" + } + }<#if(Model.IsExtended){#>)<#}#>).done((data, textStatus, xhr) => { + this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); + }).fail((xhr) => { + this.process<#=operation.OperationNameUpper#>WithCallbacks(url, xhr, onSuccess, onFail); + }); + } + + private process<#=operation.OperationNameUpper#>WithCallbacks(url: string, xhr: any, onSuccess?: any, onFail?: any) { + try { +<#if(Model.IsExtended){#> + var result = this.transformResult(url, xhr, (xhr) => this.process<#=operation.OperationNameUpper#>(xhr)); +<#}else{#> + var result = this.process<#=operation.OperationNameUpper#>(xhr); +<#}#> + if (onSuccess !== undefined) + onSuccess(result); + } catch (e) { + if (onFail !== undefined) + onFail(e, "http_service_exception"); + } + } + + private process<#=operation.OperationNameUpper#>(xhr: any) { + var data = xhr.responseText; + var status = xhr.status.toString(); + +<#foreach(var response in operation.Responses){#> + if (status === "<#=response.StatusCode#>") { +<# if(response.HasType){#> + var result<#=response.StatusCode#>: <#=response.Type#> = null; + if (data !== undefined && data !== null && data !== "") { +<# if(response.IsDate){#> + result<#=response.StatusCode#> = new Date(data); +<# }else{#> +<# if(response.IsFile){#> + result<#=response.StatusCode#> = data; +<# }else{#> +<# if(response.UseDtoClass){#> + var resultData<#=response.StatusCode#> = data === "" ? null : jQuery.parseJSON(data); + <#=ConversionUtilities.Tab(response.DataConversionCode, 4)#> +<# }else{#> + result<#=response.StatusCode#> = data === "" ? null : <<#=response.Type#>>jQuery.parseJSON(data); +<# }#> +<# } + }#> + } +<# }else{#> + var result<#=response.StatusCode#>: any = undefined; +<# }#> +<# if(response.IsSuccess){#> + return result<#=response.StatusCode#>; +<# }else{#> + throw result<#=response.StatusCode#>; +<# }#> + } + else +<#}#> + { +<#if(operation.HasDefaultResponse){#> +<# if(operation.DefaultResponse.HasType){#> + var result: <#=operation.DefaultResponse.Type#> = null; + if (data !== undefined && data !== null && data !== "") { +<# if(operation.DefaultResponse.IsDate){#> + result = new Date(data); +<# }else{#> +<# if(operation.DefaultResponse.IsFile){#> + result = data; +<# }else{#> +<# if(operation.DefaultResponse.UseDtoClass){#> + var resultData = data === "" ? null : jQuery.parseJSON(data); + <#=ConversionUtilities.Tab(operation.DefaultResponse.DataConversionCode, 4)#> +<# }else{#> + result = data === "" ? null : <<#=operation.DefaultResponse.Type#>>jQuery.parseJSON(data); +<# }#> +<# }#> +<# }#> + } +<# }else{#> + var result: any = undefined; +<# }#> + +<# if(operation.HasOnlyDefaultResponse){#> + if (status.length === 3 && status.indexOf("2") === 0) + return result; + else + throw result; +<# }else{#> + return result; +<# } +}else{#> + throw new Error("error_no_callback_for_the_received_http_status"); +<#}#> + } + } +<#}#>} <#}#> \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.Extensions.cs deleted file mode 100644 index d7e1ccdd50..0000000000 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromisesTemplate.Extensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using NJsonSchema.CodeGeneration; -using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models; - -namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates -{ - internal partial class JQueryPromisesTemplate : ITemplate - { - public ClientTemplateModel Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) - { - Model = (ClientTemplateModel) model; - } - - /// Renders the template. - /// The output. - public string Render() - { - return ConversionUtilities.TrimWhiteSpaces(TransformText()); - } - } -} diff --git a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/RequestBodyTemplate.Extensions.cs b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/RequestBodyTemplate.Extensions.cs index bd32d8e73f..db5ab16a89 100644 --- a/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/RequestBodyTemplate.Extensions.cs +++ b/src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/RequestBodyTemplate.Extensions.cs @@ -5,17 +5,13 @@ namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates { internal partial class RequestBodyTemplate : ITemplate { - public ParameterModel Model { get; set; } - - /// Initializes the template with a model. - /// The model. - public void Initialize(object model) + public RequestBodyTemplate(ParameterModel model) { - Model = (ParameterModel)model; + Model = model; } - /// Renders the template. - /// The output. + public ParameterModel Model { get; } + public string Render() { return ConversionUtilities.TrimWhiteSpaces(TransformText()); diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 850f603690..95dd5f5b5c 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -40,14 +40,6 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.3.3.6061.16591\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll - True - - - ..\packages\NJsonSchema.CodeGeneration.3.3.6061.16591\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.CodeGeneration.dll - True - @@ -74,12 +66,12 @@ FileTemplate.tt - + True True - WebApiControllerTemplate.tt + ControllerTemplate.tt - + @@ -94,17 +86,17 @@ - - + + True True - Angular2Template.tt + Angular2ClientTemplate.tt - - + + True True - AngularJSTemplate.tt + AngularJSClientTemplate.tt True @@ -112,17 +104,17 @@ FileTemplate.tt - - + + True True - JQueryCallbacksTemplate.tt + JQueryCallbacksClientTemplate.tt - - + + True True - JQueryPromisesTemplate.tt + JQueryPromisesClientTemplate.tt @@ -154,6 +146,14 @@ + + {8A463FA0-DAAF-483C-813E-AE9C6153CBF7} + NJsonSchema.CodeGeneration + + + {7B7A2E32-E808-4A19-98B1-37E766580F8C} + NJsonSchema + {2E6174AA-FC75-4821-9E86-51B30568BEC0} NSwag.Core @@ -171,29 +171,29 @@ TextTemplatingFilePreprocessor FileTemplate.cs - + TextTemplatingFilePreprocessor - WebApiControllerTemplate.cs + ControllerTemplate1.cs - + TextTemplatingFilePreprocessor - Angular2Template1.cs + Angular2ClientTemplate.cs - + TextTemplatingFilePreprocessor - AngularJSTemplate1.cs + AngularJSClientTemplate.cs TextTemplatingFilePreprocessor FileTemplate.cs - + TextTemplatingFilePreprocessor - JQueryCallbacksTemplate1.cs + JQueryCallbacksClientTemplate.cs - + TextTemplatingFilePreprocessor - JQueryPromisesTemplate.cs + JQueryPromisesClientTemplate.cs diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 40a4ca8666..1a0efe207d 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -46,10 +46,6 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.3.3.6061.16591\lib\portable45-net45+win8+wp8+wpa81\NJsonSchema.dll - True - @@ -93,6 +89,12 @@ + + + {7B7A2E32-E808-4A19-98B1-37E766580F8C} + NJsonSchema + +