8000 fix: could not deserialize unique_id by RandomUser14 · Pull Request #367 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

fix: could not deserialize unique_id #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/Database/Properties/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdProperty), PropertyType.UniqueId)]
public class Property
{
[JsonProperty("id")]
Expand Down
5 changes: 4 additions & 1 deletion Src/Notion.Client/Models/Database/Properties/PropertyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public enum PropertyType
LastEditedTime,

[EnumMember(Value = "status")]
Status
Status,

[EnumMember(Value = "unique_id")]
UniqueId,
}
}
15 changes: 15 additions & 0 deletions Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class UniqueIdProperty : Property
{
public override PropertyType Type => PropertyType.UniqueId;

[JsonProperty("unique_id")]
public Dictionary<string, object> UniqueId { get; set; }
}
}

1 change: 1 addition & 0 deletions Src/Notion.Client/Models/PropertyValue/PropertyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)]
[JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
public class PropertyValue
Expand Down
5 changes: 4 additions & 1 deletion Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public enum PropertyValueType
LastEditedBy,

[EnumMember(Value = "status")]
Status
Status,

[EnumMember(Value = "unique_id")]
UniqueId,
}
}
29 changes: 29 additions & 0 deletions Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Newtonsoft.Json;

namespace Notion.Client
{
/// <summary>
/// Unique Id property value object.
/// </summary>
public class UniqueIdPropertyValue : PropertyValue
{
public override PropertyValueType Type => PropertyValueType.UniqueId;

/// <summary>
/// Unique Id property of database item
/// </summary>
[JsonProperty("unique_id")]
public UniqueIdValue UniqueId { get; set; }
}

public class UniqueIdValue
{
[JsonProperty("prefix")]
public string Prefix { get; set; }

[JsonProperty("number")]
public double? Number { get; set; }
}
}

2 changes: 2 additions & 0 deletions Test/Notion.UnitTests/PropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PropertyTests
[InlineData(typeof(SelectProperty), PropertyType.Select)]
[InlineData(typeof(TitleProperty), PropertyType.Title)]
[InlineData(typeof(UrlProperty), PropertyType.Url)]
[InlineData(typeof(UniqueIdProperty), PropertyType.UniqueId)]
public void TestPropertyType(Type type, PropertyType expectedPropertyType)
{
var typeInstance = (Property)Activator.CreateInstance(type);
Expand Down Expand Up @@ -54,6 +55,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType)
[InlineData(typeof(SelectProperty), "select")]
[InlineData(typeof(TitleProperty), "title")]
[InlineData(typeof(UrlProperty), "url")]
[InlineData(typeof(UniqueIdProperty), "unique_id")]
public void TestPropertyTypeText(Type type, string expectedPropertyType)
{
var typeInstance = (Property)Activator.CreateInstance(type);
Expand Down
0