diff --git a/docs/tutorials/GenerateProxyClientWithCLI/generate-proxy-client.md b/docs/tutorials/GenerateProxyClientWithCLI/generate-proxy-client.md
index de1e8b58e..c5b5334db 100644
--- a/docs/tutorials/GenerateProxyClientWithCLI/generate-proxy-client.md
+++ b/docs/tutorials/GenerateProxyClientWithCLI/generate-proxy-client.md
@@ -107,6 +107,7 @@ nswag run sample.nswag /runtime:Net50
"operationGenerationMode": "MultipleClientsFromOperationId",
"includedOperationIds": [ "SampleOperationId" ],
"excludedOperationIds": [],
+ "excludeDeprecated": false,
"generateOptionalParameters": false,
"generateJsonMethods": true,
"parameterArrayType": "System.Collections.Generic.IEnumerable",
diff --git a/docs/tutorials/GenerateProxyClientWithCLI/sample.nswag b/docs/tutorials/GenerateProxyClientWithCLI/sample.nswag
index 796d9b58c..58a283949 100644
Binary files a/docs/tutorials/GenerateProxyClientWithCLI/sample.nswag and b/docs/tutorials/GenerateProxyClientWithCLI/sample.nswag differ
diff --git a/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.props b/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.props
index b5e000249..0fe1b28d0 100644
--- a/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.props
+++ b/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.props
@@ -130,6 +130,7 @@
$(NSwagOperationGenerationMode)
$(NSwagIncludedOperationIds)
$(NSwagExcludedOperationIds)
+ $(NSwagExcludeDeprecated)
$(NSwagAdditionalNamespaceUsages)
$(NSwagAdditionalContractNamespaceUsages)
$(NSwagGenerateOptionalParameters)
diff --git a/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.targets b/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.targets
index a40585721..213877785 100644
--- a/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.targets
+++ b/src/NSwag.ApiDescription.Client/NSwag.ApiDescription.Client.targets
@@ -127,6 +127,9 @@
%(Command) /excludedOperationIds:%(NSwagExcludedOperationIds)
+
+ %(Command) /excludeDeprecated:%(NSwagExcludeDeprecated)
+
%(Command) /additionalNamespaceUsages:%(NSwagAdditionalNamespaceUsages)
diff --git a/src/NSwag.CodeGeneration.CSharp.Tests/CSharpClientSettingsTests.cs b/src/NSwag.CodeGeneration.CSharp.Tests/CSharpClientSettingsTests.cs
index 0fa6f3675..bf07bda9d 100644
--- a/src/NSwag.CodeGeneration.CSharp.Tests/CSharpClientSettingsTests.cs
+++ b/src/NSwag.CodeGeneration.CSharp.Tests/CSharpClientSettingsTests.cs
@@ -20,6 +20,9 @@ public object CreatePerson(bool @override = false)
return null;
}
+#pragma warning disable S1133 // Deprecated code should be removed
+ [Obsolete("Testing generation of obsolete endpoints")]
+#pragma warning restore S1133 // Deprecated code should be removed
public object DeletePerson(bool @override = false)
{
return null;
@@ -413,5 +416,58 @@ await VerifyHelper.Verify(code)
.UseParameters(excludedOperationIds.Length);
CSharpCompiler.AssertCompile(code);
}
+
+ [Fact]
+ public async Task When_depreacted_endpoints_are_excluded_the_client_should_not_generate_these_endpoint()
+ {
+ // Arrange
+ var swaggerGenerator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings
+ {
+ SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings()
+ });
+
+ var document = await swaggerGenerator.GenerateForControllerAsync();
+ var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings
+ {
+ GenerateClientClasses = true,
+ ExcludeDeprecated = true
+ });
+
+ // Act
+ var code = generator.GenerateFile();
+
+ // Assert
+ Assert.DoesNotContain("DeletePerson", code);
+ Assert.DoesNotContain("Obsolete", code);
+ await VerifyHelper.Verify(code);
+ CSharpCompiler.AssertCompile(code);
+ }
+
+ [Fact]
+ public async Task When_depreacted_endpoints_are_excluded_the_client_should_still_generate_explicitly_included_endpoints()
+ {
+ // Arrange
+ var swaggerGenerator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings
+ {
+ SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings()
+ });
+
+ var document = await swaggerGenerator.GenerateForControllerAsync();
+ var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings
+ {
+ GenerateClientClasses = true,
+ ExcludeDeprecated = true,
+ IncludedOperationIds = ["Foo_DeletePerson"]
+ });
+
+ // Act
+ var code = generator.GenerateFile();
+
+ // Assert
+ Assert.Contains("DeletePerson", code);
+ Assert.Contains("Obsolete", code);
+ await VerifyHelper.Verify(code);
+ CSharpCompiler.AssertCompile(code);
+ }
}
}
\ No newline at end of file
diff --git a/src/NSwag.CodeGeneration.CSharp.Tests/Snapshots/CSharpClientSettingsTests.WhenUsingBaseUrl_ButNoProperty_ThenPropertyIsNotUsedAndFieldIsGenerated.verified.txt b/src/NSwag.CodeGeneration.CSharp.Tests/Snapshots/CSharpClientSettingsTests.WhenUsingBaseUrl_ButNoProperty_ThenPropertyIsNotUsedAndFieldIsGenerated.verified.txt
index 727b7f20e..b2bdee072 100644
--- a/src/NSwag.CodeGeneration.CSharp.Tests/Snapshots/CSharpClientSettingsTests.WhenUsingBaseUrl_ButNoProperty_ThenPropertyIsNotUsedAndFieldIsGenerated.verified.txt
+++ b/src/NSwag.CodeGeneration.CSharp.Tests/Snapshots/CSharpClientSettingsTests.WhenUsingBaseUrl_ButNoProperty_ThenPropertyIsNotUsedAndFieldIsGenerated.verified.txt
@@ -193,11 +193,13 @@ namespace MyNamespace
}
}
+ [System.Obsolete]
public virtual System.Threading.Tasks.Task