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

Better support for json-like input and outputs in the schema #92

Merged
merged 12 commits into from
Oct 31, 2023
Merged

Conversation

Coobaha
Copy link
Owner

@Coobaha Coobaha commented Oct 29, 2023

Continuation of #89

request body is typed as json-like structure, while response body is not fully casted and doesn't cast original types from schema.

@qwelias, it was a nice puzzle! Could you please verify if it meets your expectations, works correctly, and covers all your cases? Thank you.

The commit refactors the code by updating the type parameter name from "DoNotCastToPrimitive" to "CastBehavior" in order to improve code clarity and consistency.
@qwelias
Copy link
Collaborator

qwelias commented Oct 29, 2023

Thanks a lot, will check out within a day

test/fixtures.ts Show resolved Hide resolved
test/test_schema.ts Show resolved Hide resolved
src/type-utils.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@qwelias qwelias left a comment

Choose a reason for hiding this comment

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

looks great, thanks

@Coobaha Coobaha merged commit 4d33197 into main Oct 31, 2023
4 checks passed
@Coobaha Coobaha deleted the jsonify branch October 31, 2023 03:05
@Coobaha
Copy link
Owner Author

Coobaha commented Oct 31, 2023

@qwelias I released a @coobaha/[email protected] with this changes

I noticed one regression for undefined values in objects. I think it should make Jsonlike key optional, like:

type Obj = {
  a: string | null | undefined
}

type ResultJsonLikeType = {
 a?: string | null
}
declare const obj: Obj;

// works as JSON.strinigfy(obj) will remove undefined values
req.send(obj) // results in a {} response

#97

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.

2 participants