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

fix(zod-openapi): return Response if response is not text or JSON #853

Merged
merged 3 commits into from
Nov 28, 2024

Conversation

yusukebe
Copy link
Member

@yusukebe yusukebe commented Nov 28, 2024

Fixes #842

#852 was a great PR to fix #842. However, type errors should not arise for responses other than HTML. Example:
application/xml. So, the problem will be solved if we set Response to contents other than JSON or Text like the following.

  • JSON - TypedRespose with json
  • Text - TypedResponse with text
  • Others - Response

This PR will correct whether the returned value should be a TypedResponse or a Response based on the specified content type.

Co-authored-by: sushichan044 <mail@sushichan.live>
Copy link

changeset-bot bot commented Nov 28, 2024

🦋 Changeset detected

Latest commit: 3096667

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/zod-openapi Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -1779,21 +1779,21 @@ describe('RouteConfigToTypedResponse', () => {
age: number
},
200,
'json' | 'text'
'json'
Copy link
Member Author

Choose a reason for hiding this comment

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

Since now the TypedResponse only allows json with application/json, I fixed the test.

? ContentType extends `application/${infer Start}json${infer _End}`
? Start extends '' | `${string}+` | `vnd.${string}+`
? TypedResponse<
SimplifyDeepArray<Content> extends JSONValue
Copy link
Member Author

Choose a reason for hiding this comment

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

This is following JSONRespondReturn, which is introduced in hono.

@yusukebe yusukebe marked this pull request as ready for review November 28, 2024 09:14
@yusukebe
Copy link
Member Author

Hi @sushichan044!

What do you think of this PR?

@sushichan044
Copy link
Contributor

@yusukebe Looks good!
Conditions for branching are simple and easy to understand.

@yusukebe
Copy link
Member Author

@sushichan044

Thanks! I'll merge this. But I like your implementation!

@yusukebe yusukebe merged commit a9804af into main Nov 28, 2024
1 check passed
@yusukebe yusukebe deleted the fix/zod-openapi-inferring-response branch November 28, 2024 09:35
@github-actions github-actions bot mentioned this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

using c.html as response gives error in openapi()
2 participants