-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
When you return a type with the badly chosen name "ActionResult", where it is a custom class and not the one from MVC, then NSwag doesn't work correcly.
It will map the property to "file" instead of the custom class.
Example code:
[HttpGet("Test")]
public async Task<FakeResponse> GetTest()
{
return new FakeResponse { Result = new ActionResult { Something = "test" } };
}
public class FakeResponse
{
public ActionResult Result { get; set; }
}
public class ActionResult
{
public string Something { get; set; }
}
This will produce the swagger.json without a definition for ActionResult and instead maps the "result" property to "file":
"FakeResponse": {
"type": "object",
"properties": {
"result": {
"type": "file"
}
}
Workaround
If the method would immediately return the ActionResult type, then [ProducesResponseType(typeof(ActionResult), 200)] could have been a workaround. However this cannot be used here since it is a property of the type "FakeResponse" that is returned.
Working workaround: renaming "ActionResult" to anything else; for example "ActionResult2" works.
Version of NSwag toolchain, computer and .NET runtime used
NSwag.AspNetCode 14.6.1 (latest)
NSwag.SwaggerGeneration.WebApi 12.3.0 (latest)
NET 9.0
Expected behavior
I expect a definition for the custom class in the "definitions" part of swagger.json.
I expect it to map to the property "result" (of "FakeResponse") to the custom class and not to "file".