Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/RicoSuter/NJsonSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Nov 19, 2024
2 parents 3ed0741 + b48f891 commit 7869b1e
Show file tree
Hide file tree
Showing 72 changed files with 328 additions and 231 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
# [CustomGitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
Expand Down Expand Up @@ -33,6 +33,10 @@ jobs:
name: windows-latest
runs-on: windows-latest
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0
- uses: actions/checkout@v4
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v4
Expand All @@ -48,13 +52,18 @@ jobs:
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}
- name: 'Publish: artifacts'
uses: actions/upload-artifact@v4
if: runner.os == 'Windows'
with:
name: artifacts
path: artifacts
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0
- uses: actions/checkout@v4
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v4
Expand All @@ -70,6 +79,7 @@ jobs:
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}
- name: 'Publish: artifacts'
uses: actions/upload-artifact@v4
if: runner.os == 'Windows'
with:
name: artifacts
path: artifacts
10 changes: 9 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
# [CustomGitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
Expand Down Expand Up @@ -34,6 +34,10 @@ jobs:
name: windows-latest
runs-on: windows-latest
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0
- uses: actions/checkout@v4
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v4
Expand All @@ -48,6 +52,10 @@ jobs:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0
- uses: actions/checkout@v4
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v4
Expand Down
30 changes: 29 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,40 @@
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<!--
[IDE0005] Using directive is unnecessary
[IDE0008] Use explicit type instead of 'var'
[IDE0019] Use pattern matching
[IDE0021] Use block body for constructor
[IDE0022] Use block body for method
[IDE0025] Use expression body for property
[IDE0027] Use expression body for accessor
[IDE0028] Collection initialization can be simplified
[IDE0029] Null check can be simplified
[IDE0032] Use auto property
[IDE0039] Use local function]
[IDE0045] 'if' statement can be simplified]
[IDE0046] 'if' statement can be simplified
[IDE0055] Fix formatting
[IDE0057] Substring can be simplified
[IDE0059] Unnecessary assignment of a value
[IDE0060] Remove unused parameter
[IDE0074] Use compound assignment
[IDE0078] Use pattern matching
[IDE0083] Use pattern matching
[IDE0090] 'new' expression can be simplified
[IDE0100] Remove redundant equality
[IDE0130] Namespace does not match folder structure
[IDE0160] Convert to block scoped namespace
[IDE0260] Use pattern matching
[IDE0290] Use primary constructor
[IDE1005] Delegate invocation can be simplified
[CA1200] Avoid using cref tags with a prefix
[CA1510] Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
[CA1716] rename parameter property so that it no longer conflicts with the reserved language keyword
[CA1720] Identifier 'xxx' contains type name
[CA2263] Prefer the generic overload 'System.Enum.GetValues<TEnum>()'
-->
<NoWarn>$(NoWarn);CA1200;CA1510;CA1716;CA1720</NoWarn>
<NoWarn>$(NoWarn);IDE0005;IDE0008;IDE0019;IDE0021;IDE0022;IDE0025;IDE0027;IDE0028;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0057;IDE0059;IDE0060;IDE0074;IDE0078;IDE0083;IDE0090;IDE0100;IDE0130;IDE0160;IDE0260;IDE0290;IDE1005;CA1200;CA1510;CA1716;CA1720;CA2263</NoWarn>
</PropertyGroup>

</Project>
60 changes: 58 additions & 2 deletions build/Build.CI.GitHubActions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Collections.Generic;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;

[GitHubActions(
[CustomGitHubActions(
"pr",
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
Expand All @@ -12,7 +16,7 @@
CacheKeyFiles = ["global.json", "src/**/*.csproj", "src/**/package.json"],
ConcurrencyCancelInProgress = true)
]
[GitHubActions(
[CustomGitHubActions(
"build",
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
Expand All @@ -21,8 +25,60 @@
OnPushIncludePaths = ["**/*.*"],
OnPushExcludePaths = ["**/*.md"],
PublishArtifacts = true,
PublishCondition = "runner.os == 'Windows'",
InvokedTargets = [nameof(Compile), nameof(Test), nameof(Pack), nameof(Publish)],
ImportSecrets = ["NUGET_API_KEY", "MYGET_API_KEY"],
CacheKeyFiles = ["global.json", "src/**/*.csproj", "src/**/package.json"])
]
public partial class Build;

class CustomGitHubActionsAttribute : GitHubActionsAttribute
{
public CustomGitHubActionsAttribute(string name, GitHubActionsImage image, params GitHubActionsImage[] images) : base(name, image, images)
{
}

protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCollection<ExecutableTarget> relevantTargets)
{
var job = base.GetJobs(image, relevantTargets);

var newSteps = new List<GitHubActionsStep>(job.Steps);

// only need to list the ones that are missing from default image
newSteps.Insert(0, new GitHubActionsSetupDotNetStep(["9.0"]));

job.Steps = newSteps.ToArray();
return job;
}
}

class GitHubActionsSetupDotNetStep : GitHubActionsStep
{
public GitHubActionsSetupDotNetStep(string[] versions)
{
Versions = versions;
}

string[] Versions { get; }

public override void Write(CustomFileWriter writer)
{
writer.WriteLine("- uses: actions/setup-dotnet@v4");

using (writer.Indent())
{
writer.WriteLine("with:");
using (writer.Indent())
{
writer.WriteLine("dotnet-version: |");
using (writer.Indent())
{
foreach (var version in Versions)
{
writer.WriteLine(version);
}
}
}
}
}
}
1 change: 1 addition & 0 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="8.1.4" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"version": "9.0.100",
"rollForward": "latestMinor"
}
}
2 changes: 2 additions & 0 deletions src/NJsonSchema.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static void Main(string[] args)
BenchmarkDotNet.Running.BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAllJoined();
}

#pragma warning disable IDE0051
private static void RunCsharpBenchmark()
#pragma warning restore IDE0051
{
var benchmark = new CsharpGeneratorBenchmark();
benchmark.Setup().GetAwaiter().GetResult();
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema.Benchmark/SchemaGenerationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class WritingInstrument
{
public static Type[] GetKnownTypes()
{
return new[] { typeof(Pen), typeof(Pencil) };
return [typeof(Pen), typeof(Pencil)];
}

public string Baz { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void When_using_NewtonsoftJson_with_JsonConverters_GenerateJsonSerializer
var settings = new CSharpGeneratorSettings
{
JsonLibrary = CSharpJsonLibrary.NewtonsoftJson,
JsonConverters = new string[] { "CustomConverter1", "CustomConverter2" }
JsonConverters = ["CustomConverter1", "CustomConverter2"]
};

//// Act
Expand Down Expand Up @@ -68,7 +68,7 @@ public void When_using_NewtonsoftJson_with_HandleReferences_and_JsonConverters_a
{
JsonLibrary = CSharpJsonLibrary.NewtonsoftJson,
HandleReferences = true,
JsonConverters = new string[] { "CustomConverter1", "CustomConverter2" },
JsonConverters = ["CustomConverter1", "CustomConverter2"],
JsonSerializerSettingsTransformationMethod = "TestJsonSerializerSettingsTransformationMethod",
};

Expand All @@ -88,7 +88,7 @@ public void When_using_SystemTextJson_with_JsonConverters_GenerateJsonConverters
var settings = new CSharpGeneratorSettings
{
JsonLibrary = CSharpJsonLibrary.SystemTextJson,
JsonConverters = new string[] { "CustomConverter1", "CustomConverter2" }
JsonConverters = ["CustomConverter1", "CustomConverter2"]
};

//// Act
Expand All @@ -107,7 +107,7 @@ public void When_using_NewtonsoftJson_with_JsonConverters_GenerateJsonConverters
var settings = new CSharpGeneratorSettings
{
JsonLibrary = CSharpJsonLibrary.NewtonsoftJson,
JsonConverters = new string[] { "CustomConverter1", "CustomConverter2" }
JsonConverters = ["CustomConverter1", "CustomConverter2"]
};

//// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ public async Task When_generating_CSharp_code_then_default_value_generates_expec
}");

//// Act
var settings = new CSharpGeneratorSettings();
settings.GenerateDefaultValues = true;
var settings = new CSharpGeneratorSettings
{
GenerateDefaultValues = true
};

var generator = new CSharpGenerator(document, settings);
var code = generator.GenerateFile();
Expand All @@ -117,8 +119,10 @@ public async Task When_generating_CSharp_code_then_default_value_with_decimal_ge
}");

//// Act
var settings = new CSharpGeneratorSettings();
settings.GenerateDefaultValues = true;
var settings = new CSharpGeneratorSettings
{
GenerateDefaultValues = true
};

var generator = new CSharpGenerator(document, settings);
var code = generator.GenerateFile();
Expand Down Expand Up @@ -149,8 +153,10 @@ public async Task When_generating_CSharp_code_then_default_value_of_dictionary_w
}");

// Act
var settings = new CSharpGeneratorSettings();
settings.GenerateDefaultValues = true;
var settings = new CSharpGeneratorSettings
{
GenerateDefaultValues = true
};

var generator = new CSharpGenerator(document, settings);
var code = generator.GenerateFile();
Expand Down Expand Up @@ -181,8 +187,10 @@ public async Task When_generating_CSharp_code_then_default_value_of_array_of_arr
}");

// Act
var settings = new CSharpGeneratorSettings();
settings.GenerateDefaultValues = true;
var settings = new CSharpGeneratorSettings
{
GenerateDefaultValues = true
};

var generator = new CSharpGenerator(document, settings);
var code = generator.GenerateFile();
Expand Down
Loading

0 comments on commit 7869b1e

Please sign in to comment.