openapi-typescript-fetch
openapi-typescript-fetch copied to clipboard
Deleted payload when repeated in body
trafficstars
We have the {id} of the rest api's path also included in the body of the request. That might be a questionable choice, but is as it is.
Unfortunately, atm all values of the path and the query get deleted from the body payload. I must admit I'm not entirely sold on mixing path, query and body into a single object, but if so, deleting values which are specified in the api schema as needed for the request body is a problem (for me).
Can that be solved with like
function getPath(path: string, payload: Record<string, any>) {
return path.replace(/\{([^}]+)\}/g, (_, key) => {
const value = encodeURIComponent(payload[key])
if ( (payload as RequestBody)[key] === undefined ) {
delete payload[key]
}
return value
})
}