diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs index 12989d1f..c31aef9f 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -8,6 +9,7 @@ public class SelectOptionSchema public string Name { get; set; } [JsonProperty("color")] - public string Color { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 145a37e5..e6711de5 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index f995e3be..d694e33c 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -18,6 +19,10 @@ public class Info [JsonProperty("icon")] public IPageIcon Icon { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/Color.cs b/Src/Notion.Client/Models/Blocks/Color.cs new file mode 100644 index 00000000..b4682a7b --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Color.cs @@ -0,0 +1,64 @@ +using System.Runtime.Serialization; + +namespace Notion.Client +{ + public enum Color + { + [EnumMember(Value = "default")] + Default, + + [EnumMember(Value = "gray")] + Gray, + + [EnumMember(Value = "brown")] + Brown, + + [EnumMember(Value = "orange")] + Orange, + + [EnumMember(Value = "yellow")] + Yellow, + + [EnumMember(Value = "green")] + Green, + + [EnumMember(Value = "blue")] + Blue, + + [EnumMember(Value = "purple")] + Purple, + + [EnumMember(Value = "pink")] + Pink, + + [EnumMember(Value = "red")] + Red, + + [EnumMember(Value = "gray_background")] + GrayBackground, + + [EnumMember(Value = "brown_background")] + BrownBackground, + + [EnumMember(Value = "orange_background")] + OrangeBackground, + + [EnumMember(Value = "yellow_background")] + YellowBackground, + + [EnumMember(Value = "green_background")] + GreenBackground, + + [EnumMember(Value = "blue_background")] + BlueBackground, + + [EnumMember(Value = "purple_background")] + PurpleBackground, + + [EnumMember(Value = "pink_background")] + PinkBackground, + + [EnumMember(Value = "red_background")] + RedBackground, + } +} diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 67132fe5..ccf29220 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -16,6 +17,10 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 2e4dde99..73897da0 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -16,6 +17,10 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index 82c75047..7b4e161e 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -16,6 +17,10 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 581d8977..189eedf1 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 02560aee..f45e8628 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 9a8dda8e..68479075 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 49e11bf4..29305ca9 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -11,6 +12,9 @@ public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Data { + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 0417827d..d2fcc75e 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -18,6 +19,10 @@ public class Info [JsonProperty("checked")] public bool IsChecked { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 2653cd1b..1367f40b 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 47e6fa64..dd1dfeb1 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -33,7 +34,8 @@ public class SelectOption /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". /// [JsonProperty("color")] - public string Color { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } public class MultiSelectProperty : Property diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 1c9a7610..0b509325 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -42,7 +42,7 @@ public class Annotations public bool IsCode { get; set; } [JsonProperty("color")] - // color: Color | BackgroundColor - public string Color { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index b87fdd5e..a3254131 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -214,17 +214,17 @@ public async Task CreateDatabaseAsync() { new SelectOptionSchema { - Color = "green", + Color = Color.Green, Name = "🥦Vegetable" }, new SelectOptionSchema { - Color = "red", + Color = Color.Red, Name = "🍎Fruit" }, new SelectOptionSchema { - Color = "yellow", + Color = Color.Yellow, Name = "💪Protein" } } @@ -248,17 +248,17 @@ public async Task CreateDatabaseAsync() option => { option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be("green"); + option.Color.Should().Be(Color.Green); }, option => { option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be("red"); + option.Color.Should().Be(Color.Red); }, option => { option.Name.Should().Be("💪Protein"); - option.Color.Should().Be("yellow"); + option.Color.Should().Be(Color.Yellow); } ); } @@ -303,17 +303,17 @@ public async Task UpdateDatabaseAsync() { new SelectOption { - Color = "green", + Color = Color.Green, Name = "🥦Vegetables" }, new SelectOption { - Color = "red", + Color = Color.Red, Name = "🍎Fruit" }, new SelectOption { - Color = "yellow", + Color = Color.Yellow, Name = "💪Protein" } } @@ -346,17 +346,17 @@ public async Task UpdateDatabaseAsync() option => { option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be("green"); + option.Color.Should().Be(Color.Green); }, option => { option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be("red"); + option.Color.Should().Be(Color.Red); }, option => { option.Name.Should().Be("💪Protein"); - option.Color.Should().Be("yellow"); + option.Color.Should().Be(Color.Yellow); } );

AltStyle によって変換されたページ (->オリジナル) /