lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.32k stars 481 forks source link

Reasoning for always setting defaultNumberType #1613

Closed Marcelo00 closed 1 month ago

Marcelo00 commented 2 months ago

Sorting

Expected Behavior

If you have the following property in an interface

export interface ExampleInterface {
   numberType: number;
}

I would expect TSOA to not add a format option to the corresponding type in the openapi.yaml:

numberType:
   type: number

Additionally, I do not have the optional defaultNumberType config set in my TSOA config.

Current Behavior

This is the result I will get:

numberType:
   type: number
   format: double

The source of this behavior comes from lines 148-150 in packages/cli/src/cli.ts - see this pull request. If you not set defaultNumberType, it will just assume a double type for the numberType. In this context I wanted to get some clarification on why this behavior is the default approach?

For our use case, we would like to just have the type without the optional format. In downstream tasks it would lead to some confusion in the validation as the input 0 will be validated against the type double in the current default behavior. For languages like Python, it would lead to an error with such an input because the 0 is an integer. Removing format: double would lead to a successful validation as only number consists of floating numbers and integers.

Possible Solution

Remove the respective lines.

Steps to Reproduce

      1. 4.

Context (Environment)

Version of the library: 6.2.0 Version of NodeJS: 18.18.0

Detailed Description

Breaking change?

github-actions[bot] commented 2 months ago

Hello there Marcelo00 👋

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

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

github-actions[bot] commented 1 month ago

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