RobinTail / express-zod-api

A Typescript framework to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.
https://ez.robintail.cz
MIT License
634 stars 35 forks source link

Error in frontend client usage exemple #2177

Closed HenriJ closed 2 hours ago

HenriJ commented 4 hours ago

Description

The usage example in the generated client tries to find out if the response should be parsed as JSON or text using this line of code:

const parser = `${method} ${path}` in jsonEndpoints ? "json" : "text";

But path in this context is not a MethodPath but the path where the parameters have already been replaced by their value. Because of that, the "json" parser will never be selected

Expected

It's not clear to me what the cleanest fix would be. I suppose Implementation could accept a 4th param that would be the original MethodPath ?

Reproduction

Try to use the generated client with a JSON endpoint that has a path parameter

Context

Additional context

Love this lib! Really incredible work!

RobinTail commented 4 hours ago

Good point... checking why it still works...

RobinTail commented 4 hours ago

Thank you for reporting this, @HenriJ . And for the donation. It seems that I missed the path parameters case in my tests.

RobinTail commented 3 hours ago

In order to preserve the backwards compatibility, the suggested Implementation will use the content-type header of the actual response instead of jsonEndpoints dictionary.

RobinTail commented 2 hours ago

🚀 v20.21.2, @HenriJ Thank you for the contribution