Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/open_api_typesense/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 17 additions & 0 deletions test/default_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down