Giter Site home page Giter Site logo

Number type and decimal about tsoa HOT 7 CLOSED

lukeautry avatar lukeautry commented on May 20, 2024
Number type and decimal

from tsoa.

Comments (7)

isman-usoh avatar isman-usoh commented on May 20, 2024 3

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> {...}
}

from tsoa.

lukeautry avatar lukeautry commented on May 20, 2024

Hmm, good call. It should probably be a float; will get that change in soon.

from tsoa.

dpinart-uxland avatar dpinart-uxland commented on May 20, 2024

I can't make it work
`export class MonitorController {

@Get()
/**
 * @isInt limit
 * @isInt offset
 */
findMonitors(@Query() limit: number, @Query()offset: number, @Query() searchString?: string): Promise<QueryResponse<Monitor>>{
    return Promise.resolve(<QueryResponse<Monitor>>{included: [], currentPage: 1, lastPage: true, firstPage: true, })
}

}`

and the swagger gnerated is:
"parameters": [ { "in": "query", "name": "limit", "required": true, "format": "double", "type": "number" }, { "in": "query", "name": "offset", "required": true, "format": "double", "type": "number" }, { "in": "query", "name": "searchString", "required": false, "type": "string" } ]

from tsoa.

dgreene1 avatar dgreene1 commented on May 20, 2024

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?

from tsoa.

dpinart-uxland avatar dpinart-uxland commented on May 20, 2024

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

from tsoa.

WoH avatar WoH commented on May 20, 2024

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 👍

from tsoa.

mrl5 avatar mrl5 commented on May 20, 2024

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 {

swagger.json after above changes:

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 Year declaration and using number instead:

-        @Path() year: Year,
+        @Path() year: number,

update:
I guess the catch is that type Year was declared also in external dependency and used in eventService.ts -> swagger definition was taken from that one ...

from tsoa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.