RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.24k forks source link

Reusable request bodies are not handled correctly #2747

Open i-sinister opened 4 years ago

i-sinister commented 4 years ago

According to OpenApi 3.0 spec "reusable request bodies" are supported. However with latest NSwag (version 13.3.0.0) controllers are not generated correctly - action argument is always of type 'object':

openapi: '3.0.0'
paths:
  /bugs:
    post:
      summary: Returns list on NSwagStudio bugs
      requestBody:
        $ref: "#/components/requestBodies/NSwagStudioBug"
      responses:
        '200':
          $ref: '#/components/responses/NoContent'
components:
  requestBodies:
    description: Describes NSwagStudio bug
    required: true
    content:
      application/json:
        schema:
          type: string
  responses:
    NoContent:
      description: No content

and here is the generated code generated for action:

[Microsoft.AspNetCore.Mvc.HttpPost, Microsoft.AspNetCore.Mvc.Route("bugs")]
public System.Threading.Tasks.Task Bugs([Microsoft.AspNetCore.Mvc.FromBody] object body)
{
    return _implementation.BugsAsync(body);
}

Expected: body type should be 'string'.

JordyThien commented 2 years ago

Seems like a duplicate of https://github.com/RicoSuter/NSwag/issues/2122 However, the problem is not fixed