Skip to content

Commit

Permalink
NJsonSchema v11 (preview) (#1450)
Browse files Browse the repository at this point in the history
* Use STJ, refactor

* Remove legacy

* up

* Ignore tests

* Move

* Remove old targets

* Add STJ

* Remove dep

* Rename

* Update

* Refactor

* Updates

* Fixes

* Remove code

* Refactoring

* Refactor

* Update

* Update

* Fixes

* clean proj

* Improve proj

* Fixes

* Fix

* Improve type handling

* Update

* Fixes

* fix tests

* improvements

* improve projects

* update packages

* Upgrade to net462

* Namotion.Reflection v3

* add net6.0 target

* add struct

* remove enum handling

* update pipeline

* update build.yml

* update build

* fix string enums

* Remove SystemTextJsonSchemaGenerator

* fixes

* fix

* Move namespaces

* move

* Fix struct handling, closes #1624

* move

* Ignore EqualityContract

---------

Co-authored-by: Rico Suter <rico.suter@buhlergroup.com>
  • Loading branch information
RicoSuter and Rico Suter authored Sep 26, 2023
1 parent 95a5be6 commit 2633a99
Show file tree
Hide file tree
Showing 148 changed files with 2,475 additions and 2,168 deletions.
15 changes: 12 additions & 3 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@ protected override void OnBuildInitialized()
{
VersionPrefix = DetermineVersionPrefix();

VersionSuffix = !IsTaggedBuild
? $"preview-{DateTime.UtcNow:yyyyMMdd-HHmm}"
: "";
var versionParts = VersionPrefix.Split('-');
if (versionParts.Length == 2)
{
VersionPrefix = versionParts[0];
VersionSuffix = versionParts[1];
}
else
{
VersionSuffix = !IsTaggedBuild
? $"preview-{DateTime.UtcNow:yyyyMMdd-HHmm}"
: "";
}

if (IsLocalBuild)
{
Expand Down
4 changes: 2 additions & 2 deletions build/_build.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="5.3.0" />
<PackageReference Include="Nuke.Common" Version="7.0.2" />
<PackageDownload Include="NuGet.CommandLine" Version="[5.11.0]" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion src/NJsonSchema.Benchmark/JsonSchemaGeneratorBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BenchmarkDotNet.Attributes;
using NJsonSchema.NewtonsoftJson.Generation;

namespace NJsonSchema.Benchmark
{
Expand All @@ -8,7 +9,7 @@ public class JsonSchemaGeneratorBenchmark
[Benchmark]
public void GenerateFile()
{
JsonSchema.FromType<SchemaGenerationBenchmarks.Container>();
NewtonsoftJsonSchemaGenerator.FromType<SchemaGenerationBenchmarks.Container>();
}
}
}
11 changes: 9 additions & 2 deletions src/NJsonSchema.Benchmark/NJsonSchema.Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<NoWarn>$(NoWarn),xUnit1013</NoWarn>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="*.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NBench" Version="2.0.1" />
<PackageReference Include="Pro.NBench.xUnit" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj" />
<ProjectReference Include="..\NJsonSchema.CodeGeneration.TypeScript\NJsonSchema.CodeGeneration.TypeScript.csproj" />
<ProjectReference Include="..\NJsonSchema.NewtonsoftJson\NJsonSchema.NewtonsoftJson.csproj" />
<ProjectReference Include="..\NJsonSchema.Tests\NJsonSchema.Tests.csproj" />
<ProjectReference Include="..\NJsonSchema\NJsonSchema.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/NJsonSchema.Benchmark/SchemaGenerationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Runtime.Serialization;
using NBench;
using NJsonSchema.NewtonsoftJson.Generation;
using Pro.NBench.xUnit.XunitExtensions;
using Xunit.Abstractions;

Expand Down Expand Up @@ -32,7 +33,7 @@ public void Setup(BenchmarkContext context)
[CounterThroughputAssertion("Iterations", MustBe.GreaterThan, 100)]
public void GenerateSchema()
{
var schema = JsonSchema.FromType<Container>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<Container>();
_counter.Increment();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.NewtonsoftJson.Generation;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -15,7 +16,7 @@ public abstract class AbstractClass
public async Task When_class_is_abstract_then_is_abstract_CSharp_keyword_is_generated()
{
/// Arrange
var schema = JsonSchema.FromType<AbstractClass>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<AbstractClass>();

/// Act
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using Xunit;

namespace NJsonSchema.CodeGeneration.Tests.CSharp
Expand Down Expand Up @@ -236,7 +237,7 @@ public class Book
public void When_AlwaysAllowAdditionalObjectProperties_is_set_then_dictionary_and_no_object_are_not_same()
{
// Arrange
var schema = JsonSchema.FromType<Book>(new JsonSchemaGeneratorSettings
var schema = NewtonsoftJsonSchemaGenerator.FromType<Book>(new NewtonsoftJsonSchemaGeneratorSettings
{
AlwaysAllowAdditionalObjectProperties = true
});
Expand All @@ -262,7 +263,7 @@ public void When_AlwaysAllowAdditionalObjectProperties_is_set_then_dictionary_an
public void When_AlwaysAllowAdditionalObjectProperties_is_set_then_any_page_has_additional_properties()
{
// Arrange
var schema = JsonSchema.FromType<Book>(new JsonSchemaGeneratorSettings
var schema = NewtonsoftJsonSchemaGenerator.FromType<Book>(new NewtonsoftJsonSchemaGeneratorSettings
{
AlwaysAllowAdditionalObjectProperties = true
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.NewtonsoftJson.Generation;
using Xunit;

namespace NJsonSchema.CodeGeneration.Tests.CSharp
Expand All @@ -23,7 +24,7 @@ public class MyRequiredTest
public async Task When_array_property_is_not_nullable_then_it_does_not_have_a_setter()
{
//// Arrange
var schema = JsonSchema.FromType<MyRequiredTest>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<MyRequiredTest>();
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings
{
ClassStyle = CSharpClassStyle.Poco,
Expand Down
5 changes: 3 additions & 2 deletions src/NJsonSchema.CodeGeneration.CSharp.Tests/ArrayTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NJsonSchema.Annotations;
using NJsonSchema.NewtonsoftJson.Generation;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
Expand All @@ -18,7 +19,7 @@ public class ArrayTest
public async Task When_array_property_is_required_then_array_instance_can_be_changed()
{
//// Arrange
var schema = JsonSchema.FromType<ArrayTest>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<ArrayTest>();
var data = schema.ToJson();

//// Act
Expand All @@ -45,7 +46,7 @@ public class ClassWithNullableArrayItems
public async Task When_array_item_is_nullable_then_generated_CSharp_is_correct()
{
// Arrange
var schema = JsonSchema.FromType<ClassWithNullableArrayItems>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<ClassWithNullableArrayItems>();
var json = schema.ToJson();
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using NJsonSchema.NewtonsoftJson.Generation;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -25,7 +26,7 @@ public class EnumKeyDictionaryTest
public async Task When_dictionary_key_is_enum_then_csharp_has_enum_key()
{
//// Arrange
var schema = JsonSchema.FromType<EnumKeyDictionaryTest>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<EnumKeyDictionaryTest>();
var data = schema.ToJson();

//// Act
Expand All @@ -41,7 +42,7 @@ public async Task When_dictionary_key_is_enum_then_csharp_has_enum_key()
public async Task When_dictionary_property_is_required_then_dictionary_instance_can_be_changed()
{
//// Arrange
var schema = JsonSchema.FromType<EnumKeyDictionaryTest>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<EnumKeyDictionaryTest>();
var data = schema.ToJson();

//// Act
Expand Down
7 changes: 4 additions & 3 deletions src/NJsonSchema.CodeGeneration.CSharp.Tests/EnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json.Converters;
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -137,7 +138,7 @@ public enum MyStringEnum
public async Task When_enum_list_uses_string_enums_then_ItemConverterType_is_set()
{
//// Arrange
var schema = JsonSchema.FromType<MyStringEnumListTest>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<MyStringEnumListTest>();
var data = schema.ToJson();
var generator =
new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
Expand All @@ -153,7 +154,7 @@ public async Task When_enum_list_uses_string_enums_then_ItemConverterType_is_set
public async Task When_enum_is_nullable_then_StringEnumConverter_is_set()
{
//// Arrange
var schema = JsonSchema.FromType<MyStringEnumListTest>();
var schema = NewtonsoftJsonSchemaGenerator.FromType<MyStringEnumListTest>();
var data = schema.ToJson();
var generator =
new CSharpGenerator(schema, new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco });
Expand Down Expand Up @@ -182,7 +183,7 @@ public class SomeClass
public async Task When_class_has_enum_array_property_then_enum_name_is_preserved()
{
//// Arrange
var schema = JsonSchema.FromType<SomeClass>(new JsonSchemaGeneratorSettings());
var schema = NewtonsoftJsonSchemaGenerator.FromType<SomeClass>(new NewtonsoftJsonSchemaGeneratorSettings());
var json = schema.ToJson();

//// Act
Expand Down
Loading

0 comments on commit 2633a99

Please sign in to comment.