Bumped package version to 1.5.0, changed Program.cs a little of the example. Improved the Javascript Client generator by exporting all types and changing enum to behave in a more useful way.
This commit is contained in:
parent
e2c5aba868
commit
fe5fc73d14
@ -10,8 +10,6 @@ using System.Net.Mime;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace MontoyaTech.Rest.Net.Example
|
namespace MontoyaTech.Rest.Net.Example
|
||||||
{
|
|
||||||
public class Program
|
|
||||||
{
|
{
|
||||||
public class BaseUser
|
public class BaseUser
|
||||||
{
|
{
|
||||||
@ -66,6 +64,8 @@ namespace MontoyaTech.Rest.Net.Example
|
|||||||
public int Test;
|
public int Test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
public static RouteFileCache FileCache = new RouteFileCache(100 * 1024 * 1024);
|
public static RouteFileCache FileCache = new RouteFileCache(100 * 1024 * 1024);
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
@ -87,16 +87,15 @@ namespace MontoyaTech.Rest.Net.Example
|
|||||||
|
|
||||||
string code = listener.GenerateCSharpClient();
|
string code = listener.GenerateCSharpClient();
|
||||||
|
|
||||||
File.WriteAllText("Client.cs", code);
|
File.WriteAllText("Client.cs", listener.GenerateCSharpClient());
|
||||||
|
|
||||||
Console.WriteLine(code);
|
File.WriteAllText("Client.js", listener.GenerateJavascriptClient());
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
string staticCode = listener.GenerateCSharpClient("StaticClient", staticCode: true);
|
File.WriteAllText("StaticClient.cs", listener.GenerateCSharpClient("StaticClient", staticCode: true));
|
||||||
|
|
||||||
File.WriteAllText("Client.Static.cs", staticCode);
|
File.WriteAllText("StaticClient.js", listener.GenerateJavascriptClient("StaticClient", staticCode: true));
|
||||||
|
|
||||||
Console.WriteLine(staticCode);
|
Console.WriteLine("Generated Client.cs, Client.js, StaticClient.cs, StaticClient.js");
|
||||||
|
|
||||||
listener.RequestPreProcessEvent += (HttpListenerContext context) => {
|
listener.RequestPreProcessEvent += (HttpListenerContext context) => {
|
||||||
Console.WriteLine($"[{context.Request.HttpMethod}] Request start: " + context.Request.RawUrl);
|
Console.WriteLine($"[{context.Request.HttpMethod}] Request start: " + context.Request.RawUrl);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<Version>1.4.9</Version>
|
<Version>1.5.0</Version>
|
||||||
<PackageReleaseNotes></PackageReleaseNotes>
|
<PackageReleaseNotes></PackageReleaseNotes>
|
||||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -62,8 +62,12 @@ namespace MontoyaTech.Rest.Net
|
|||||||
//Create the client constructor or init method
|
//Create the client constructor or init method
|
||||||
if (this.StaticCode)
|
if (this.StaticCode)
|
||||||
{
|
{
|
||||||
writer.WriteBreak().WriteLine("/** @param {string} baseUrl */");
|
|
||||||
writer.Write("static init(baseUrl) ").WriteLine("{").Indent();
|
writer.WriteBreak().WriteLine("/**").Indent();
|
||||||
|
writer.WriteLine("Initializes the api client with a given baseUrl of where to send requests.");
|
||||||
|
writer.WriteLine("@param {string} baseUrl");
|
||||||
|
writer.Outdent().WriteLine("*/");
|
||||||
|
writer.Write("static Init(baseUrl) ").WriteLine("{").Indent();
|
||||||
|
|
||||||
//Make sure the baseUrl isn't null or whitespace
|
//Make sure the baseUrl isn't null or whitespace
|
||||||
writer.WriteBreak().WriteLine("if (baseUrl == null || baseUrl == undefined || baseUrl.trim() == '') {").Indent();
|
writer.WriteBreak().WriteLine("if (baseUrl == null || baseUrl == undefined || baseUrl.trim() == '') {").Indent();
|
||||||
@ -116,7 +120,19 @@ namespace MontoyaTech.Rest.Net
|
|||||||
|
|
||||||
writer.WriteBreak().WriteLine($"window.{this.ClientName} = {this.ClientName};");
|
writer.WriteBreak().WriteLine($"window.{this.ClientName} = {this.ClientName};");
|
||||||
|
|
||||||
writer.WriteBreak().WriteLine($"export {{ {this.ClientName} }};");
|
//Export the Client and all the Types
|
||||||
|
writer.WriteBreak().WriteLine("export {").Indent();
|
||||||
|
|
||||||
|
writer.WriteLine($"{this.ClientName},");
|
||||||
|
|
||||||
|
foreach (var type in includedTypes)
|
||||||
|
{
|
||||||
|
var newName = type.GetCustomAttribute<RouteTypeName>();
|
||||||
|
|
||||||
|
writer.WriteLine($"{(type.DeclaringType != null ? type.DeclaringType.Name : "")}{(newName != null ? newName.Name : type.Name)},");
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Outdent().WriteLine("};");
|
||||||
|
|
||||||
return writer.ToString();
|
return writer.ToString();
|
||||||
}
|
}
|
||||||
@ -170,7 +186,7 @@ namespace MontoyaTech.Rest.Net
|
|||||||
{
|
{
|
||||||
return "string";
|
return "string";
|
||||||
}
|
}
|
||||||
else if (typeCode == TypeCode.Object)
|
else if (typeCode == TypeCode.Object || type.IsEnum)
|
||||||
{
|
{
|
||||||
if (type.DeclaringType != null && !IsTypeDotNet(type.DeclaringType))
|
if (type.DeclaringType != null && !IsTypeDotNet(type.DeclaringType))
|
||||||
return $"{this.GetTypeFullyResolvedName(type.DeclaringType)}{base.GetTypeFullyResolvedName(type)}";
|
return $"{this.GetTypeFullyResolvedName(type.DeclaringType)}{base.GetTypeFullyResolvedName(type)}";
|
||||||
@ -221,6 +237,8 @@ namespace MontoyaTech.Rest.Net
|
|||||||
|
|
||||||
if (!type.IsEnum && !(IsTypeDotNet(type.BaseType) && type.BaseType.Name == "Object"))
|
if (!type.IsEnum && !(IsTypeDotNet(type.BaseType) && type.BaseType.Name == "Object"))
|
||||||
writer.Write(" extends ").Write(this.GetTypeFullyResolvedName(type.BaseType));
|
writer.Write(" extends ").Write(this.GetTypeFullyResolvedName(type.BaseType));
|
||||||
|
else if (type.IsEnum)
|
||||||
|
writer.Write(" extends Number");
|
||||||
|
|
||||||
writer.WriteLine(" {").Indent();
|
writer.WriteLine(" {").Indent();
|
||||||
|
|
||||||
@ -240,6 +258,8 @@ namespace MontoyaTech.Rest.Net
|
|||||||
this.GenerateJavascriptIncludedProperty(property, writer);
|
this.GenerateJavascriptIncludedProperty(property, writer);
|
||||||
|
|
||||||
//Generate a helper constructor
|
//Generate a helper constructor
|
||||||
|
if (!type.IsEnum)
|
||||||
|
{
|
||||||
writer.WriteBreak().WriteLine("/**").Indent();
|
writer.WriteBreak().WriteLine("/**").Indent();
|
||||||
writer.WriteLine("@method");
|
writer.WriteLine("@method");
|
||||||
|
|
||||||
@ -267,6 +287,7 @@ namespace MontoyaTech.Rest.Net
|
|||||||
writer.Write("this.").Write(property.Name).Write(" = ").Write(property.Name).WriteLine(";");
|
writer.Write("this.").Write(property.Name).Write(" = ").Write(property.Name).WriteLine(";");
|
||||||
|
|
||||||
writer.Outdent().WriteLine("}");
|
writer.Outdent().WriteLine("}");
|
||||||
|
}
|
||||||
|
|
||||||
writer.Outdent().WriteLine("}");
|
writer.Outdent().WriteLine("}");
|
||||||
|
|
||||||
@ -284,7 +305,7 @@ namespace MontoyaTech.Rest.Net
|
|||||||
|
|
||||||
if (field.DeclaringType != null && field.DeclaringType.IsEnum)
|
if (field.DeclaringType != null && field.DeclaringType.IsEnum)
|
||||||
{
|
{
|
||||||
writer.WriteLine("/** @type {number} */");
|
writer.WriteLine($"/** @type {{{GetTypeFullyResolvedName(field.DeclaringType)}}} */");
|
||||||
writer.WriteLine($"static {field.Name} = {field.GetRawConstantValue()};");
|
writer.WriteLine($"static {field.Name} = {field.GetRawConstantValue()};");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user