openapi-typescript-fetch icon indicating copy to clipboard operation
openapi-typescript-fetch copied to clipboard

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

Open mattdemichele-pearson opened this issue 2 years ago • 3 comments

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"

https://github.com/ajaishankar/openapi-typescript-fetch/blob/b62ee714e645c14b8e07c98aaaa53880e7d6c847/src/fetcher.ts#L51

mattdemichele-pearson avatar Apr 05 '22 23:04 mattdemichele-pearson

Having the same issue. Thanks for any consideration.

thebetternewt avatar Apr 29 '22 14:04 thebetternewt

@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.

mattdemichele-pearson avatar Apr 29 '22 14:04 mattdemichele-pearson

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)

SpazzMarticus avatar Nov 17 '22 14:11 SpazzMarticus