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

POST with same property name in path as well as in body gets removed #21

Open
mattdemichele-pearson opened this issue Apr 5, 2022 · 3 comments

Comments

@mattdemichele-pearson
Copy link

mattdemichele-pearson commented Apr 5, 2022

As an example, say you have a POST endpoint defined as:

POST /api/notes/id/{id}
that expects a body that looks like:

{
  id: 1,
  text: 'xyz'
}

Because the path and the body have a property with the same name, it ends up breaking. In this example, "id" gets put in the path, but then gets removed from the body payload that gets sent in the request.

I narrowed this down to being a problem in getFetchParams(), where the getPath() function ends up deleting keys from the payload. The way the code is written, I see why this is a necessity. I am wondering if there are any suggestions?

One thought I had was to add a third optional parameter to the function that create() returns that can be an array of strings for "keys to persist into body payload"

delete payload[key]

@thebetternewt
Copy link

Having the same issue. Thanks for any consideration.

@mattdemichele-pearson
Copy link
Author

@thebetternewt I submitted a PR #25 for the solution I use in a fork to get around this. Not sure if it will be acceptable to be upstreamed.

@SpazzMarticus
Copy link

Same issue here, but I think path parameters should be handled entirely seperate from the (body) payload.

/petshop/{id}/pets should allow PUTting Dog: { id: 99, name: 'Barky' } (body) to Petshop: { id: 24 } (path parameter)

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

3 participants