Skip to content

Commit b35806f

Browse files
authored
Merge pull request #69 from candela-software/master
2 parents db87a1d + a093ce1 commit b35806f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Source/Schema.NET.Tool/ViewModels/Enumeration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public override string ToString()
2323

2424
// Using statements
2525
stringBuilder.AppendIndentLine(4, "using System.Runtime.Serialization;");
26+
stringBuilder.AppendIndentLine(4, "using Newtonsoft.Json;");
27+
stringBuilder.AppendIndentLine(4, "using Newtonsoft.Json.Converters;");
2628
stringBuilder.AppendLine();
2729

2830
// Comment
@@ -31,6 +33,7 @@ public override string ToString()
3133
stringBuilder.AppendIndentLine(4, "/// </summary>");
3234

3335
// Enum
36+
stringBuilder.AppendIndentLine(4, $"[JsonConverter(typeof(StringEnumConverter))]");
3437
stringBuilder.AppendIndentLine(4, $"public enum {this.Name}");
3538
stringBuilder.AppendIndentLine(4, "{");
3639

Source/Schema.NET/ValuesJsonConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ public virtual void WriteObject(JsonWriter writer, object value, JsonSerializer
163163

164164
private static object ParseTokenArguments(JToken token, JsonToken tokenType, Type type, object value)
165165
{
166+
const string SCHEMA_ORG = "http://schema.org/";
166167
const int SCHEMA_ORG_LENGTH = 18; // equivalent to "http://schema.org/".Length
167168
object args = null;
168169
var unwrappedType = type.GetUnderlyingTypeFromNullable();
169170
if (unwrappedType.GetTypeInfo().IsEnum)
170171
{
171-
var enumString = token.ToString().Substring(SCHEMA_ORG_LENGTH);
172+
var en = token.ToString();
173+
var enumString = en.Contains(SCHEMA_ORG) ? en.Substring(SCHEMA_ORG_LENGTH) : en;
172174
args = Enum.Parse(unwrappedType, enumString);
173175
}
174176
else

Tests/Schema.NET.Test/core/MusicAlbumTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public class MusicAlbumTest
2424
},
2525
SameAs = new Uri("https://music.apple.com/us/album/hail-to-the-thief/1097863576"), // Recommended
2626
Url = new Uri("https://open.spotify.com/album/1oW3v5Har9mvXnGk0x4fHm"), // Recommended
27+
AggregateRating = new AggregateRating() // Recommended
28+
{
29+
BestRating = 100, // Required
30+
RatingValue = 60, // Required
31+
WorstRating = 0 // Required
32+
},
2733
DatePublished = new DateTime(2003, 5, 26), // Recommended
2834
Offers = new Offer() // Recommended
2935
{
@@ -64,6 +70,13 @@ public class MusicAlbumTest
6470
"]," +
6571
"\"sameAs\": \"https://music.apple.com/us/album/hail-to-the-thief/1097863576\"," +
6672
"\"url\": \"https://open.spotify.com/album/1oW3v5Har9mvXnGk0x4fHm\"," +
73+
"\"aggregateRating\": {" +
74+
"\"@context\": \"http://schema.org\"," +
75+
"\"@type\": \"AggregateRating\"," +
76+
"\"bestRating\": 100," +
77+
"\"ratingValue\": 60," +
78+
"\"worstRating\": 0" +
79+
"}," +
6780
"\"datePublished\": \"2003-05-26\"," +
6881
"\"offers\": {" +
6982
"\"@context\": \"http://schema.org\"," +

0 commit comments

Comments
 (0)