In C#, I've noticed that the optional parameters on some method calls are unavailable in the generated libraries. For instance, with the Gmail API, trying to insert a message, there are optional query parameters of deleted and internalDateSource. However, if I attempt to use them, there is no parameter to do so. The generated method for the standard Insert (not the MediaUpload version) is:
public virtual InsertRequest Insert(Google.Apis.Gmail.v1.Data.Message body, string userId)
{
return new InsertRequest(service, body, userId);
}
So, within this generated API there is no way to set those two parameters without having the user create their own InsertRequest, which seems to defeat the purpose of the method call which returns the InsertRequest.
Upon closer inspection, it looks like within the /csharp/languages/csharp/default/templates/_method.tmpl file the only parameters being created are the requiredParameters. This seems to be by design, but I'm not sure why we wouldn't want those parameters accessible.
[Please feel free to ignore this suggestion.] The solution I've been using in my forked project is to wrap all required parameters in an optional Properties subclass (named for the method it is associated with) that is passed to any method with optional parameters. That way, no matter how many there are, your methods won't get cluttered. From there, I expand the new object being created and assign each optional parameter after the constructor, so that would look like:
public virtual InsertRequest Insert(Google.Apis.Gmail.v1.Data.Message body, string userId, Google.Apis.Gmail.v1.Data.Message.InsertParameters parameters = null)
{
if (null == parameters) parameters = new Google.Apis.Gmail.v1.Data.Message.InsertParameters();
return new InsertRequest(service, body, userId)
{
Deleted = parameters.Deleted,
InternalDateSource = parameters.InternalDateSource,
};
}
I'm not sure how well that solution would fit in to other languages, or if it would be necessary, but I figured I'd offer that. :)
In C#, I've noticed that the optional parameters on some method calls are unavailable in the generated libraries. For instance, with the Gmail API, trying to insert a message, there are optional query parameters of deleted and internalDateSource. However, if I attempt to use them, there is no parameter to do so. The generated method for the standard Insert (not the MediaUpload version) is:
So, within this generated API there is no way to set those two parameters without having the user create their own InsertRequest, which seems to defeat the purpose of the method call which returns the InsertRequest.
Upon closer inspection, it looks like within the /csharp/languages/csharp/default/templates/_method.tmpl file the only parameters being created are the requiredParameters. This seems to be by design, but I'm not sure why we wouldn't want those parameters accessible.
[Please feel free to ignore this suggestion.] The solution I've been using in my forked project is to wrap all required parameters in an optional Properties subclass (named for the method it is associated with) that is passed to any method with optional parameters. That way, no matter how many there are, your methods won't get cluttered. From there, I expand the new object being created and assign each optional parameter after the constructor, so that would look like:
I'm not sure how well that solution would fit in to other languages, or if it would be necessary, but I figured I'd offer that. :)