Description
Description
The middleware throws the following error when neither onRequest()
nor onResponse()
is provided.
"Middleware must be an object with one of onRequest() or onResponse()"
https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/src/index.js#L223
Based on this, I think the type definition below could be improved by making it more explicit and better aligned with the intended behavior: https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/src/index.d.ts#L147
Proposal
It seems like the Middleware
interface might be improved with the following modification:
export type Middleware {
onRequest?: ...;
onResponse: ...;
} | {
onRequest: ...;
onResponse?: ...;
}
This modification ensures that either onRequest or onResponse is required, and this is reflected in the type, allowing the issue to be detected at compile time.
Checklist
- I’m willing to open a PR for this (see CONTRIBUTING.md)