#312 better (generated) comments for args that will serialized to JSON
This commit is contained in:
parent
51578717e0
commit
09c6d6c60f
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
|
@ -8,18 +8,18 @@ namespace Flurl.Http.CodeGen
|
||||
public static IEnumerable<HttpExtensionMethod> GetAll() {
|
||||
return
|
||||
from httpVerb in new[] { null, "Get", "Post", "Head", "Put", "Delete", "Patch", "Options" }
|
||||
from bodyType in new[] { null, "Json", /*"Xml",*/ "String", "UrlEncoded" }
|
||||
from reqType in new[] { null, "Json", /*"Xml",*/ "String", "UrlEncoded" }
|
||||
from extensionType in new[] { "IFlurlRequest", "Url", "string" }
|
||||
where SupportedCombo(httpVerb, bodyType, extensionType)
|
||||
from deserializeType in new[] { null, "Json", "JsonList", /*"Xml",*/ "String", "Stream", "Bytes" }
|
||||
where httpVerb == "Get" || deserializeType == null
|
||||
where SupportedCombo(httpVerb, reqType, extensionType)
|
||||
from respType in new[] { null, "Json", "JsonList", /*"Xml",*/ "String", "Stream", "Bytes" }
|
||||
where httpVerb == "Get" || respType == null
|
||||
from isGeneric in new[] { true, false }
|
||||
where AllowDeserializeToGeneric(deserializeType) || !isGeneric
|
||||
where AllowDeserializeToGeneric(respType) || !isGeneric
|
||||
select new HttpExtensionMethod {
|
||||
HttpVerb = httpVerb,
|
||||
BodyType = bodyType,
|
||||
RequestBodyType = reqType,
|
||||
ExtentionOfType = extensionType,
|
||||
DeserializeToType = deserializeType,
|
||||
ResponseBodyType = respType,
|
||||
IsGeneric = isGeneric
|
||||
};
|
||||
}
|
||||
@ -48,16 +48,16 @@ namespace Flurl.Http.CodeGen
|
||||
}
|
||||
|
||||
public string HttpVerb { get; set; }
|
||||
public string BodyType { get; set; }
|
||||
public string RequestBodyType { get; set; }
|
||||
public string ExtentionOfType { get; set; }
|
||||
public string DeserializeToType { get; set; }
|
||||
public string ResponseBodyType { get; set; }
|
||||
public bool IsGeneric { get; set; }
|
||||
|
||||
public string Name => $"{HttpVerb ?? "Send"}{BodyType ?? DeserializeToType}Async";
|
||||
public string Name => $"{HttpVerb ?? "Send"}{RequestBodyType ?? ResponseBodyType}Async";
|
||||
|
||||
public string TaskArg {
|
||||
get {
|
||||
switch (DeserializeToType) {
|
||||
switch (ResponseBodyType) {
|
||||
case "Json": return IsGeneric ? "T" : "dynamic";
|
||||
case "JsonList": return "IList<dynamic>";
|
||||
//case "Xml": return ?;
|
||||
@ -72,7 +72,7 @@ namespace Flurl.Http.CodeGen
|
||||
public string ReturnTypeDescription {
|
||||
get {
|
||||
//var response = (xm.DeserializeToType == null) ? "" : "" + xm.TaskArg;
|
||||
switch (DeserializeToType) {
|
||||
switch (ResponseBodyType) {
|
||||
case "Json": return "the JSON response body deserialized to " + (IsGeneric ? "an object of type T" : "a dynamic");
|
||||
case "JsonList": return "the JSON response body deserialized to a list of dynamics";
|
||||
//case "Xml": return ?;
|
||||
|
@ -8,7 +8,7 @@ namespace Flurl.Http.CodeGen
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args) {
|
||||
var codePath = (args.Length > 0) ? args[0] : @"..\Flurl.Http\GeneratedExtensions.cs";
|
||||
var codePath = (args.Length > 0) ? args[0] : @"..\..\..\..\Flurl.Http\GeneratedExtensions.cs";
|
||||
|
||||
if (!File.Exists(codePath)) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
@ -82,10 +82,14 @@ namespace Flurl.Http.CodeGen
|
||||
writer.WriteLine("/// <param name=\"url\">The URL.</param>");
|
||||
if (xm.HttpVerb == null)
|
||||
writer.WriteLine("/// <param name=\"verb\">The HTTP method used to make the request.</param>");
|
||||
if (xm.BodyType != null)
|
||||
if (hasRequestBody) {
|
||||
if (xm.RequestBodyType == "Json")
|
||||
writer.WriteLine("/// <param name=\"data\">An object representing the request body, which will be serialized to JSON.</param>");
|
||||
else if (xm.RequestBodyType != null)
|
||||
writer.WriteLine("/// <param name=\"data\">Contents of the request body.</param>");
|
||||
else if (hasRequestBody)
|
||||
else
|
||||
writer.WriteLine("/// <param name=\"content\">Contents of the request body.</param>");
|
||||
}
|
||||
writer.WriteLine("/// <param name=\"cancellationToken\">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>");
|
||||
writer.WriteLine("/// <param name=\"completionOption\">The HttpCompletionOption used in the request. Optional.</param>");
|
||||
writer.WriteLine("/// <returns>A Task whose result is @0.</returns>", xm.ReturnTypeDescription);
|
||||
@ -94,8 +98,8 @@ namespace Flurl.Http.CodeGen
|
||||
args.Add("this " + xm.ExtentionOfType + (xm.ExtentionOfType == "IFlurlRequest" ? " request" : " url"));
|
||||
if (xm.HttpVerb == null)
|
||||
args.Add("HttpMethod verb");
|
||||
if (xm.BodyType != null)
|
||||
args.Add((xm.BodyType == "String" ? "string" : "object") + " data");
|
||||
if (xm.RequestBodyType != null)
|
||||
args.Add((xm.RequestBodyType == "String" ? "string" : "object") + " data");
|
||||
else if (hasRequestBody)
|
||||
args.Add("HttpContent content");
|
||||
|
||||
@ -113,20 +117,20 @@ namespace Flurl.Http.CodeGen
|
||||
xm.HttpVerb == "Patch" ? "new HttpMethod(\"PATCH\")" : // there's no HttpMethod.Patch
|
||||
"HttpMethod." + xm.HttpVerb);
|
||||
|
||||
if (xm.BodyType != null || hasRequestBody)
|
||||
if (xm.RequestBodyType != null || hasRequestBody)
|
||||
args.Add("content: content");
|
||||
|
||||
args.Add("cancellationToken: cancellationToken");
|
||||
args.Add("completionOption: completionOption");
|
||||
|
||||
if (xm.BodyType != null) {
|
||||
if (xm.RequestBodyType != null) {
|
||||
writer.WriteLine("var content = new Captured@0Content(@1);",
|
||||
xm.BodyType,
|
||||
xm.BodyType == "String" ? "data" : $"request.Settings.{xm.BodyType}Serializer.Serialize(data)");
|
||||
xm.RequestBodyType,
|
||||
xm.RequestBodyType == "String" ? "data" : $"request.Settings.{xm.RequestBodyType}Serializer.Serialize(data)");
|
||||
}
|
||||
|
||||
var request = (xm.ExtentionOfType == "IFlurlRequest") ? "request" : "new FlurlRequest(url)";
|
||||
var receive = (xm.DeserializeToType == null) ? "" : string.Format(".Receive{0}{1}()", xm.DeserializeToType, xm.IsGeneric ? "<T>" : "");
|
||||
var receive = (xm.ResponseBodyType == null) ? "" : string.Format(".Receive{0}{1}()", xm.ResponseBodyType, xm.IsGeneric ? "<T>" : "");
|
||||
writer.WriteLine("return @0.SendAsync(@1)@2;", request, string.Join(", ", args), receive);
|
||||
}
|
||||
else
|
||||
|
@ -47,7 +47,7 @@ namespace Flurl.Http
|
||||
/// </summary>
|
||||
/// <param name="request">The IFlurlRequest instance.</param>
|
||||
/// <param name="verb">The HTTP method used to make the request.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -61,7 +61,7 @@ namespace Flurl.Http
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="verb">The HTTP method used to make the request.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -74,7 +74,7 @@ namespace Flurl.Http
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="verb">The HTTP method used to make the request.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -433,7 +433,7 @@ namespace Flurl.Http
|
||||
/// Sends an asynchronous POST request.
|
||||
/// </summary>
|
||||
/// <param name="request">The IFlurlRequest instance.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -446,7 +446,7 @@ namespace Flurl.Http
|
||||
/// Creates a FlurlRequest from the URL and sends an asynchronous POST request.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -458,7 +458,7 @@ namespace Flurl.Http
|
||||
/// Creates a FlurlRequest from the URL and sends an asynchronous POST request.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -613,7 +613,7 @@ namespace Flurl.Http
|
||||
/// Sends an asynchronous PUT request.
|
||||
/// </summary>
|
||||
/// <param name="request">The IFlurlRequest instance.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -626,7 +626,7 @@ namespace Flurl.Http
|
||||
/// Creates a FlurlRequest from the URL and sends an asynchronous PUT request.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -638,7 +638,7 @@ namespace Flurl.Http
|
||||
/// Creates a FlurlRequest from the URL and sends an asynchronous PUT request.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -756,7 +756,7 @@ namespace Flurl.Http
|
||||
/// Sends an asynchronous PATCH request.
|
||||
/// </summary>
|
||||
/// <param name="request">The IFlurlRequest instance.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -769,7 +769,7 @@ namespace Flurl.Http
|
||||
/// Creates a FlurlRequest from the URL and sends an asynchronous PATCH request.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
@ -781,7 +781,7 @@ namespace Flurl.Http
|
||||
/// Creates a FlurlRequest from the URL and sends an asynchronous PATCH request.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="data">Contents of the request body.</param>
|
||||
/// <param name="data">An object representing the request body, which will be serialized to JSON.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
|
||||
/// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
|
||||
/// <returns>A Task whose result is the received HttpResponseMessage.</returns>
|
||||
|
Loading…
x
Reference in New Issue
Block a user