Skip to content

Reusable request bodies are not handled correctly #2747

@i-sinister

Description

@i-sinister

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions