Skip to content

Commit 2ca1c64

Browse files
Merge pull request #225 from notion-dotnet/223-remove-enum-types-used-in-response-models
Remove enum types used in response models
2 parents 55dc049 + 3eaf5c8 commit 2ca1c64

File tree

5 files changed

+20
-201
lines changed

5 files changed

+20
-201
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Converters;
32

43
namespace Notion.Client
54
{
@@ -9,7 +8,6 @@ public class SelectOptionSchema
98
public string Name { get; set; }
109

1110
[JsonProperty("color")]
12-
[JsonConverter(typeof(StringEnumConverter))]
13-
public Color Color { get; set; }
11+
public string Color { get; set; }
1412
}
1513
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Runtime.Serialization;
2-
using Newtonsoft.Json;
3-
using Newtonsoft.Json.Converters;
1+
using Newtonsoft.Json;
42

53
namespace Notion.Client
64
{
@@ -15,106 +13,6 @@ public class NumberProperty : Property
1513
public class Number
1614
{
1715
[JsonProperty("format")]
18-
[JsonConverter(typeof(StringEnumConverter))]
19-
public NumberFormat Format { get; set; }
20-
}
21-
22-
public enum NumberFormat
23-
{
24-
[EnumMember(Value = null)]
25-
Unknown,
26-
27-
[EnumMember(Value = "number")]
28-
Number,
29-
30-
[EnumMember(Value = "number_with_commas")]
31-
NumberWithCommas,
32-
33-
[EnumMember(Value = "percent")]
34-
Percent,
35-
36-
[EnumMember(Value = "dollar")]
37-
Dollar,
38-
39-
[EnumMember(Value = "euro")]
40-
Euro,
41-
42-
[EnumMember(Value = "pound")]
43-
Pound,
44-
45-
[EnumMember(Value = "yen")]
46-
Yen,
47-
48-
[EnumMember(Value = "ruble")]
49-
Ruble,
50-
51-
[EnumMember(Value = "rupee")]
52-
Rupee,
53-
54-
[EnumMember(Value = "won")]
55-
Won,
56-
57-
[EnumMember(Value = "yuan")]
58-
Yuan,
59-
60-
[EnumMember(Value = "hong_kong_dollar")]
61-
HongKongDollar,
62-
63-
[EnumMember(Value = "new_zealand_dollar")]
64-
NewZealandDollar,
65-
66-
[EnumMember(Value = "krona")]
67-
Krona,
68-
69-
[EnumMember(Value = "norwegian_krone")]
70-
NorwegianKrone,
71-
72-
[EnumMember(Value = "mexican_peso")]
73-
MexicanPeso,
74-
75-
[EnumMember(Value = "rand")]
76-
Rand,
77-
78-
[EnumMember(Value = "new_taiwan_dollar")]
79-
NewTaiwanDollar,
80-
81-
[EnumMember(Value = "danish_krone")]
82-
DanishKrone,
83-
84-
[EnumMember(Value = "zloty")]
85-
Zloty,
86-
87-
[EnumMember(Value = "baht")]
88-
Baht,
89-
90-
[EnumMember(Value = "forint")]
91-
Forint,
92-
93-
[EnumMember(Value = "koruna")]
94-
Koruna,
95-
96-
[EnumMember(Value = "shekel")]
97-
Shekel,
98-
99-
[EnumMember(Value = "chilean_peso")]
100-
ChileanPeso,
101-
102-
[EnumMember(Value = "philippine_peso")]
103-
PhilippinePeso,
104-
105-
[EnumMember(Value = "dirham")]
106-
Dirham,
107-
108-
[EnumMember(Value = "colombian_peso")]
109-
ColombianPeso,
110-
111-
[EnumMember(Value = "riyal")]
112-
Riyal,
113-
114-
[EnumMember(Value = "ringgit")]
115-
Ringgit,
116-
117-
[EnumMember(Value = "leu")]
118-
Leu
16+
public string Format { get; set; }
11917
}
12018
}

Src/Notion.Client/Models/Database/Properties/SelectProperty.cs

+1-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Collections.Generic;
2-
using System.Runtime.Serialization;
32
using Newtonsoft.Json;
4-
using Newtonsoft.Json.Converters;
53

64
namespace Notion.Client
75
{
@@ -35,44 +33,7 @@ public class SelectOption
3533
/// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default".
3634
/// </summary>
3735
[JsonProperty("color")]
38-
[JsonConverter(typeof(StringEnumConverter))]
39-
public Color? Color { get; set; }
40-
}
41-
42-
public enum Color
43-
{
44-
[EnumMember(Value = null)]
45-
Unknown,
46-
47-
[EnumMember(Value = "default")]
48-
Default,
49-
50-
[EnumMember(Value = "gray")]
51-
Gray,
52-
53-
[EnumMember(Value = "brown")]
54-
Brown,
55-
56-
[EnumMember(Value = "orange")]
57-
Orange,
58-
59-
[EnumMember(Value = "yellow")]
60-
Yellow,
61-
62-
[EnumMember(Value = "green")]
63-
Green,
64-
65-
[EnumMember(Value = "blue")]
66-
Blue,
67-
68-
[EnumMember(Value = "purple")]
69-
Purple,
70-
71-
[EnumMember(Value = "pink")]
72-
Pink,
73-
74-
[EnumMember(Value = "red")]
75-
Red
36+
public string Color { get; set; }
7637
}
7738

7839
public class MultiSelectProperty : Property

Test/Notion.UnitTests/DatabasesClientTests.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public async Task CreateDatabaseAsync()
203203
createDatabaseParameters.Properties = new Dictionary<string, IPropertySchema>
204204
{
205205
{ "Name", new TitlePropertySchema { Title = new Dictionary<string, object>() } },
206-
{ "Price", new NumberPropertySchema { Number = new Number { Format = NumberFormat.Dollar } } },
206+
{ "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } },
207207
{ "Food group", new SelectPropertySchema
208208
{
209209
Select = new OptionWrapper<SelectOptionSchema>
@@ -212,17 +212,17 @@ public async Task CreateDatabaseAsync()
212212
{
213213
new SelectOptionSchema
214214
{
215-
Color = Color.Green,
215+
Color = "green",
216216
Name = "🥦Vegetable"
217217
},
218218
new SelectOptionSchema
219219
{
220-
Color = Color.Red,
220+
Color = "red",
221221
Name = "🍎Fruit"
222222
},
223223
new SelectOptionSchema
224224
{
225-
Color = Color.Yellow,
225+
Color = "yellow",
226226
Name = "💪Protein"
227227
}
228228
}
@@ -246,17 +246,17 @@ public async Task CreateDatabaseAsync()
246246
option =>
247247
{
248248
option.Name.Should().Be("🥦Vegetable");
249-
option.Color.Should().Be(Color.Green);
249+
option.Color.Should().Be("green");
250250
},
251251
option =>
252252
{
253253
option.Name.Should().Be("🍎Fruit");
254-
option.Color.Should().Be(Color.Red);
254+
option.Color.Should().Be("red");
255255
},
256256
option =>
257257
{
258258
option.Name.Should().Be("💪Protein");
259-
option.Color.Should().Be(Color.Yellow);
259+
option.Color.Should().Be("yellow");
260260
}
261261
);
262262
}
@@ -292,7 +292,7 @@ public async Task UpdateDatabaseAsync()
292292
updateDatabaseParameters.Properties = new Dictionary<string, IUpdatePropertySchema>
293293
{
294294
{ "Name", new TitleUpdatePropertySchema { Title = new Dictionary<string, object>() } },
295-
{ "Price", new NumberUpdatePropertySchema { Number = new Number { Format = NumberFormat.Yen } } },
295+
{ "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } },
296296
{ "Food group", new SelectUpdatePropertySchema
297297
{
298298
Select = new OptionWrapper<SelectOption>
@@ -301,17 +301,17 @@ public async Task UpdateDatabaseAsync()
301301
{
302302
new SelectOption
303303
{
304-
Color = Color.Green,
304+
Color = "green",
305305
Name = "🥦Vegetables"
306306
},
307307
new SelectOption
308308
{
309-
Color = Color.Red,
309+
Color = "red",
310310
Name = "🍎Fruit"
311311
},
312312
new SelectOption
313313
{
314-
Color = Color.Yellow,
314+
Color = "yellow",
315315
Name = "💪Protein"
316316
}
317317
}
@@ -344,22 +344,22 @@ public async Task UpdateDatabaseAsync()
344344
option =>
345345
{
346346
option.Name.Should().Be("🥦Vegetables");
347-
option.Color.Should().Be(Color.Green);
347+
option.Color.Should().Be("green");
348348
},
349349
option =>
350350
{
351351
option.Name.Should().Be("🍎Fruit");
352-
option.Color.Should().Be(Color.Red);
352+
option.Color.Should().Be("red");
353353
},
354354
option =>
355355
{
356356
option.Name.Should().Be("💪Protein");
357-
option.Color.Should().Be(Color.Yellow);
357+
option.Color.Should().Be("yellow");
358358
}
359359
);
360360

361361
var price = (NumberProperty)database.Properties["Price"];
362-
price.Number.Format.Should().Be(NumberFormat.Yen);
362+
price.Number.Format.Should().Be("yen");
363363
}
364364

365365
[Fact]
@@ -398,7 +398,7 @@ public async Task FormulaPropertyCanBeSetWhenCreatingDatabase()
398398
createDatabaseParameters.Properties = new Dictionary<string, IPropertySchema>
399399
{
400400
{ "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } },
401-
{ "Price", new NumberPropertySchema { Number = new Number { Format = NumberFormat.Dollar } } }
401+
{ "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }
402402
};
403403

404404
var database = await _client.CreateAsync(createDatabaseParameters);

Test/Notion.UnitTests/PropertyTests.cs

-38
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,5 @@ public void TestPropertyTypeText(Type type, string expectedPropertyType)
6363

6464
Assert.Equal(expectedPropertyType, actualPropertyType);
6565
}
66-
67-
[Theory]
68-
[InlineData(null, NumberFormat.Unknown)]
69-
[InlineData("number", NumberFormat.Number)]
70-
[InlineData("number_with_commas", NumberFormat.NumberWithCommas)]
71-
[InlineData("percent", NumberFormat.Percent)]
72-
[InlineData("dollar", NumberFormat.Dollar)]
73-
[InlineData("euro", NumberFormat.Euro)]
74-
[InlineData("pound", NumberFormat.Pound)]
75-
[InlineData("yen", NumberFormat.Yen)]
76-
[InlineData("ruble", NumberFormat.Ruble)]
77-
[InlineData("rupee", NumberFormat.Rupee)]
78-
[InlineData("won", NumberFormat.Won)]
79-
[InlineData("yuan", NumberFormat.Yuan)]
80-
[InlineData("hong_kong_dollar", NumberFormat.HongKongDollar)]
81-
[InlineData("new_zealand_dollar", NumberFormat.NewZealandDollar)]
82-
[InlineData("krona", NumberFormat.Krona)]
83-
[InlineData("norwegian_krone", NumberFormat.NorwegianKrone)]
84-
[InlineData("mexican_peso", NumberFormat.MexicanPeso)]
85-
[InlineData("rand", NumberFormat.Rand)]
86-
[InlineData("new_taiwan_dollar", NumberFormat.NewTaiwanDollar)]
87-
[InlineData("danish_krone", NumberFormat.DanishKrone)]
88-
[InlineData("zloty", NumberFormat.Zloty)]
89-
[InlineData("baht", NumberFormat.Baht)]
90-
[InlineData("forint", NumberFormat.Forint)]
91-
[InlineData("koruna", NumberFormat.Koruna)]
92-
[InlineData("shekel", NumberFormat.Shekel)]
93-
[InlineData("chilean_peso", NumberFormat.ChileanPeso)]
94-
[InlineData("philippine_peso", NumberFormat.PhilippinePeso)]
95-
[InlineData("dirham", NumberFormat.Dirham)]
96-
[InlineData("colombian_peso", NumberFormat.ColombianPeso)]
97-
[InlineData("riyal", NumberFormat.Riyal)]
98-
[InlineData("ringgit", NumberFormat.Ringgit)]
99-
[InlineData("leu", NumberFormat.Leu)]
100-
public void NumberFormatEnumTypes(string textValue, NumberFormat numberFormat)
101-
{
102-
numberFormat.GetEnumMemberValue().Should().Be(textValue);
103-
}
10466
}
10567
}

0 commit comments

Comments
 (0)