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
48 changes: 48 additions & 0 deletions src/NSwag.CodeGeneration.TypeScript.Tests/AxiosTests.cs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests should use

await VerifyHelper.Verify(code);
TypeScriptCompiler.AssertCompile(code);

like above

Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,53 @@
await VerifyHelper.Verify(code);
TypeScriptCompiler.AssertCompile(code);
}

[Fact]

Check failure on line 227 in src/NSwag.CodeGeneration.TypeScript.Tests/AxiosTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

NSwag.CodeGeneration.TypeScript.Tests.AxiosTests.When_typestyle_is_interface_without_handlereferences_will_have_parse_trycatch

Assert.Contains() Failure: Sub-string not found String: "//----------------------\n// <auto-generated>\n// "··· Not found: "try { result200 ="

Check failure on line 227 in src/NSwag.CodeGeneration.TypeScript.Tests/AxiosTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

NSwag.CodeGeneration.TypeScript.Tests.AxiosTests.When_typestyle_is_interface_without_handlereferences_will_have_parse_trycatch

Assert.Contains() Failure: Sub-string not found String: "//----------------------\n// <auto-generated>\n// "··· Not found: "try { result200 ="

Check failure on line 227 in src/NSwag.CodeGeneration.TypeScript.Tests/AxiosTests.cs

View workflow job for this annotation

GitHub Actions / macos-latest

NSwag.CodeGeneration.TypeScript.Tests.AxiosTests.When_typestyle_is_interface_without_handlereferences_will_have_parse_trycatch

Assert.Contains() Failure: Sub-string not found String: "//----------------------\n// <auto-generated>\n// "··· Not found: "try { result200 ="
public async Task When_typestyle_is_interface_without_handlereferences_will_have_parse_trycatch()
{
//// Arrange
var generator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings());
var document = await generator.GenerateForControllerAsync<DiscussionController>();

//// Act
var codeGen = new TypeScriptClientGenerator(document, new TypeScriptClientGeneratorSettings
{
Template = TypeScriptTemplate.Axios,
PromiseType = PromiseType.Promise,
TypeScriptGeneratorSettings =
{
TypeStyle = NJsonSchema.CodeGeneration.TypeScript.TypeScriptTypeStyle.Interface,
HandleReferences = false
}
});
var code = codeGen.GenerateFile();

//// Assert
Assert.Contains("try { result200 =", code);
}

[Fact]
public async Task When_typestyle_is_interface_with_handlereferences_will_have_jsonParse()
{
//// Arrange
var generator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings());
var document = await generator.GenerateForControllerAsync<DiscussionController>();

//// Act
var codeGen = new TypeScriptClientGenerator(document, new TypeScriptClientGeneratorSettings
{
Template = TypeScriptTemplate.Axios,
PromiseType = PromiseType.Promise,
TypeScriptGeneratorSettings =
{
TypeStyle = NJsonSchema.CodeGeneration.TypeScript.TypeScriptTypeStyle.Interface,
HandleReferences = true
}
});
var code = codeGen.GenerateFile();

//// Assert
Assert.Contains("jsonParse(", code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ let resultData{{ response.StatusCode }} = _responseText;
{% if response.UseDtoClass -%}
{{ response.DataConversionCode }}
{% else -%}
result{{ response.StatusCode }} = {% unless response.IsPlainText %}JSON.parse({% endunless %}resultData{{ response.StatusCode }}{% unless response.IsPlainText %}){% endunless %};
try { result{{ response.StatusCode }} = {% unless response.IsPlainText %}JSON.parse({% endunless %}resultData{{ response.StatusCode }}{% unless response.IsPlainText %}){% endunless %}; }
catch(err) { result{{ response.StatusCode }} = resultData{{ response.StatusCode }}; }
{% endif -%}
{% else -%}
{% if response.UseDtoClass or response.IsDateOrDateTime -%}
Expand Down
Loading