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

Deleted payload when repeated in body #9

Open
doktordirk opened this issue Jan 2, 2022 · 0 comments
Open

Deleted payload when repeated in body #9

doktordirk opened this issue Jan 2, 2022 · 0 comments

Comments

@doktordirk
Copy link

doktordirk commented Jan 2, 2022

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
  })
}
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

No branches or pull requests

1 participant