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

Don't attempt to json encode string types #1479

Closed

Conversation

keslerm
Copy link

@keslerm keslerm commented Sep 5, 2023

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
  • This PR is associated with an existing issue?

Closing issues
close #1394

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there keslerm 👋

Thank you and congrats 🎉 for opening your first PR on this project.✨

We will review the following PR soon! 👀

@keslerm
Copy link
Author

keslerm commented Sep 5, 2023

I'm only really familiar with Express but reviewing the code for the other two types of servers they don't appear to have the same issue Express is having here.

@WoH
Copy link
Collaborator

WoH commented Sep 8, 2023

Hi there, can you please add integration tests to show we have a consistent behavior?

@keslerm
Copy link
Author

keslerm commented Sep 8, 2023

Hi there, can you please add integration tests to show we have a consistent behavior?

I'd love to, I looked around a bit at the tests and it's a lot to digest - could you give me a ballpark spot to look at that I can use as a starting point?

@keslerm keslerm force-pushed the fix/handle-string-return-types branch from 185dc8f to 5688f98 Compare September 8, 2023 16:05
@hpx7
Copy link
Contributor

hpx7 commented Oct 3, 2023

We are running into this issue as well. Is this fine to merge?

@keslerm
Copy link
Author

keslerm commented Oct 3, 2023

@WoH I got side tracked by work, is there anything I need to do on this still?

@WoH
Copy link
Collaborator

WoH commented Oct 3, 2023

Can you check the content type headers in the tests? The body could've been correct before, now we want text/plain not application/json

@keslerm keslerm force-pushed the fix/handle-string-return-types branch from 5688f98 to 306b854 Compare October 4, 2023 00:40
@keslerm
Copy link
Author

keslerm commented Oct 4, 2023

@WoH I added some appropriate calls for each server type (hapi and express required an extra step, koa seemed to do it correctly from the git go)

There are a couple of tests failing as a result of this change however. I looked at them a bit and I'm not entirely sure what is ultimately causing them to fail

tsoa-tests:   3 failing
tsoa-tests:   1) Express Server
tsoa-tests:        Sub resource
tsoa-tests:          parses path parameters from the controller description:
tsoa-tests:      Uncaught AssertionError: expected {} to equal 'main-123'
tsoa-tests:       at /home/rridley/projects/aegiszero/tsoa/tests/integration/express-server.spec.ts:1450:29
tsoa-tests:       at Test.<anonymous> (integration/express-server.spec.ts:1565:11)
tsoa-tests:       at Test.assert (/home/rridley/projects/aegiszero/tsoa/node_modules/supertest/lib/test.js:172:8)
tsoa-tests:       at Server.localAssert (/home/rridley/projects/aegiszero/tsoa/node_modules/supertest/lib/test.js:120:14)
tsoa-tests:       at Object.onceWrapper (node:events:628:28)
tsoa-tests:       at Server.emit (node:events:514:28)
tsoa-tests:       at Server.emit (node:domain:489:12)
tsoa-tests:       at emitCloseNT (node:net:2148:8)
tsoa-tests:       at processTicksAndRejections (node:internal/process/task_queues:81:21)
tsoa-tests: 
tsoa-tests:   2) Express Server
tsoa-tests:        Sub resource
tsoa-tests:          parses path parameters from the controller description and method description:
tsoa-tests:      Uncaught AssertionError: expected {} to equal 'main-123:sub-456'
tsoa-tests:       at /home/rridley/projects/aegiszero/tsoa/tests/integration/express-server.spec.ts:1459:29
tsoa-tests:       at Test.<anonymous> (integration/express-server.spec.ts:1565:11)
tsoa-tests:       at Test.assert (/home/rridley/projects/aegiszero/tsoa/node_modules/supertest/lib/test.js:172:8)
tsoa-tests:       at Server.localAssert (/home/rridley/projects/aegiszero/tsoa/node_modules/supertest/lib/test.js:120:14)
tsoa-tests:       at Object.onceWrapper (node:events:628:28)
tsoa-tests:       at Server.emit (node:events:514:28)
tsoa-tests:       at Server.emit (node:domain:489:12)
tsoa-tests:       at emitCloseNT (node:net:2148:8)
tsoa-tests:       at processTicksAndRejections (node:internal/process/task_queues:81:21)
tsoa-tests: 
tsoa-tests:   3) Inversify Express Server Dynamic Container
tsoa-tests:        can handle get request with no path argument:
tsoa-tests:      Uncaught AssertionError: expected {} to equal '/v1/ManagedTest'
tsoa-tests:       at /home/rridley/projects/aegiszero/tsoa/tests/integration/inversify-dynamic-container.spec.ts:13:24
tsoa-tests:       at Test.<anonymous> (integration/inversify-dynamic-container.spec.ts:41:11)
tsoa-tests:       at Test.assert (/home/rridley/projects/aegiszero/tsoa/node_modules/supertest/lib/test.js:172:8)
tsoa-tests:       at Server.localAssert (/home/rridley/projects/aegiszero/tsoa/node_modules/supertest/lib/test.js:120:14)
tsoa-tests:       at Object.onceWrapper (node:events:628:28)
tsoa-tests:       at Server.emit (node:events:514:28)
tsoa-tests:       at Server.emit (node:domain:489:12)
tsoa-tests:       at emitCloseNT (node:net:2148:8)
tsoa-tests:       at processTicksAndRejections (node:internal/process/task_queues:81:21)

@WoH
Copy link
Collaborator

WoH commented Oct 4, 2023

I'll take a look, first guess is the data is now on res.body, and it's checking/parsing res.data in the tests

@@ -208,6 +208,9 @@ export function RegisterRoutes(app: Router) {
if (data && typeof data.pipe === 'function' && data.readable && typeof data._read === 'function') {
response.status(statusCode || 200)
data.pipe(response);
} else if (data && typeof data === 'string') {
Copy link
Collaborator

@WoH WoH Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data could be '' which is nullish, do we want this to fall through to 204 no content?

Copy link

github-actions bot commented Nov 4, 2023

This PR 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

@github-actions github-actions bot added the Stale label Nov 4, 2023
@github-actions github-actions bot closed this Nov 10, 2023
@WoH WoH reopened this Nov 10, 2023
@WoH WoH removed the Stale label Nov 10, 2023
Copy link

This PR 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

@github-actions github-actions bot added the Stale label Dec 11, 2023
@github-actions github-actions bot closed this Dec 17, 2023
@david-loe
Copy link

david-loe commented Feb 23, 2024

Any plans on reopening this?
@WoH '' could create a 204 in my opinion

@xseman
Copy link
Contributor

xseman commented Oct 6, 2024

@WoH Is this still being worked on? I'd love to help if it's still planned.

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

Successfully merging this pull request may close these issues.

Question: how to return text/plain response
5 participants