improperly handles optional``` requestBody```
KotoriK opened this issue · 1 comments
KotoriK commented
For example a typescript definition file generated by openapi-typescript
:
export interface paths{
'/api/auth/login': {
post: {
requestBody?: {
content: {
'application/json': components['schemas']['LoginInput'];
'text/json': components['schemas']['LoginInput'];
'application/*+json': components['schemas']['LoginInput'];
};
};
responses: {
/** @description Success */
200: never;
};
};
};
}
In this case, below code will throw a type error, indicating body
should be undefined
:
createFetch<paths>('/api/auth/login',{body:{name:string}})
after changing requestBody
to required, body
can be infered correctly.
Expecting behaviour
optional requestBody
should be infer as ${RequestBodySchema} | undefined
instead of undefined
Reproduce link
https://codesandbox.io/s/openapi-fetch-optional-requestbody-8e699k
it cannot be compiled in browser because of some typescript issue, please download and setup on local.
drwpow commented
Can confirm this is happening. Omitting the body works, but providing it raises a TS error. Will work on a fix