You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried to generate controller code (using openApiToCSharpController) from following OpenAPI specification. But it seems, that the POST request body is mapped to an object parameter each time. And not using the referenced schema definition's type.
Hint: Without the $ref: "#/components/requestBodies/Room" (using the Room schema directly) the Room type is used as expected.
It generates:
[HttpPost, Route("rooms", Name = "createRoom")]
public abstract System.Threading.Tasks.Task<Room> CreateRoom([FromBody] [BindRequired] Room body);
Are there any settings affecting the request body mapping?
Thanks in advance for any further information.
Generated controller base class with create method:
[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")]
public abstract class RoomsControllerBase : ControllerBase
{
/// <returns>single room</returns>
[HttpPost, Route("rooms", Name = "createRoom")]
public abstract System.Threading.Tasks.Task<Room> CreateRoom([FromBody] object? body = null);
}
The source OpenAPI specification used for the test:
+1
I've also hit this when generating a C# client.
The spec allows for requestBody to be either a Request Body Object, or a Reference Object.
So the problem is the implementation not conforming to the standard.
Eruzo
linked a pull request
Feb 6, 2024
that will
close
this issue
I've tried to generate controller code (using
openApiToCSharpController
) from following OpenAPI specification. But it seems, that thePOST
request body is mapped to an object parameter each time. And not using the referenced schema definition's type.Hint: Without the
$ref: "#/components/requestBodies/Room"
(using theRoom
schema directly) theRoom
type is used as expected.It generates:
Are there any settings affecting the request body mapping?
Thanks in advance for any further information.
Generated controller base class with create method:
The source OpenAPI specification used for the test:
The text was updated successfully, but these errors were encountered: