Skip to content

Commit

Permalink
[Client SDK] Add package deprecation (loic-sharma#471)
Browse files Browse the repository at this point in the history
Addresses loic-sharma#395
  • Loading branch information
loic-sharma authored Feb 14, 2020
1 parent 15b2060 commit 89da76b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/BaGet.Protocol/Models/AlternatePackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace BaGet.Protocol.Models
{
/// <summary>
/// The alternate package that should be used instead of a deprecated package.
///
/// See https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#package-deprecation
/// </summary>
public class AlternatePackage
{
[JsonProperty("@id")]
public string Url { get; set; }

[JsonProperty("@type")]
public string Type { get; set; }

/// <summary>
/// The ID of the alternate package.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// The allowed version range, or * if any version is allowed.
/// </summary>
[JsonProperty("range")]
public string Range { get; set; }
}
}
38 changes: 38 additions & 0 deletions src/BaGet.Protocol/Models/PackageDeprecation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace BaGet.Protocol.Models
{
/// <summary>
/// A package's metadata.
///
/// See https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#package-deprecation
/// </summary>
public class PackageDeprecation
{
/// <summary>
/// The URL to the document used to produce this object.
/// </summary>
[JsonProperty("@id")]
public string CatalogLeafUrl { get; set; }

/// <summary>
/// The reasons why the package was deprecated.
/// Deprecation reasons include: "Legacy", "CriticalBugs", and "Other".
/// </summary>
[JsonProperty("reasons")]
public IReadOnlyList<string> Reasons { get; set; }

/// <summary>
/// The additional details about this deprecation.
/// </summary>
[JsonProperty("message")]
public string Message { get; set; }

/// <summary>
/// The alternate package that should be used instead.
/// </summary>
[JsonProperty("alternatePackage")]
public AlternatePackage AlternatePackage { get; set; }
}
}
18 changes: 12 additions & 6 deletions src/BaGet.Protocol/Models/PackageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public class PackageMetadata
[JsonProperty("authors")]
public string Authors { get; set; }

/// <summary>
/// The dependencies of the package, grouped by target framework.
/// </summary>
[JsonProperty("dependencyGroups")]
public IReadOnlyList<DependencyGroupItem> DependencyGroups { get; set; }

/// <summary>
/// The deprecation associated with the package, if any.
/// </summary>
[JsonProperty("deprecation")]
public PackageDeprecation Deprecation { get; set; }

/// <summary>
/// The package's description.
/// </summary>
Expand Down Expand Up @@ -113,11 +125,5 @@ public class PackageMetadata
/// </summary>
[JsonProperty("title")]
public string Title { get; set; }

/// <summary>
/// The dependencies of the package, grouped by target framework.
/// </summary>
[JsonProperty("dependencyGroups")]
public IReadOnlyList<DependencyGroupItem> DependencyGroups { get; set; }
}
}
7 changes: 7 additions & 0 deletions tests/BaGet.Protocol.Tests/RawPackageMetadataClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public async Task GetRegistrationPage()
Assert.Equal("2.0.0+build", firstMetadata.Version);
}

[Fact]
public async Task GetRegistrationPageDeprecated()
{
// TODO
await Task.Yield();
}

[Fact]
public async Task GetsRegistrationLeaf()
{
Expand Down

0 comments on commit 89da76b

Please sign in to comment.