diff --git a/CHANGELOG.md b/CHANGELOG.md index 603b222..97244f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## major.minor.patch (yyyy.mm.dd) +### Fixed + +* Do not attach a body to bodyless requests. `encode_body/1` serialized a nil body to the literal `"null"`, so every GET/DELETE carried a JSON body. Older HTTP clients dropped it, but Req >= 0.7 transmits it and Typesense returns 404 for a GET-with-body (e.g. `get_collection` on `/collections/:name`), breaking collection existence checks and reindexing. + ## 1.3.5 (2026.06.09) ### Chore diff --git a/lib/open_api_typesense/client.ex b/lib/open_api_typesense/client.ex index 7488ec1..aa7c757 100644 --- a/lib/open_api_typesense/client.ex +++ b/lib/open_api_typesense/client.ex @@ -123,6 +123,14 @@ defmodule OpenApiTypesense.Client do |> scrub_data() case {opts[:request], body} do + # No request-body spec and no body (e.g. GET/DELETE) — send no body at all. + # Encoding `nil` to the literal "null" makes bodyless requests carry a JSON body, which + # older HTTP clients silently dropped but Req >= 0.7 transmits. Typesense then returns 404 + # for a GET-with-body on routes like `/collections/:name`, so `get_collection` cannot see a + # collection that exists. Returning nil lets Req omit the body. + {nil, nil} -> + nil + {nil, _} -> Jason.encode_to_iodata!(body) diff --git a/test/default_client_test.exs b/test/default_client_test.exs index 658f7b1..7ea624d 100644 --- a/test/default_client_test.exs +++ b/test/default_client_test.exs @@ -57,6 +57,23 @@ defmodule DefaultClientTest do max_retries: 0 } end + + @tag [ + "30.1": true, + "30.0": true, + "29.0": true, + "28.0": true, + "27.1": true, + "27.0": true, + "26.0": true + ] + test "does not attach a body to bodyless requests" do + # A GET/DELETE with no body must not carry the literal "null" — Req >= 0.7 transmits it and + # Typesense 404s a GET-with-body (e.g. get_collection). See encode_body/1. + req = Client.build_req_client(Connection.new(), url: "/collections/foo", method: :get) + + assert req.body == nil + end end @tag [