-
Notifications
You must be signed in to change notification settings - Fork 54
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
Invalid Typescript schema requested for POST #3
Comments
Thanks @bnhovde It is definitely a bug, wasn't anticipating body to be a top level array... Will fix in next version - thinking for this special case the arg would be typed as type Arg = {
formId: string
__body: {
identifier: string
value?: number | null | undefined
observedAt?: string | null | undefined
}[]
} |
@bnhovde as a workaround you could try submitForm(
Object.assign(
[ { identifier: "id", value: 1, observedAt: "now" } ], // body array first
{ formId: "form1" } // param next
)
) You still get type safety on the required properties. |
@ajaishankar That makes sense! Thanks for the workaround. I suppose it's a bit of an edge case. It feels intuitive to pass the POST/PUT-body as the second argument of a fetcher, e.g Amazing work, I found no other hiccups implementing this. |
Thanks @bnhovde! Glad to know it works well on real world schemas. Closing this issue for now since there is a workaround. Will reopen if more users have schemas with similar array based request bodies. |
Hate to say it, but I think I might have evidence that top level arrays in a body is a fairly common usecase: RFC 6902 - Section 3. That being said, it does look like the workaround and the utility function |
Hi, love this initiative. It's allowed me to remove hundreds of lines of code.
I've got a strange problem trying to wire up a POST request using the standard approach:
export const submitForm = fetcher.path('/form/{formId}/submit').method('post').create();
The Swagger API definition requests
formId
as a parameter and formFields as the post body, but the returned function requests the following input, a intersection between an object and an array, which is impossible to provide:I might be doing something wrong, but it seems like a potential bug. Here's the type for the request:
The text was updated successfully, but these errors were encountered: