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

How use typia in combination with tsoa #1568

Closed
2 of 4 tasks
cesco69 opened this issue Feb 21, 2024 · 2 comments
Closed
2 of 4 tasks

How use typia in combination with tsoa #1568

cesco69 opened this issue Feb 21, 2024 · 2 comments
Labels

Comments

@cesco69
Copy link
Contributor

cesco69 commented Feb 21, 2024

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

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit
Copy link

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.👀

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant