Closed Hoopie closed 3 years ago
I'm running into this too. Definitely looks like a bug. The question is does the GitHub API do anything with the Payload
property? Or is that just round tripped by the API and ignored by GitHub. If it's ignored by GitHub, maybe the safest change is to change the type of Payload
to string
on Deployment
.
Otherwise it might make sense to change Payload
on NewDeployment
to be a dictionary so things round trip properly.
Actually, probably needs to be a string since the Payload field can be created by other clients. I know the ruby client just lets you set that as a string. In order to be able to use this client to load deployments created by other clients, we can't assume they put it in a format deserializable to a dictionary.
Ah, changing it to a string probably won't help. The issue is that the serializer doesn't know that NewDeployment.Payload
is supposed to be a JSON string. So when it serializes it, it escapes it.
[Fact]
public void CanSerialize()
{
var deployment = new NewDeployment("ref")
{
Payload = @"{ ""environment"":""production""}"
};
var deserialized = new SimpleJsonSerializer().Serialize(deployment);
Assert.Equal(@"{""ref"":""ref"",""task"":""deploy"",""payload"":""{ \""environment\"":\""production\""}""}", deserialized);
}
That's why it can't round trip it. I wonder if there's a way to tell JSON.NET to treat that property as raw JSON and don't encode it.
Ok, after digging into the code, I forgot that Octokit.net uses a simple serializer that doesn't embed type info. So I think the easy fix is to change NewDeployment.Payload
to Dictionary<string, string>
. It's a breaking change, but probably worth it considering that any deployments created prior are kind of broken.
As per the documentation the
deployment.payload
is intended to accept json. Octokit.net hasNewDeployment.Payload
as string.When creating a new deployment with a json serialized string in
Payload
the request is accepted and the deployment is created. However, it fails with anInvalidCastException
when attempting return theDeployment
response model.On closer inspection it appears to be an issue with the Deployment response model expecting to be able to cast to a
IReadOnlyDictionary<string,string>
yet the NewDeployment request model accepts a string. See https://github.com/octokit/octokit.net/blob/main/Octokit/Models/Response/Deployment.cs#L60 and https://github.com/octokit/octokit.net/blob/main/Octokit/Models/Request/NewDeployment.cs#L62Here is some of my sandbox code I used that raised the error. This is using Octokit 0.48.0
I get the following error
Of note, i also tried creating a NewDeployment serializing a
Dictionary<string,string>
to payload but got the same result. Deployment was created on github but Octokit failed with a cast exception.When calling github directly via curl I can see my deployment object created as expected. Note payload is a string and not json.
Is this a bug or am i over thinking it?