Fixed a csharp client generator bug. The csharp client generator now outputs a constructor for types that allows setting property/fields. Bumped package version to 1.5.7

This commit is contained in:
2023-05-29 06:47:52 -07:00
parent 755a2399e4
commit a630f0e334
5 changed files with 104 additions and 16 deletions

View File

@ -1,3 +1,4 @@
//Generated using MontoyaTech.Rest.Net
using System;
using System.Net;
using System.Net.Http;
@ -48,7 +49,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/status");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -69,7 +70,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Post, $"{StaticClient.BaseUrl}/add/{a}/{b}");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -90,7 +91,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/compress");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -111,7 +112,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/file/compress");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -135,7 +136,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth/{name}");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -158,7 +159,7 @@ public class StaticClient
message.Content = new StringContent(JsonConvert.SerializeObject(request));
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
@ -168,7 +169,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -189,7 +190,7 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth/role");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -217,7 +218,7 @@ public class StaticClient
message.Content = new StreamContent(request);
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
@ -227,15 +228,13 @@ public class StaticClient
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/download");
var response = StaticClient.HttpClient.Send(message);
var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var stream = new System.IO.MemoryStream();
response.Content.ReadAsStream().CopyTo(stream);
stream.Seek(0, System.IO.SeekOrigin.Begin);
response.Content.CopyToAsync(stream).GetAwaiter().GetResult();
return stream;
}
@ -249,6 +248,18 @@ public class StaticClient
public class IncludedType
{
public int Test;
public IncludedType() { }
public IncludedType(IncludedType instance)
{
this.Test = instance.Test;
}
public IncludedType(int Test = 0)
{
this.Test = Test;
}
}
public class UserDto : BaseUser
@ -259,23 +270,79 @@ public class StaticClient
public System.Collections.Generic.List<string> List;
public System.String[] Array;
public ulong Property { get; set; }
public UserDto() { }
public UserDto(UserDto instance)
{
this.MachineType = instance.MachineType;
this.Name = instance.Name;
this.List = instance.List;
this.Array = instance.Array;
this.Property = instance.Property;
}
public UserDto(System.PlatformID MachineType = 0, string Name = null, System.Collections.Generic.List<string> List = null, System.String[] Array = null, ulong Property = 0)
{
this.MachineType = MachineType;
this.Name = Name;
this.List = List;
this.Array = Array;
this.Property = Property;
}
}
public class BaseUser
{
public string Id;
public char FirstInitial;
public System.Collections.Generic.List<Permission> Permissions;
public UserRole Role { get; set; }
public BaseUser() { }
public BaseUser(BaseUser instance)
{
this.Id = instance.Id;
this.FirstInitial = instance.FirstInitial;
this.Permissions = instance.Permissions;
this.Role = instance.Role;
}
public BaseUser(string Id = null, char FirstInitial = '\0', System.Collections.Generic.List<Permission> Permissions = null, UserRole Role = 0)
{
this.Id = Id;
this.FirstInitial = FirstInitial;
this.Permissions = Permissions;
this.Role = Role;
}
public class Permission
{
public string Name;
public Types Type;
public Permission() { }
public Permission(Permission instance)
{
this.Name = instance.Name;
this.Type = instance.Type;
}
public Permission(string Name = null, Types Type = 0)
{
this.Name = Name;
this.Type = Type;
}
public enum Types : int
{
Read = 0,

View File

@ -219,7 +219,7 @@ namespace MontoyaTech.Rest.Net.Example
}
[RouteGroup("Stream")]
[RouteResponse(typeof(FileStream), Parameter = true)]
[RouteResponse(typeof(MemoryStream), Parameter = false)]
public static HttpListenerResponse Download(HttpListenerContext context)
{
return context.Response.WithStatus(HttpStatusCode.OK).WithText("Hello world");