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.

How to return integer from method call

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

I want a controller method to return an int32. I didn’t find any documented way to do this. JSDoc annotation /** @isInt */ works for parameters and number fields of structures, but not for response bodies (or at least it’s not documented).

"responses": {
  "200": {
    "description": "Ok",
    "content": {
      "application/json": {
        "schema": {
          "type": "integer",
          "format": "int32"
        }
      }
    }
}

How do you achieve this?

Context (Environment)

Version of the library: 4.1.1 Version of NodeJS: 12.22.12

  • Confirm you were using yarn not npm: [X]

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
szekelyiszcommented, Jul 27, 2022

Found a hacky workaround.

import { Controller, Get, Route } from "tsoa";

/**
 * @isInt
 */
type Integer = number;

@Route("/")
export class MyController extends Controller {
  @Get("/")
  public async get(): Promise<Integer> {
    return Promise.resolve(1);
  }
}

which generates

  "components": {
    "schemas": {
      "Integer": {
        "type": "integer",
        "format": "int32"
      },
    }
  }

  "paths": {
    "/": {
      "get": {
        "operationId": "Get",
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Integer"
                }
              }
            }
          }
        },
        "security": [],
        "parameters": []
      }
    }
  }
0reactions
github-actions[bot]commented, Oct 9, 2022

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to return an Int from one method to another in java
So we define variable x in our main method and passes it to the getNumber method, which returns the square of received variable....
Read more >
Returning a Value from a Method (The Java™ Tutorials ...
whichever occurs first. You declare a method's return type in its method declaration. Within the body of the method, you use the return...
Read more >
Returning Values From Methods (Java) - Geek Tech Stuff
The above example will return the integer 4 to the main method. The below methods so various examples of the returns including how...
Read more >
Java Return Keyword - Javatpoint
Java return keyword is used to complete the execution of a method. The return followed by the appropriate value that is returned to...
Read more >
2.5. Calling Methods that Return Values — CS Java
Some methods return values. · To use the return value when calling a method, it must be stored in a variable or used...
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