Skip to content

Commit 02018c8

Browse files
committed
fix: use conn.private, not conn[:private]
test: add tests for calling the open api controller
1 parent bd8d6ee commit 02018c8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/ash_json_api/controllers/open_api.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if Code.ensure_loaded?(OpenApiSpex) do
1919

2020
@doc false
2121
def spec(conn, opts) do
22-
phoenix_endpoint = opts[:phoenix_endpoint] || conn[:private][:phoenix_endpoint]
22+
phoenix_endpoint = opts[:phoenix_endpoint] || conn.private[:phoenix_endpoint]
2323

2424
opts
2525
|> Keyword.put(:phoenix_endpoint, phoenix_endpoint)

test/acceptance/open_api_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule Test.Acceptance.OpenApiTest do
22
use ExUnit.Case, async: true
3+
use Plug.Test
34
alias OpenApiSpex.{OpenApi, Schema}
45

56
defmodule Bio do
@@ -253,6 +254,19 @@ defmodule Test.Acceptance.OpenApiTest do
253254
%{open_api_spec: api_spec}
254255
end
255256

257+
test "spec can be fetched from the controller", %{open_api_spec: api_spec} do
258+
assert :get
259+
|> conn("/open_api")
260+
|> AshJsonApi.Controllers.OpenApi.call(
261+
domains: [Blogs],
262+
modify_open_api: {__MODULE__, :modify_open_api, []}
263+
)
264+
|> sent_resp()
265+
|> elem(2)
266+
|> Jason.decode!()
267+
|> Kernel.==(Jason.decode!(Jason.encode!(api_spec)))
268+
end
269+
256270
test "modify option is honored", %{open_api_spec: api_spec} do
257271
assert api_spec.info.title == "foobar"
258272
end

0 commit comments

Comments
 (0)