Skip to content

Commit

Permalink
Run against NSwag v14 (requires to clone NSwag sources and checkout R…
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed May 12, 2024
1 parent 9bdea37 commit 5dcfab8
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
<RunSettingsFilePath>$(MSBuildThisFileDirectory)tests.runsettings</RunSettingsFilePath>
<JsonApiDotNetCoreVersionPrefix>5.5.2</JsonApiDotNetCoreVersionPrefix>
<!-- Requires checkout of https://github.com/RicoSuter/NSwag/pull/4888 in sibling directory of JsonApiDotNetCore repository -->
<NSwagTemplateDirectory>$(MSBuildThisFileDirectory)..\NSwag\src\NSwag.CodeGeneration.CSharp\Templates</NSwagTemplateDirectory>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion package-versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<InheritDocVersion>2.0.*</InheritDocVersion>
<KiotaVersion>1.*</KiotaVersion>
<MicrosoftApiClientVersion>8.0.*</MicrosoftApiClientVersion>
<NSwagApiClientVersion>13.20.*</NSwagApiClientVersion>
<NSwagApiClientVersion>14.0.*</NSwagApiClientVersion>
<NewtonsoftJsonVersion>13.0.*</NewtonsoftJsonVersion>
<SourceLinkVersion>8.0.*</SourceLinkVersion>
<SwashbuckleVersion>6.5.*</SwashbuckleVersion>
Expand Down
8 changes: 5 additions & 3 deletions src/Examples/OpenApiNSwagClientExample/ExampleApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace OpenApiNSwagClientExample;
[UsedImplicitly(ImplicitUseTargetFlags.Itself)]
public partial class ExampleApiClient : JsonApiClient
{
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
partial void Initialize()
{
SetSerializerSettingsForJsonApi(settings);
_instanceSettings = new JsonSerializerSettings();

#if DEBUG
settings.Formatting = Formatting.Indented;
_instanceSettings.Formatting = Formatting.Indented;
#endif

SetSerializerSettingsForJsonApi(_instanceSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
<ClassName>ExampleApiClient</ClassName>
<OutputPath>ExampleApiClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/GenerateExceptionClasses:false /WrapResponses:true /GenerateResponseClasses:false /ResponseClass:ApiResponse /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag</Options>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagWrapResponses>true</NSwagWrapResponses>
<NSwagGenerateResponseClasses>false</NSwagGenerateResponseClasses>
<NSwagResponseClass>ApiResponse</NSwagResponseClass>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
</OpenApiReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ namespace OpenApiNSwagClientTests.LegacyOpenApi.GeneratedCode;

internal partial class LegacyClient : JsonApiClient
{
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
partial void Initialize()
{
SetSerializerSettingsForJsonApi(settings);
_instanceSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};

settings.Formatting = Formatting.Indented;
SetSerializerSettingsForJsonApi(_instanceSettings);
}
}
45 changes: 33 additions & 12 deletions test/OpenApiNSwagClientTests/OpenApiNSwagClientTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,77 @@
<ClassName>LegacyClient</ClassName>
<OutputPath>LegacyClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/GenerateClientInterfaces:true /ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag</Options>
<NSwagGenerateClientInterfaces>true</NSwagGenerateClientInterfaces>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\NamingConventions\KebabCase\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.NamingConventions.KebabCase.GeneratedCode</Namespace>
<ClassName>KebabCaseClient</ClassName>
<OutputPath>KebabCaseClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\NamingConventions\CamelCase\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.NamingConventions.CamelCase.GeneratedCode</Namespace>
<ClassName>CamelCaseClient</ClassName>
<OutputPath>CamelCaseClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\NamingConventions\PascalCase\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.NamingConventions.PascalCase.GeneratedCode</Namespace>
<ClassName>PascalCaseClient</ClassName>
<OutputPath>PascalCaseClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\ResourceFieldValidation\NullableReferenceTypesOff\ModelStateValidationOff\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOff.ModelStateValidationOff.GeneratedCode</Namespace>
<ClassName>NrtOffMsvOffClient</ClassName>
<OutputPath>NrtOffMsvOffClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOff.ModelStateValidationOff.GeneratedCode</Namespace>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:false</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>false</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\ResourceFieldValidation\NullableReferenceTypesOff\ModelStateValidationOn\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOff.ModelStateValidationOn.GeneratedCode</Namespace>
<ClassName>NrtOffMsvOnClient</ClassName>
<OutputPath>NrtOffMsvOnClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOff.ModelStateValidationOn.GeneratedCode</Namespace>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:false</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>false</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\ResourceFieldValidation\NullableReferenceTypesOn\ModelStateValidationOff\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOn.ModelStateValidationOff.GeneratedCode</Namespace>
<ClassName>NrtOnMsvOffClient</ClassName>
<OutputPath>NrtOnMsvOffClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOn.ModelStateValidationOff.GeneratedCode</Namespace>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\ResourceFieldValidation\NullableReferenceTypesOn\ModelStateValidationOn\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOn.ModelStateValidationOn.GeneratedCode</Namespace>
<ClassName>NrtOnMsvOnClient</ClassName>
<OutputPath>NrtOnMsvOnClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Namespace>OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypesOn.ModelStateValidationOn.GeneratedCode</Namespace>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ namespace OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypes

internal partial class NrtOffMsvOffClient : JsonApiClient
{
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
partial void Initialize()
{
SetSerializerSettingsForJsonApi(settings);
_instanceSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};

settings.Formatting = Formatting.Indented;
SetSerializerSettingsForJsonApi(_instanceSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ namespace OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypes

internal partial class NrtOffMsvOnClient : JsonApiClient
{
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
partial void Initialize()
{
SetSerializerSettingsForJsonApi(settings);
_instanceSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};

settings.Formatting = Formatting.Indented;
SetSerializerSettingsForJsonApi(_instanceSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ namespace OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypes

internal partial class NrtOnMsvOffClient : JsonApiClient
{
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
partial void Initialize()
{
SetSerializerSettingsForJsonApi(settings);
_instanceSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};

settings.Formatting = Formatting.Indented;
SetSerializerSettingsForJsonApi(_instanceSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ namespace OpenApiNSwagClientTests.ResourceFieldValidation.NullableReferenceTypes

internal partial class NrtOnMsvOnClient : JsonApiClient
{
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
partial void Initialize()
{
SetSerializerSettingsForJsonApi(settings);
_instanceSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};

settings.Formatting = Formatting.Indented;
SetSerializerSettingsForJsonApi(_instanceSettings);
}
}
28 changes: 23 additions & 5 deletions test/OpenApiNSwagEndToEndTests/OpenApiNSwagEndToEndTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,53 @@
<ClassName>ClientIdGenerationModesClient</ClassName>
<OutputPath>ClientIdGenerationModesClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\Headers\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagEndToEndTests.Headers.GeneratedCode</Namespace>
<ClassName>HeadersClient</ClassName>
<OutputPath>HeadersClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /WrapResponses:true /GenerateResponseClasses:false /ResponseClass:ApiResponse /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagWrapResponses>true</NSwagWrapResponses>
<NSwagResponseClass>ApiResponse</NSwagResponseClass>
<NSwagGenerateResponseClasses>false</NSwagGenerateResponseClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\QueryStrings\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagEndToEndTests.QueryStrings.GeneratedCode</Namespace>
<ClassName>QueryStringsClient</ClassName>
<OutputPath>QueryStringsClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\RestrictedControllers\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagEndToEndTests.RestrictedControllers.GeneratedCode</Namespace>
<ClassName>RestrictedControllersClient</ClassName>
<OutputPath>RestrictedControllersClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
<OpenApiReference Include="..\OpenApiTests\Links\Enabled\GeneratedSwagger\swagger.g.json">
<Namespace>OpenApiNSwagEndToEndTests.Links.GeneratedCode</Namespace>
<ClassName>LinksClient</ClassName>
<OutputPath>LinksClient.cs</OutputPath>
<CodeGenerator>NSwagCSharp</CodeGenerator>
<Options>/ClientClassAccessModifier:internal /GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.NSwag /GenerateNullableReferenceTypes:true</Options>
<NSwagClientClassAccessModifier>internal</NSwagClientClassAccessModifier>
<NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
<NSwagAdditionalNamespaceUsages>JsonApiDotNetCore.OpenApi.Client.NSwag</NSwagAdditionalNamespaceUsages>
<NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
</OpenApiReference>
</ItemGroup>
</Project>

0 comments on commit 5dcfab8

Please sign in to comment.