From e40c792e27342efad55b9c90e36a8968978a0e22 Mon Sep 17 00:00:00 2001 From: Phil Haack Date: Sun, 21 Feb 2021 13:11:51 -0800 Subject: [PATCH] Change Payload to a Dictionary (#2303) When serializing the `NewDeployment` type, the `Payload` is serialized as an escaped string because JSON.NET doesn't know it's meant to be JSON. This causes a problem when you call the API because the Payload is supposed to be a JSON dictionary that's just part of the overall payload. It's not supposed to be an escaped string. That's why the JSON deserializer fails on it. Not only that, any deployments created using the current Octokit.net will create an invalid payload. This PR fixes it by changing the type of `Payload` to a dictionary. THIS IS A BREAKING CHANGE, but the old behavior was broken so it forces a new correct behavior. Fixes #2250 --- Octokit.Tests/Models/DeploymentTests.cs | 12 ++++++++++++ Octokit/Models/Request/NewDeployment.cs | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Models/DeploymentTests.cs b/Octokit.Tests/Models/DeploymentTests.cs index d60c9b11..dab6b668 100644 --- a/Octokit.Tests/Models/DeploymentTests.cs +++ b/Octokit.Tests/Models/DeploymentTests.cs @@ -8,6 +8,18 @@ namespace Octokit.Tests.Models { public class DeploymentTests { + [Fact] + public void CanSerialize() + { + var deployment = new NewDeployment("ref") + { + Payload = new Dictionary {{"environment", "production"}} + }; + var deserialized = new SimpleJsonSerializer().Serialize(deployment); + + Assert.Equal(@"{""ref"":""ref"",""task"":""deploy"",""payload"":{""environment"":""production""}}", deserialized); + } + [Fact] public void CanDeserialize() { diff --git a/Octokit/Models/Request/NewDeployment.cs b/Octokit/Models/Request/NewDeployment.cs index b844ceff..7fdf30d4 100644 --- a/Octokit/Models/Request/NewDeployment.cs +++ b/Octokit/Models/Request/NewDeployment.cs @@ -1,4 +1,5 @@ -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -59,7 +60,7 @@ namespace Octokit /// /// JSON payload with extra information about the deployment. /// - public string Payload { get; set; } + public Dictionary Payload { get; set; } /// /// Optional name for the target deployment environment (e.g., production, staging, qa). Default: "production"