Added ability to specify a RouteResponse and RouteRequest as a dynamic. Improved documentation and fixed some null checks that were missing with this change. Bumped package version to 1.7.6
This commit is contained in:
		| @@ -211,7 +211,7 @@ namespace MontoyaTech.Rest.Net.Example | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         [RouteGroup("Auth")] |         [RouteGroup("Auth")] | ||||||
|         [RouteResponse(typeof(JObject))] |         [RouteResponse(Dynamic = true)] | ||||||
|         public static HttpListenerResponse Dynamic(HttpListenerContext context) |         public static HttpListenerResponse Dynamic(HttpListenerContext context) | ||||||
|         { |         { | ||||||
|             return context.Response.WithStatus(HttpStatusCode.OK).WithJson(777); |             return context.Response.WithStatus(HttpStatusCode.OK).WithJson(777); | ||||||
|   | |||||||
| @@ -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.7.5</Version> |     <Version>1.7.6</Version> | ||||||
|     <PackageReleaseNotes></PackageReleaseNotes> |     <PackageReleaseNotes></PackageReleaseNotes> | ||||||
|     <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon> |     <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   | |||||||
| @@ -378,9 +378,9 @@ namespace MontoyaTech.Rest.Net | |||||||
|  |  | ||||||
|             //Generate the route function header |             //Generate the route function header | ||||||
|             if (this.StaticCode) |             if (this.StaticCode) | ||||||
|                 writer.Write($"public static {(routeResponse == null ? "void" : this.GetTypeFullyResolvedName(routeResponse.ResponseType))} {(routeName == null ? methodInfo.Name : routeName.Name)}("); |                 writer.Write($"public static {(routeResponse == null ? "void" : (routeResponse.Dynamic ? "dynamic" : this.GetTypeFullyResolvedName(routeResponse.ResponseType)))} {(routeName == null ? methodInfo.Name : routeName.Name)}("); | ||||||
|             else |             else | ||||||
|                 writer.Write($"public {(routeResponse == null ? "void" : this.GetTypeFullyResolvedName(routeResponse.ResponseType))} {(routeName == null ? methodInfo.Name : routeName.Name)}("); |                 writer.Write($"public {(routeResponse == null ? "void" : (routeResponse.Dynamic ? "dynamic" : this.GetTypeFullyResolvedName(routeResponse.ResponseType)))} {(routeName == null ? methodInfo.Name : routeName.Name)}("); | ||||||
|  |  | ||||||
|             //Generate the functions parameters |             //Generate the functions parameters | ||||||
|             var parameters = methodInfo.GetParameters(); |             var parameters = methodInfo.GetParameters(); | ||||||
| @@ -397,13 +397,25 @@ namespace MontoyaTech.Rest.Net | |||||||
|             if (routeRequest != null) |             if (routeRequest != null) | ||||||
|             { |             { | ||||||
|                 writer.WriteSeparator(); |                 writer.WriteSeparator(); | ||||||
|                 writer.Write(this.GetTypeFullyResolvedName(routeRequest.RequestType)).Write(" request"); |  | ||||||
|  |                 if (routeRequest.Dynamic) | ||||||
|  |                     writer.Write("dynamic"); | ||||||
|  |                 else | ||||||
|  |                     writer.Write(this.GetTypeFullyResolvedName(routeRequest.RequestType)); | ||||||
|  |  | ||||||
|  |                 writer.Write(" request"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (routeResponse != null && routeResponse.Parameter) |             if (routeResponse != null && routeResponse.Parameter) | ||||||
|             { |             { | ||||||
|                 writer.WriteSeparator(); |                 writer.WriteSeparator(); | ||||||
|                 writer.Write(this.GetTypeFullyResolvedName(routeResponse.ResponseType)).Write(" input"); |  | ||||||
|  |                 if (routeResponse.Dynamic) | ||||||
|  |                     writer.Write("dynamic"); | ||||||
|  |                 else | ||||||
|  |                     writer.Write(this.GetTypeFullyResolvedName(routeResponse.ResponseType)); | ||||||
|  |  | ||||||
|  |                 writer.Write(" input"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             writer.WriteLine(")").WriteLine("{").Indent(); |             writer.WriteLine(")").WriteLine("{").Indent(); | ||||||
| @@ -507,7 +519,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|             { |             { | ||||||
|                 writer.WriteBreak().WriteLine("if (response.IsSuccessStatusCode)").WriteLine("{").Indent(); |                 writer.WriteBreak().WriteLine("if (response.IsSuccessStatusCode)").WriteLine("{").Indent(); | ||||||
|  |  | ||||||
|                 if (routeResponse.ResponseType.IsAssignableTo(typeof(Stream))) |                 if (routeResponse.ResponseType != null && routeResponse.ResponseType.IsAssignableTo(typeof(Stream))) | ||||||
|                 { |                 { | ||||||
|                     if (routeResponse.Parameter) |                     if (routeResponse.Parameter) | ||||||
|                     { |                     { | ||||||
| @@ -532,7 +544,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|  |  | ||||||
|                     if (routeResponse.Json) |                     if (routeResponse.Json) | ||||||
|                     { |                     { | ||||||
|                         writer.WriteBreak().WriteLine($"return JsonConvert.DeserializeObject<{this.GetTypeFullyResolvedName(routeResponse.ResponseType)}>(content);"); |                         writer.WriteBreak().WriteLine($"return JsonConvert.DeserializeObject<{(routeResponse.Dynamic ? "dynamic" : this.GetTypeFullyResolvedName(routeResponse.ResponseType))}>(content);"); | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|                     { |                     { | ||||||
| @@ -599,7 +611,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|                                 break; |                                 break; | ||||||
|  |  | ||||||
|                             case TypeCode.Object: |                             case TypeCode.Object: | ||||||
|                                 throw new NotSupportedException("ResponseType isn't JSON but is an object."); |                                 throw new NotSupportedException("RouteResponse has JSON=false but ResponseType is an object."); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -166,7 +166,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|  |  | ||||||
|                 var routeRequest = methodInfo.GetCustomAttribute<RouteRequest>(); |                 var routeRequest = methodInfo.GetCustomAttribute<RouteRequest>(); | ||||||
|  |  | ||||||
|                 if (routeRequest != null) |                 if (routeRequest != null && routeRequest.RequestType != null) | ||||||
|                 { |                 { | ||||||
|                     var types = this.FindTypeDependencies(routeRequest.RequestType); |                     var types = this.FindTypeDependencies(routeRequest.RequestType); | ||||||
|  |  | ||||||
| @@ -177,7 +177,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|  |  | ||||||
|                 var routeResponse = methodInfo.GetCustomAttribute<RouteResponse>(); |                 var routeResponse = methodInfo.GetCustomAttribute<RouteResponse>(); | ||||||
|  |  | ||||||
|                 if (routeResponse != null) |                 if (routeResponse != null && routeResponse.ResponseType != null) | ||||||
|                 { |                 { | ||||||
|                     var types = this.FindTypeDependencies(routeResponse.ResponseType); |                     var types = this.FindTypeDependencies(routeResponse.ResponseType); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -496,11 +496,11 @@ namespace MontoyaTech.Rest.Net | |||||||
|  |  | ||||||
|             //Generate request doc if any |             //Generate request doc if any | ||||||
|             if (routeRequest != null) |             if (routeRequest != null) | ||||||
|                 writer.WriteLine($"@param {{{this.GetTypeFullyResolvedName(routeRequest.RequestType)}}} request"); |                 writer.WriteLine($"@param {{{(routeRequest.Dynamic ? "Any" : this.GetTypeFullyResolvedName(routeRequest.RequestType))}}} request"); | ||||||
|  |  | ||||||
|             //Generate response doc if any |             //Generate response doc if any | ||||||
|             if (routeResponse != null) |             if (routeResponse != null) | ||||||
|                 writer.WriteLine($"@returns {{{this.GetTypeFullyResolvedName(routeResponse.ResponseType)}}}"); |                 writer.WriteLine($"@returns {{{(routeResponse.Dynamic ? "Any" : this.GetTypeFullyResolvedName(routeResponse.ResponseType))}}}"); | ||||||
|  |  | ||||||
|             writer.WriteLine("@throws {Response} If response status was not ok."); |             writer.WriteLine("@throws {Response} If response status was not ok."); | ||||||
|  |  | ||||||
| @@ -610,7 +610,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|             { |             { | ||||||
|                 writer.WriteBreak().WriteLine("if (response.ok) {").Indent(); |                 writer.WriteBreak().WriteLine("if (response.ok) {").Indent(); | ||||||
|  |  | ||||||
|                 if (routeResponse.ResponseType.IsAssignableTo(typeof(Stream))) |                 if (routeResponse.ResponseType != null && routeResponse.ResponseType.IsAssignableTo(typeof(Stream))) | ||||||
|                 { |                 { | ||||||
|                     if (routeResponse.Parameter) |                     if (routeResponse.Parameter) | ||||||
|                     { |                     { | ||||||
|   | |||||||
| @@ -22,6 +22,11 @@ namespace MontoyaTech.Rest.Net | |||||||
|         /// </summary> |         /// </summary> | ||||||
|         public bool Json = true; |         public bool Json = true; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Whether or not the request is a dynamic type. Default is false. | ||||||
|  |         /// </summary> | ||||||
|  |         public bool Dynamic = false; | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a default route request. |         /// Creates a default route request. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|   | |||||||
| @@ -23,10 +23,15 @@ namespace MontoyaTech.Rest.Net | |||||||
|         public bool Json = true; |         public bool Json = true; | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Whether or not the response is passed as a parameter to the route function. |         /// Whether or not the response is passed as a parameter to the route function. Default is false. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         public bool Parameter = false; |         public bool Parameter = false; | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Whether or not the response is a dynamic type. Default is false. | ||||||
|  |         /// </summary> | ||||||
|  |         public bool Dynamic = false; | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a default route response. |         /// Creates a default route response. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user