-
Notifications
You must be signed in to change notification settings - Fork 477
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
Number type and decimal #59
Comments
Hmm, good call. It should probably be a float; will get that change in soon. |
declare float/integer in model interface Model {
/**
* @isFloat ErrorMessage
*/
public floatValue: number;
/**
* @isInt ErrorMessage
*/
public intValue: number;
} declare float/integer in parameter class Controller {
/**
* @isFloat floatValue
* @isInt intValue
*/
public async hello(@Query() floatValue: number, @Query() intValue: number): Promise<void> {...}
} |
I can't make it work
}` and the swagger gnerated is: |
I’m reopening so someone can see if this bug really did regress or if there’s simply an issue on @dpinart-uxland’s side. @dpinart-uxland can you please delete all of your output files (like swagger.json) and rerun tsoa then confirm to us that the issue is still occurring? |
I upgraded swagger to spec 3 and it seems to be working now placing the jsDoc at method declaration. I guess for spec 2 (default one) the jsDoc must be placed at parameter declaration level |
Since they both share the same AST parser, both use the format I suggested, the initial implementation was done in 2017 and has changed for both Swagger and OpenAPI. (If I'm wrong, please correct me and I'll certainly take another look) Anyway, glad it worked out 👍 |
I know that it's closed however I was able to reproduce and then fix - I guess it would be nice to share it here in case someone is affected: diff --git a/src/history/eventController.ts b/src/history/eventController.ts
index 3c6d5de..8d50c39 100644
--- a/src/history/eventController.ts
+++ b/src/history/eventController.ts
@@ -12,8 +12,6 @@ import { NotFoundError } from './errors';
*/
type Time = string;
-/**
- * @isInt Year
- */
-type Year = number;
-
@Route('history/event')
export class HistoryEventController extends Controller {
@Get()
@@ -34,10 +32,13 @@ export class HistoryEventController extends Controller {
}
}
+ /**
+ * @isInt year
+ */
@Get('/{year}')
async getEventByYear(
@Res() notFoundResponse: TsoaResponse<404, NotFoundEvent>,
- @Path() year: Year,
+ @Path() year: number,
@Query() lang?: Language,
): Promise<SingleHistoryEvent> {
try {
diff --git a/spec/swagger.json b/spec/swagger.json
index 0431628..581d309 100644
--- a/spec/swagger.json
+++ b/spec/swagger.json
@@ -529,7 +529,8 @@
"name": "year",
"required": true,
"schema": {
- "$ref": "#/components/schemas/Year"
+ "format": "int32",
+ "type": "integer"
}
},
{ so the part that was needed in order to take effect was dropping - @Path() year: Year,
+ @Path() year: number, update: |
We can not use parameters validation with number if we expect float/decimal because there are always parsed as int...
Change to parseFloat maybe as float is a superset of int. Or Maybe implements a Type('float') decorator or something.
Best regards.
The text was updated successfully, but these errors were encountered: