Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default number type configuration #1439

Merged
merged 6 commits into from
Jul 21, 2023

Conversation

PetrKubes97
Copy link
Contributor

Hi, some time back I've asked about default number types, but unfortunately the issue was closed as stale - #1408. I went ahead and implemented it anyway as it is super useful for my project. I think it's quite useful, as double as the default number type isn't suitable, if the backend uses for example number ids for entities. The amount of annotation is then just too damn high.

I wasn't sure how to write proper test for this, as I could find any configuration tests.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
  • This PR is associated with an existing issue?

Closing issues

Put closes #1408

If this is a new feature submission:

  • Has the issue had a maintainer respond to the issue and clarify that the feature is something that aligns with the goals and philosophy of the project?

Potential Problems With The Approach

Test plan

@WoH
Copy link
Collaborator

WoH commented Jun 19, 2023

Is there any way to escape from having integers when I have a ts type number?

IMO that has to be there otherwise it's simpler to just use a custom template.

@PetrKubes97
Copy link
Contributor Author

Not sure what you mean by "escape from having integers when I have a ts type number". When a ts type is number, tsoa defaults to

type: number
format: double

Only if I set the default to integer, it switches to

type: integer,
format: int32,

The default behaviour is unchanged.

@WoH
Copy link
Collaborator

WoH commented Jun 19, 2023

So assume I want to have a double field now:

interface T {
  id: number // this is now fine without @isInt
  amount: number // <--- how do I make this a double ?
}

@PetrKubes97
Copy link
Contributor Author

PetrKubes97 commented Jun 19, 2023

There is a @isDouble annotation already, but it is not documented. That might be the source of confusion. I'm using it in my project and works as expected.

@WoH
Copy link
Collaborator

WoH commented Jun 23, 2023

Makes sense, I wasn't sure if that could override the integer though.
That would certainly be a useful test then.
You can run the Metadata generator directly, i.e. in the metadata tests (Link), or, if you want to test e2e, start from the prepare.ts:
https://github.com/lukeautry/tsoa/blob/master/tests/prepare.ts

@PetrKubes97
Copy link
Contributor Author

@WoH Hi, sorry for the delay. I've added the tests. Had some troubles with different formatting settings, .editorconfig might need some love.

PetrKubes97 and others added 3 commits July 20, 2023 13:56
Co-authored-by: Wolfgang Hobmaier <wolfgang@hey.com>
Co-authored-by: Wolfgang Hobmaier <wolfgang@hey.com>
Co-authored-by: Wolfgang Hobmaier <wolfgang@hey.com>
@WoH WoH merged commit 777a485 into lukeautry:master Jul 21, 2023
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants