Skip to content

Commit

Permalink
-Fixed compatibility with latest Newtonsoft.Json
Browse files Browse the repository at this point in the history
-Removed netstandard2.0 build
  • Loading branch information
JamesNK committed Feb 17, 2018
1 parent 1289071 commit fc5c104
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

$builds = @(
@{Framework = "netstandard1.3"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp1.1"; Enabled=$true}
@{Framework = "netstandard2.0"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp2.0"; Enabled=$true}
#@{Framework = "netstandard2.0"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp2.0"; Enabled=$true}
@{Framework = "net45"; TestsFunction = "NUnitTests"; TestFramework = "net46"; NUnitFramework="net-4.0"; Enabled=$true},
@{Framework = "net40"; TestsFunction = "NUnitTests"; NUnitFramework="net-4.0"; Enabled=$true},
@{Framework = "net35"; TestsFunction = "NUnitTests"; NUnitFramework="net-2.0"; Enabled=$true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@ private void PopulatePrimativeSchema(JSchema schema, JsonContract contract, Json
schema.Enum.Add(JValue.CreateNull());
}

IList<EnumValue<long>> enumValues = EnumUtils.GetNamesAndValues<long>(contract.NonNullableUnderlyingType);
foreach (EnumValue<long> enumValue in enumValues)
EnumInfo enumValues = EnumUtils.GetEnumValuesAndNames(contract.NonNullableUnderlyingType);
for (int i = 0; i < enumValues.Values.Length; i++)
{
JToken value = JToken.FromObject(enumValue.Value);
JToken value = JToken.FromObject(Enum.ToObject(contract.NonNullableUnderlyingType, enumValues.Values[i]));

schema.Enum.Add(value);
}
Expand All @@ -549,12 +549,12 @@ private void PopulatePrimativeSchema(JSchema schema, JsonContract contract, Json
Type enumDataType = AttributeHelpers.GetEnumDataType(memberProperty);
if (enumDataType != null && CollectionUtils.IsNullOrEmpty(schema._enum))
{
IList<EnumValue<long>> enumValues = EnumUtils.GetNamesAndValues<long>(enumDataType);
foreach (EnumValue<long> enumValue in enumValues)
EnumInfo enumValues = EnumUtils.GetEnumValuesAndNames(enumDataType);
for (int i = 0; i < enumValues.Values.Length; i++)
{
JToken value = (JSchemaTypeHelpers.HasFlag(type, JSchemaType.String))
? enumValue.Name
: JToken.FromObject(enumValue.Value);
? enumValues.ResolvedNames[i]
: JToken.FromObject(enumValues.Values[i]);

schema.Enum.Add(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ public override JSchema GetSchema(JSchemaTypeGenerationContext context)
object defaultValue = context.MemberProperty?.DefaultValue;
if (defaultValue != null)
{
string finalName = EnumUtils.ToEnumName(t, defaultValue.ToString(), CamelCaseText);
EnumUtils.TryToString(t, defaultValue, CamelCaseText, out string finalName);

schema.Default = JToken.FromObject(finalName);
schema.Default = JToken.FromObject(finalName ?? defaultValue.ToString());
}

string[] names = Enum.GetNames(t);

foreach (string name in names)
EnumInfo enumValues = EnumUtils.GetEnumValuesAndNames(t);
for (int i = 0; i < enumValues.Values.Length; i++)
{
string finalName = EnumUtils.ToEnumName(t, name, CamelCaseText);
EnumUtils.TryToString(t, enumValues.Values[i], CamelCaseText, out string finalName);

schema.Enum.Add(JValue.CreateString(finalName));
}
Expand Down
10 changes: 7 additions & 3 deletions Src/Newtonsoft.Json.Schema/Newtonsoft.Json.Schema.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net45;net40;net35;netstandard1.3;netstandard2.0;portable-net45+win8+wpa81+wp8</TargetFrameworks>
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net45;net40;net35;netstandard1.3;portable-net45+win8+wpa81+wp8</TargetFrameworks>
<TargetFrameworks Condition="'$(LibraryFrameworks)'!=''">$(LibraryFrameworks)</TargetFrameworks>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.1</FileVersion>
Expand Down Expand Up @@ -29,7 +29,7 @@
<MinClientVersion>2.12</MinClientVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json.Unsigned" Version="10.0.2" />
<PackageReference Include="Newtonsoft.Json.Unsigned" Version="11.0.1" />
<EmbeddedResource Include="Resources\*.json" />
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="LICENSE.md" />
</ItemGroup>
Expand All @@ -45,9 +45,13 @@
<AssemblyTitle>Json.NET Schema .NET 3.5</AssemblyTitle>
<DefineConstants>NET35;$(AdditionalConstants)</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<AssemblyTitle>Json.NET Schema .NET Standard 1.3</AssemblyTitle>
<DefineConstants>NETSTANDARD1_3;PORTABLE;$(AdditionalConstants)</DefineConstants>
Expand Down

0 comments on commit fc5c104

Please sign in to comment.