[elixir] Fix cookie parameters, header serialization, optional body comma, and undeclared 2xx responses
Merged
NE
2mo ago+1081+1081+0123456789012345678901234567890123456789-92-92-01234567890123456789
Follow-up to #24840, rebased onto master now that it has landed. Fixes remaining bugs in the Elixir client generator; most affect the default Tesla templates, and the last commit carries a header-serialization fix for the req library that was pushed a few minutes after #24840 was merged and so missed that PR.
- Cookie parameters were not generated.
in: cookieparameters producedadd_param(, ...)(invalid Elixir) when required and an empty map value when optional. They now map to:cookie/:cookie_explodedand are rendered into a singlecookieheader, appending to a caller-supplied one (an empty existing header is treated as absent). Values follow the parameter'sexplodeflag: non-exploded arrays comma-join and objects flatten tok1,v1,k2,v2; exploded ones become separate cookie pairs.ParameterFeature.Cookieis no longer excluded, now that the default library supports it. - Array and map header parameters were corrupted. They went through
to_string/1, which treats a list as a charlist, so[3, 4, 5]was sent as the bytes"\x03\x04\x05". Header serialization is now chosen from the parameter's declared type andexplodeflag at generation time, so a scalar always goes throughto_string/1(a charlist stays a string) and only declared collections are serialized as such. Perstyle: simple: arrays comma-join regardless of explode; objects flatten tok1,v1,k2,v2, ork1=v1,k2=v2when exploded. Applied to both the Tesla andreqtemplates. - Missing comma after an optional body. With
prependFormOrBodyParametersand another optional parameter, theoptional_paramsmap lacked a comma after:body => :bodyand did not compile. - Undeclared 2xx responses were reported as errors. Operations declaring only error responses (petstore
deleteOrder: 400 and 404) returned{:error, env}on a successful delete. When no mapping matches, a 2xx now returns{:ok, env}; other unmapped statuses still return{:error, env}. - Sample test titles said
jason_decode/2; the function under test isjson_decode/2.
Verification
mvn test -Dtest='Elixir*': 7 tests pass.samples/client/petstore/elixir:mix compile --warnings-as-errors,mix test(33 tests againstswaggerapi/petstore, including a newrequest_builder_test.exs),mix dialyzerall pass.samples/client/petstore/elixir-req: same,mix test44 tests,mix dialyzerpasses.- Both samples regenerate with no diff (
Samples up-to-dateclean), anddocs/generators/elixir.mdis regenerated. - Cookie and comma paths are not exercised by the petstore spec, so they were additionally checked by generating and compiling ad-hoc specs with required/optional cookie parameters and with
prependFormOrBodyParameters: true.
PR checklist
- Read the contribution guidelines.
- Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
- Run the following to build the project and update samples:
./mvnw clean package,./bin/generate-samples.sh bin/configs/elixir*.yaml,./bin/utils/export_docs_generators.sh. - File the PR against the correct branch:
master. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
cc @wing328 @mrmstn