Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ makefile text
*.woff binary
*.woff2 binary
*.exe binary
*.pyc binary
*.pyc binary

# Verify support
*.verified.txt text eol=lf working-tree-encoding=UTF-8
*.verified.xml text eol=lf working-tree-encoding=UTF-8
*.verified.json text eol=lf working-tree-encoding=UTF-8
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand Down
35 changes: 35 additions & 0 deletions src/NJsonSchema.CodeGeneration.CSharp.Tests/CodeCompiler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace NJsonSchema.CodeGeneration.CSharp.Tests;

public class CodeCompiler
{
public static void AssertCompiles(string source)
{
var syntaxTree = CSharpSyntaxTree.ParseText(source);

var metadataReferences = AppDomain.CurrentDomain.GetAssemblies()
.Where(x => !x.IsDynamic && !string.IsNullOrWhiteSpace(x.Location))
.Select(x => MetadataReference.CreateFromFile(x.Location))
.Append(MetadataReference.CreateFromFile(typeof(System.ComponentModel.DataAnnotations.RangeAttribute).Assembly.Location))
.ToList();

CSharpCompilation compilation = CSharpCompilation.Create(
assemblyName: "assemblyName",
syntaxTrees: [syntaxTree],
references:
metadataReferences,
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

using var dllStream = new MemoryStream();
using var pdbStream = new MemoryStream();

var emitResult = compilation.Emit(dllStream, pdbStream);
if (!emitResult.Success)
{
// emitResult.Diagnostics
Assert.Empty(emitResult.Diagnostics);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<Nullable>disable</Nullable>
<AnalysisLevel>latest-Minimal</AnalysisLevel>
Expand All @@ -13,15 +14,24 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Verify.XUnit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Condition="'$(TargetFramework)' == 'net8.0'" />
</ItemGroup>

<ItemGroup>
<Reference Condition="'$(TargetFramework)' == 'net472'" Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>

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

<ItemGroup>
<Compile Include="..\NJsonSchema.CodeGeneration.Tests\VerifyHelper.cs" Link="VerifyHelper.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Array10 : System.Collections.ObjectModel.Collection<string>
{

}

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
[System.ComponentModel.DataAnnotations.MaxLength(10)]
public Array10 Value { get; set; } = new Array10();



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
[System.ComponentModel.DataAnnotations.MinLength(10)]
public System.Collections.Generic.ICollection<string> Value { get; set; } = new System.Collections.ObjectModel.Collection<string>();



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(10, int.MaxValue)]
public int Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(10L, long.MaxValue)]
public long Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(int.MinValue, 20)]
public int Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(-10000000000L, 10000000000L)]
public long Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(-99999999, 99999999)]
public int Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(-100.50M, 100.50M)]
public decimal Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//----------------------
// <auto-generated>
// </auto-generated>
//----------------------


namespace MyNamespace
{
#pragma warning disable // Disable all warnings

public partial class Message
{
[Newtonsoft.Json.JsonProperty("value", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(-10000000000D, 10000000000D)]
public double Value { get; set; }



private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
set { _additionalProperties = value; }
}

}
}
Loading