-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings: ExcludeDeprecated + ExcludeByPathRegex: Tests for typescrip…
…t added
- Loading branch information
1 parent
481e230
commit 9862560
Showing
3 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/NSwag.CodeGeneration.TypeScript.Tests/TypeScriptClientSettingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Newtonsoft.Json; | ||
using NJsonSchema.CodeGeneration.TypeScript; | ||
using NSwag.Generation.WebApi; | ||
using System.Runtime.Serialization; | ||
using Xunit; | ||
using NJsonSchema.NewtonsoftJson.Converters; | ||
using NJsonSchema; | ||
using NJsonSchema.NewtonsoftJson.Generation; | ||
using static NSwag.CodeGeneration.TypeScript.Tests.OperationParameterTests; | ||
|
||
namespace NSwag.CodeGeneration.TypeScript.Tests | ||
{ | ||
public class TypeScriptClientSettingTests | ||
{ | ||
public class FooController | ||
{ | ||
[Route("test")] | ||
public string Test(int a, int? b) | ||
{ | ||
return null; | ||
} | ||
|
||
[Obsolete("Obsolete endpoint for testing")] | ||
[Route("obsoleteEndpoint")] | ||
public string ObsoleteEndpoint(int a, int? b) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task When_depreacted_endpoints_are_excluded_the_client_will_not_generate_these_endpoint() | ||
{ | ||
// Arrange | ||
var swaggerGenerator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings | ||
{ | ||
SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings() | ||
}); | ||
|
||
var document = await swaggerGenerator.GenerateForControllerAsync<FooController>(); | ||
var generator = new TypeScriptClientGenerator(document, new TypeScriptClientGeneratorSettings | ||
{ | ||
ExcludeDeprecated = true | ||
}); | ||
|
||
// Act | ||
var code = generator.GenerateFile(); | ||
|
||
// Assert | ||
Assert.DoesNotContain("obsoleteEndpoint", code); | ||
Assert.DoesNotContain("deprecated", code); | ||
Assert.Contains("test", code); // contains other endpoint | ||
} | ||
|
||
[Fact] | ||
public async Task When_regex_is_set_to_excluded_endpoints_the_client_will_not_generate_these_endpoint() | ||
{ | ||
// Arrange | ||
var swaggerGenerator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings | ||
{ | ||
SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings() | ||
}); | ||
|
||
var document = await swaggerGenerator.GenerateForControllerAsync<FooController>(); | ||
var generator = new TypeScriptClientGenerator(document, new TypeScriptClientGeneratorSettings | ||
{ | ||
ExcludeByPathRegex = "test" | ||
}); | ||
|
||
// Act | ||
var code = generator.GenerateFile(); | ||
|
||
// Assert | ||
Assert.DoesNotContain("foo", code); | ||
Assert.Contains("obsoleteEndpoint", code); // contains other endpoint | ||
Assert.Contains("deprecated", code); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters