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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="17.0.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NJsonSchema" Version="11.5.2" />
<PackageVersion Include="NJsonSchema" Version="11.6.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSwag.CodeGeneration.CSharp" Version="14.6.3" />
<PackageVersion Include="NSwag.MSBuild" Version="14.6.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.OpenApi;

namespace Swashbuckle.AspNetCore.IntegrationTests;

/// <summary>
/// Tests that validate that OpenAPI documents produce valid C# code when used with code generation tools.
/// </summary>
public class CodeGenerationTests(ITestOutputHelper outputHelper)
public partial class CodeGenerationTests(ITestOutputHelper outputHelper)
{
private const string SnapshotsDirectory = "snapshots/code";

Expand Down Expand Up @@ -87,6 +88,8 @@ await VerifyDirectory(
options: new() { RecurseSubdirectories = true })
.UseDirectory(SnapshotsDirectory)
.UseFileName($"{nameof(GeneratesValidClient)}_{hashString}")
.ScrubLinesWithReplace(line => GeneratedCodeRegex().Replace(line, "[GeneratedCode]"))
.ScrubLinesWithReplace(line => NSwagGenerationComment().Replace(line, "// Generated using the NSwag toolchain"))
.AddScrubber((builder) =>
{
var content = builder.ToString();
Expand Down Expand Up @@ -124,6 +127,12 @@ private static string GetProjectRoot() =>
.GetCustomAttributes<AssemblyMetadataAttribute>()
.First((p) => p.Key is "ProjectRoot")
.Value!;

[GeneratedRegex(@"\[System\.CodeDom\.Compiler\.GeneratedCode\(\"".*\""\)]")]
private static partial Regex GeneratedCodeRegex();

[GeneratedRegex(@"^// Generated using the NSwag toolchain.*$")]
private static partial Regex NSwagGenerationComment();
}

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// Generated using the NSwag toolchain
// </auto-generated>
//----------------------

Expand All @@ -24,7 +24,7 @@ namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests
{
using System = global::System;

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class NSwagOpenApiClient
{
#pragma warning disable 8618
Expand Down Expand Up @@ -1016,7 +1016,7 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu
/// <summary>
/// Represents the model for creating a new Todo item.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class CreateTodoItemModel
{

Expand All @@ -1031,7 +1031,7 @@ public partial class CreateTodoItemModel
/// <summary>
/// Represents the model for a created Todo item.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class CreatedTodoItemModel
{

Expand All @@ -1043,7 +1043,7 @@ public partial class CreatedTodoItemModel

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ProblemDetails
{

Expand Down Expand Up @@ -1076,7 +1076,7 @@ public System.Collections.Generic.IDictionary<string, object> AdditionalProperti
/// <summary>
/// Represents a Todo item.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class TodoItemModel
{

Expand Down Expand Up @@ -1122,7 +1122,7 @@ public partial class TodoItemModel
/// <summary>
/// Represents a collection of Todo items.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class TodoListViewModel
{

Expand All @@ -1137,7 +1137,7 @@ public partial class TodoListViewModel
/// <summary>
/// The priority levels for a Todo item.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public enum TodoPriority
{

Expand All @@ -1155,7 +1155,7 @@ public enum TodoPriority
/// <summary>
/// Represents the model for updating the priority of a Todo item.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class UpdateTodoItemPriorityModel
{

Expand All @@ -1170,7 +1170,7 @@ public partial class UpdateTodoItemPriorityModel



[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException : System.Exception
{
public int StatusCode { get; private set; }
Expand All @@ -1193,7 +1193,7 @@ public override string ToString()
}
}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException<TResult> : ApiException
{
public TResult Result { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// Generated using the NSwag toolchain
// </auto-generated>
//----------------------

Expand All @@ -24,7 +24,7 @@ namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests
{
using System = global::System;

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class NSwagOpenApiClient
{
#pragma warning disable 8618
Expand Down Expand Up @@ -2048,7 +2048,7 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu
}
}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class Address
{

Expand All @@ -2066,7 +2066,7 @@ public partial class Address

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class AddressAnnotated
{

Expand All @@ -2087,7 +2087,7 @@ public partial class AddressAnnotated

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class AsParametersRecord
{

Expand Down Expand Up @@ -2131,7 +2131,7 @@ public partial class AsParametersRecord

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class CurrenciesRate
{

Expand All @@ -2149,7 +2149,7 @@ public partial class CurrenciesRate

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public enum DateTimeKind
{

Expand All @@ -2164,7 +2164,7 @@ public enum DateTimeKind
/// <summary>
/// Description for Schema
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class Fruit
{

Expand All @@ -2173,7 +2173,7 @@ public partial class Fruit

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class OrganizationCustomExchangeRatesDto
{

Expand All @@ -2185,7 +2185,7 @@ public partial class OrganizationCustomExchangeRatesDto

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class Person
{

Expand All @@ -2197,7 +2197,7 @@ public partial class Person

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class PersonAnnotated
{

Expand All @@ -2218,7 +2218,7 @@ public partial class PersonAnnotated
/// <summary>
/// Represents a product
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class Product
{

Expand All @@ -2236,7 +2236,7 @@ public partial class Product

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class WeatherForecast
{

Expand All @@ -2255,7 +2255,7 @@ public partial class WeatherForecast

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
{
public DateFormatConverter()
Expand All @@ -2264,7 +2264,7 @@ public DateFormatConverter()
}
}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class FileParameter
{
public FileParameter(System.IO.Stream data)
Expand Down Expand Up @@ -2293,7 +2293,7 @@ public FileParameter(System.IO.Stream data, string fileName, string contentType)



[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException : System.Exception
{
public int StatusCode { get; private set; }
Expand All @@ -2316,7 +2316,7 @@ public override string ToString()
}
}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException<TResult> : ApiException
{
public TResult Result { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// Generated using the NSwag toolchain
// </auto-generated>
//----------------------

Expand All @@ -24,7 +24,7 @@ namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests
{
using System = global::System;

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class NSwagOpenApiClient
{
#pragma warning disable 8618
Expand Down Expand Up @@ -358,7 +358,7 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu
}
}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class Todo
{

Expand All @@ -377,7 +377,7 @@ public partial class Todo

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter
{
public DateFormatConverter()
Expand All @@ -388,7 +388,7 @@ public DateFormatConverter()



[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException : System.Exception
{
public int StatusCode { get; private set; }
Expand All @@ -411,7 +411,7 @@ public override string ToString()
}
}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException<TResult> : ApiException
{
public TResult Result { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
// Generated using the NSwag toolchain
// </auto-generated>
//----------------------

Expand All @@ -24,7 +24,7 @@ namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests
{
using System = global::System;

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class NSwagOpenApiClient
{
#pragma warning disable 8618
Expand Down Expand Up @@ -360,7 +360,7 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu
}
}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public enum LogLevel
{

Expand All @@ -382,7 +382,7 @@ public enum LogLevel



[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException : System.Exception
{
public int StatusCode { get; private set; }
Expand All @@ -405,7 +405,7 @@ public override string ToString()
}
}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")]
[GeneratedCode]
public partial class ApiException<TResult> : ApiException
{
public TResult Result { get; private set; }
Expand Down
Loading
Loading