Skip to content

Commit

Permalink
Fix after clean-up & generating new client
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmccall committed Jan 12, 2020
1 parent c88e611 commit 3ae8d33
Show file tree
Hide file tree
Showing 13 changed files with 1,279 additions and 2,356 deletions.
52 changes: 20 additions & 32 deletions client-generator/Templates/Endpoints/FunctionEndpointTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ namespace client_generator.Templates.Endpoints
{
using System;
#line 2 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
using System.Text;
#line default
#line hidden
#line 3 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
using System.Collections.Generic;
#line default
#line hidden
#line 4 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
using System.Linq;
#line default
#line hidden
#line 5 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
using client_generator.Extensions;
#line default
#line hidden
Expand All @@ -42,34 +30,34 @@ public virtual string TransformText()

this.Write("async ");

#line 6 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 3 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_functionName));

#line default
#line hidden
this.Write("(");

#line 6 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 3 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(", ", _signature)));

#line default
#line hidden
this.Write("): Promise<");

#line 6 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 3 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_returnTypes.StrJoin(" | ")));

#line default
#line hidden
this.Write("> {\n let _url = this.baseUrl + \"");

#line 7 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 4 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_url));

#line default
#line hidden
this.Write("?\";\n let _headers: {[key: string]: string} = {} ; \n");
#line 9 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 6 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

foreach (var code in _parameterParsingCodes)
{
Expand All @@ -81,13 +69,13 @@ public virtual string TransformText()
#line hidden
this.Write(" \n ");

#line 15 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 12 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(line));

#line default
#line hidden
this.Write(" ");
#line 15 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 12 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

}
}
Expand All @@ -96,7 +84,7 @@ public virtual string TransformText()
#line default
#line hidden
this.Write(" \n _url = _url.replace(/[?&]$/, \"\");\n\n let _options = {\n");
#line 22 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 19 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

if (_haveBody)
{
Expand All @@ -105,7 +93,7 @@ public virtual string TransformText()
#line default
#line hidden
this.Write(" body: _body,\n");
#line 27 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 24 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

}

Expand All @@ -114,13 +102,13 @@ public virtual string TransformText()
#line hidden
this.Write(" method: \"");

#line 30 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 27 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_type.ToString().ToUpper()));

#line default
#line hidden
this.Write("\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Accept\": \"application/json\",\n ..._headers\n }\n };\n\n let _response = await fetch(_url, _options);\n\n");
#line 40 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 37 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

foreach (var (status, response) in _responses)
{
Expand All @@ -130,13 +118,13 @@ public virtual string TransformText()
#line hidden
this.Write(" if (_response.status === ");

#line 44 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 41 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(status));

#line default
#line hidden
this.Write(") {\n");
#line 45 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 42 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

foreach (var line in response.Split("\n"))
{
Expand All @@ -146,13 +134,13 @@ public virtual string TransformText()
#line hidden
this.Write(" ");

#line 49 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 46 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(line));

#line default
#line hidden
this.Write(" \n");
#line 50 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 47 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

}
if (status.WasSuccessful())
Expand All @@ -163,13 +151,13 @@ public virtual string TransformText()
#line hidden
this.Write(" return _data");

#line 55 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 52 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(status));

#line default
#line hidden
this.Write("; \n");
#line 56 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 53 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

}
else
Expand All @@ -180,21 +168,21 @@ public virtual string TransformText()
#line hidden
this.Write(" throw _data");

#line 61 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 58 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(status));

#line default
#line hidden
this.Write(";\n");
#line 62 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 59 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

}


#line default
#line hidden
this.Write(" }\n");
#line 66 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"
#line 63 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Endpoints/FunctionEndpointTemplate.tt"

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<#@ template language="C#" #>
<#@ im
ort namespace="client_generator.Extensions" #>
onName #>(<#= string.Join(", ", _signature) #>): Promise<<#= _returnTypes.StrJoin(" | ") #>> {
<#@ import namespace="client_generator.Extensions" #>
async <#= _functionName #>(<#= string.Join(", ", _signature) #>): Promise<<#= _returnTypes.StrJoin(" | ") #>> {
let _url = this.baseUrl + "<#= _url #>?";
let _headers: {[key: string]: string} = {} ;
<#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#@ template languag e="C#" #>
<#@ template languae="C#" #>
<#@ import namespace="client_generator.Models" #>
<#@ import namespace="client_generator.Models.Parameters" #>
<#
Expand Down
60 changes: 31 additions & 29 deletions client-generator/Templates/Schemes/ClassSchemaTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ public partial class ClassSchemaTemplate : ClassSchemaTemplateBase
public virtual string TransformText()
{

this.Write("> { \n");
this.Write("class ");

#line 4 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_name));

#line default
#line hidden
this.Write(" {\n");
#line 5 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

foreach (var (name, type) in _properties)
Expand All @@ -43,90 +50,85 @@ public virtual string TransformText()
#line hidden
this.Write(" ");

#line 9 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 8 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
#line 9 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 8 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

if (quiredProperties.Contains(name))
if (_requiredProperties.Contains(name))
{


#line default
#line hidden
this.Write("?");
#line 12 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 11 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

}

#line default
#line hidden
this.Write(": ");

#line 13 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 12 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(type.GetName()));

#line default
#line hidden
this.Write(";\n");
#line 14 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

}

#line default
#line hidden
this.Write(" \n");
#line 17 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 13 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

if (_pro perties.Any())
}

if (_properties.Any())
{


#line default
#line hidden
this.Write(" static fromResponse(data?: any): ");
this.Write("\n static fromResponse(data?: any): ");

#line 21 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 20 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_name));

#line default
#line hidden
this.Write(" {\n const _data = typeof data === 'object' ? data : {};\n const _response = new ");

#line 23 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 22 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(_name));

#line default
#line hidden
this.Write("();\n \n");
#line 25 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 24 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

foreach (var (name, type) in _properties)
{
if (ty.GetSchemaType() != SchemaType.Array)
if (type.GetSchemaType() != SchemaType.Array)
{


#line default
#line hidden
this.Write(" _response[\"");

#line 31 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 30 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
this.Write("\"] = _data[\"");

#line 31 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 30 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
this.Write("\"];\n");
#line 32 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 31 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

}
else
Expand All @@ -137,34 +139,34 @@ public virtual string TransformText()
#line hidden
this.Write(" if (Array.isArray(_data[\"");

#line 37 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 36 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
this.Write("\"])) {\n _response[\"");

#line 38 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 37 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
this.Write("\"] = [] as any;\n for (let _item of _data[\"");

#line 39 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 38 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
this.Write("\"]) {\n _response[\"");

#line 40 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 39 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(name));

#line default
#line hidden
this.Write("\"].push(_item);\n }\n }\n");
#line 43 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 42 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

}
}
Expand All @@ -173,7 +175,7 @@ public virtual string TransformText()
#line default
#line hidden
this.Write("\n return _response;\n }\n");
#line 50 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"
#line 49 "/Users/lukasz/studies/cis/CookBook/client-generator/Templates/Schemes/ClassSchemaTemplate.tt"

}

Expand Down
Loading

0 comments on commit 3ae8d33

Please sign in to comment.