question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid autogenerated response status in Controllers

See original GitHub issue

Sorting

  • I’m submitting a …

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn’t already been submit

Expected Behavior

Hi! First of all, congrats for this great project

I have a little problem with the infered response status (and response object):

All my Controllers entry-point are void methods that can return a variety of responses (200 with content, 204 without content, 400 with error message…) When a use annotations with some endpoint that return a response, tsoa infers automatically that, being a void method, the status code is 204 with no-content, even if I use the annotation @Response<MyResponse>(200, ‘some description’)

This is an example of my controller

  @Get()
  @Response<UserGetResponse>(200)
  public async execute(): Promise<void> {
    this.sendResponse(UserGetController.toResponse({user: undefined}));
  }

  protected sendResponse(params: Record<string, unknown>, statusCode?: number): void {
    this.response.status(statusCode || 200).json(params);
  }

Current Behavior

With this code, currently tsoa generate two kind of responses instead of one (this is the swagger.json generated):

"paths": {
        "/user": {
            "get": {
                "operationId": "Execute",
                "responses": {
                    "200": {
                        "description": "",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/UserGetResponse"
                                }
                            }
                        }
                    },
                    "204": {
                        "description": "No content"
                    }
                },
                "tags": [
                    "User"
                ],
                "security": [],
                "parameters": []
            }
        }
    },

Possible Solution

I would like to find a way to ignore or override the inferred response (the status code 204 in my case) but I couldn’t find anything in the Docs or the examples ¿It’s possible?

Context (Environment)

Version of the library: 4.1.2 Version of NodeJS: 16 Version of Express: 4.17.0

  • Confirm you were using yarn not npm

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
github-actions[bot]commented, Sep 20, 2022

Hello there pabloleonalcaide 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

0reactions
pconecommented, Dec 6, 2022

I’m running into the same issue, I’m trying to use tsoa to generate openapi documentation for an API, but I’m not using the runtime tsoa functionality. I’ve got methods that conform to (input: In) => Success | SomeError | NotFound, and I’ve decorated it with

@Post()
@Response<Success>(201, "description") 
@Response<SomeError> (400, "description") 
@Response<NotFound>(404, "description") 

This almost does what I need it to, except it generates an extra 200 Ok response in the documentation which I don’t want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Should the Controller interact directly with the auto-generated ...
I'm working on a project using MVC and Entity Framework. For now, what I am doing is that I am using the Controllers...
Read more >
Return HTML from controller #224 - lukeautry/tsoa - GitHub
I have a couple endpoints where I would like to return HTML ... eslint-disable */ // WARNING: This file was auto-generated with tsoa....
Read more >
Resolving view state message authentication code (MAC) errors
Describes view state and how to resolve message authentication code (MAC) errors.
Read more >
Generic and dynamically generated controllers in ASP.NET ...
Approach 1: Inheriting from the generic controller ... The simplest solution would be to make child controllers, that inherit from BaseController< ...
Read more >
Hide actions from Swagger / OpenAPI documentation in ASP ...
By adding this attribute on a controller or action and specifying IgnoreApi = true , it gets hidden from auto-generated documentation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found