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

properly support JSON types when the response is JSON and return raw data when the response is not JSON #1738

Open
2 tasks
kchobantonov opened this issue Jan 5, 2025 · 1 comment · May be fixed by #1739
Open
2 tasks

Comments

@kchobantonov
Copy link

Sorting

  • I'm submitting a ...

    • [ x] bug report
    • feature request
    • support request
  • I confirm that I

    • [x ] used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

  1. Allow when we return from a controller method a null value and the response is json then the null should appear as a body
  2. If the data is a string but the content type is not specified then return the text as is without using json (e.g. quoted string)

Current Behavior

  1. When the result is null with any content type then the response won't have any data
  2. If we return a string without specifying the content type as JSON then the result will be the quoted string

Possible Solution

In expressTemplateService.ts fix the returnHandler to not assume that the response should be always a JSON response,
the same as in the koa and hapi implementations

Steps to Reproduce

  1. Have the following controller method
  @Get('/null-value')
  @Produces('application/json')
  public async getNullValue(): Promise<any> {
    this.setHeader('Content-Type', 'application/json');
    return null;
  }

  1. then make sure that the response body is the text - null

  2. Have the following controller method

  @Get('/string-value')
  @Produces('plain/text')
  public async getNullValue(): Promise<any> {
    this.setHeader('Content-Type', 'plain/text');
    return 'Some String';
  }

  1. then make sure that the response body is the text - Some String and not - "Some String"

Context (Environment)

Version of the library: 6.6.0
Version of NodeJS: v18.19.0

  • Confirm you were using yarn not npm: [x ]

Detailed Description

Breaking change?

@kchobantonov kchobantonov changed the title property support JSON types when the response is JSON and return raw data when the response is not JSON properly support JSON types when the response is JSON and return raw data when the response is not JSON Jan 5, 2025
@kchobantonov
Copy link
Author

fixed by #1739

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