Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file modified docs/tutorials/GenerateProxyClientWithCLI/sample.nswag
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<NSwagOperationGenerationMode>$(NSwagOperationGenerationMode)</NSwagOperationGenerationMode>
<NSwagIncludedOperationIds>$(NSwagIncludedOperationIds)</NSwagIncludedOperationIds>
<NSwagExcludedOperationIds>$(NSwagExcludedOperationIds)</NSwagExcludedOperationIds>
<NSwagExcludeDeprecated>$(NSwagExcludeDeprecated)</NSwagExcludeDeprecated>
<NSwagAdditionalNamespaceUsages>$(NSwagAdditionalNamespaceUsages)</NSwagAdditionalNamespaceUsages>
<NSwagAdditionalContractNamespaceUsages>$(NSwagAdditionalContractNamespaceUsages)</NSwagAdditionalContractNamespaceUsages>
<NSwagGenerateOptionalParameters>$(NSwagGenerateOptionalParameters)</NSwagGenerateOptionalParameters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<CurrentOpenApiReference>
<Command Condition="'%(NSwagExcludedOperationIds)' != ''">%(Command) /excludedOperationIds:%(NSwagExcludedOperationIds)</Command>
</CurrentOpenApiReference>
<CurrentOpenApiReference>
<Command Condition="'%(NSwagExcludeDeprecated)' != ''">%(Command) /excludeDeprecated:%(NSwagExcludeDeprecated)</Command>
</CurrentOpenApiReference>
<CurrentOpenApiReference>
<Command Condition="'%(NSwagAdditionalNamespaceUsages)' != ''">%(Command) /additionalNamespaceUsages:%(NSwagAdditionalNamespaceUsages)</Command>
</CurrentOpenApiReference>
Expand Down
56 changes: 56 additions & 0 deletions src/NSwag.CodeGeneration.CSharp.Tests/CSharpClientSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FooController>();
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<FooController>();
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = new System.Net.Http.HttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace MyNamespace

System.Threading.Tasks.Task<object> CreatePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

}
Expand Down Expand Up @@ -218,11 +220,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace MyNamespace

System.Threading.Tasks.Task<object> CreatePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

}
Expand Down Expand Up @@ -218,11 +220,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace MyNamespace

System.Threading.Tasks.Task<object> CreatePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

}
Expand Down Expand Up @@ -218,11 +220,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace MyNamespace

System.Threading.Tasks.Task<object> CreatePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

}
Expand Down Expand Up @@ -218,11 +220,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace MyNamespace

System.Threading.Tasks.Task<object> CreatePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override);

[System.Obsolete]
System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = _httpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = new System.Net.Http.HttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ namespace MyNamespace
}
}

[System.Obsolete]
public virtual System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override)
{
return DeletePersonAsync(@override, System.Threading.CancellationToken.None);
}

[System.Obsolete]
public virtual async System.Threading.Tasks.Task<object> DeletePersonAsync(bool? @override, System.Threading.CancellationToken cancellationToken)
{
var client_ = new CustomNamespace.CustomHttpClient();
Expand Down
Loading
Loading