Open brotheroftux opened 4 years ago
Seams reasonable to wrap everything in the generator, do you want to open a PR for this?
Sure, if by wrapping everything in generator you mean just adding encodeURIComponent
to the built-in generator's code for every path parameter. I'm not quite sure if this feature needs to be configurable — there might be a use case where a developer would want to provide, say, their own encoding function — so maybe we might want to add this option for the config.
I think it's a reasonable behavior, I don't really see any drawback of using encodeURI everytime. If somebody have a need for more config over there, let's iterate, but for now I'm in favor of keep it simple 😁
Right, I'll open a PR later today then.
@fabien0102 We've got a case where we need the encoding to be RFC 3986 compliant (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent), so I guess I'll be adding configuration support for custom encode functions after all.
Path parameters in the generated code are getting simply interpolated into the resulting path string, which is used in an actual request without any URI encoding (https://github.com/contiamo/restful-react/blob/454db37e029fdd3b8fceb98a6dc977720a91cb0b/src/scripts/import-open-api.ts#L301). Is there a way to somehow enforce encoding for path parameters without having to either write a custom generator or wrap every parameter value in
encodeURIComponent
at call site?Thanks in advance.