Haskell-OpenAPI-Code-Generator / Haskell-OpenAPI-Client-Code-Generator

Generate Haskell client code from an OpenAPI 3 specification
46 stars 19 forks source link

fix: de- and encode bodies with utf-8 #65

Closed thomasbach-dev closed 2 years ago

thomasbach-dev commented 2 years ago

The previous implementation using B8.unpack and B8.pack handled UTF-8 characters wrong. For example, using the character î (i-circumflex) in the generated stripeapi library I got:

Invalid UTF-8 characters found in POST body

as B8.pack would not convert the character into UTF-8.

I changed the implementation to use encodeUtf8 and decodeUtf8 from Data.Text.Encoding.

This is the upstream fix for https://github.com/Haskell-OpenAPI-Code-Generator/Stripe-Haskell-Library/issues/9

thomasbach-dev commented 2 years ago

@joelfisch Should I also update the generated code in the example directory? If so, how should I do this?

joel-bach commented 2 years ago

Thank you for creating the PR.

It would be helpful if you could update the example folder with the new code. You can just run the generator with the options -o example/generatedCode specifications/petstore.yaml but be aware that the repository contains a default openapi-configuration.yml which will be picked up automatically if you do not rename or remove it (or provide another configuration). Maybe it would be helpful if we created a file called example-configuration.yml or something like this which contains the following content:

specification: specifications/petstore.yaml
outputDir: example/generatedCode

Then you could just run the generator with --configuration example-configuration.yml. Please note that the generated code will contain many other changes as well because I neglected the updating of the example in the past.

Another thing: The golden files are currently not equivalent to the code generated (or in the case of Common.hs just copied). You can update this using .circleci/test_golden update to get the exact result.

Thank you for your help!

thomasbach-dev commented 2 years ago

I think I addressed all things mentioned above. I reversed the commit history to address your issues first and put my changes on top of them. I also added a small section to the README with instructions how to update examples and golden tests.

thomasbach-dev commented 2 years ago

Ok, I incorporated your suggestions above. Note that I also added *.hs-boot files in the example directory. Ping me if these should be dropped again and rather be ignored.

joel-bach commented 2 years ago

Ok, I incorporated your suggestions above. Note that I also added *.hs-boot files in the example directory. Ping me if these should be dropped again and rather be ignored.

That is absolutely correct. This looks good and I'll merge it. Thanks!