lukeautry / tsoa

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

How use typia in combination with tsoa #1568

Closed cesco69 closed 3 months ago

cesco69 commented 4 months ago

typia has a super-fast JSON serialization (typia.json.stringify()) I want to use instead of express.js JSON.stringify

After setup typia

npm install typia
npx typia setup

I have implemented into the controller in this way:

import { Controller, Get, Route, Request } from 'tsoa';
import typia from "typia";

interface TestResponse {
    name: string;
    surname: string;
}

@Route()
export class TestController extends Controller {

    @Get('test')
    public async test(@Request() req: express.Request): Promise<TestResponse> {
        const data = typia.json.stringify<TestResponse>({
            name: 'foo',
            surname: 'bar'
        })
        req.res?.header("Content-Type", "application/json; charset=utf-8")
        req.res?.send(data)
        return null as any
    }
}

I have used this workaround:

        req.res?.header("Content-Type", "application/json; charset=utf-8")
        req.res?.send(data)
        return null as any

for:

  1. return the string from typia.json.stringify as application/json
  2. fix Swagger for the response type is TestResponse

Has tsoa a way for fix implement this code without workaround?

Side note, I think typia can be a feature of tsoa, because it is a huge performance improvment. Typia use fast-json-stringify that is the reasone because fastify is faster than express

Sorting

github-actions[bot] commented 4 months ago

Hello there cesco69 👋

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 3 months 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