Skip to content

Commit

Permalink
use Map.get
Browse files Browse the repository at this point in the history
  • Loading branch information
msutkowski committed Dec 16, 2023
1 parent 9deee85 commit 81a7fc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions lib/open_api_spex/test/test_assertions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ defmodule OpenApiSpex.TestAssertions do
case operation_lookup[operation_id] do
nil ->
flunk(
"Failed to resolve schema. Unable to find a response for operation_id: #{operation_id} for response status code: #{conn.status}"
"Failed to resolve a response schema for operation_id: #{operation_id} for status code: #{conn.status}"
)

operation ->
Expand All @@ -157,13 +157,12 @@ defmodule OpenApiSpex.TestAssertions do
content_type = Utils.content_type_from_header(conn, :response)

resolved_schema =
get_in(operation, [
Access.key!(:responses),
Access.key!(conn.status),
Access.key!(:content),
content_type,
Access.key!(:schema)
])
operation
|> Map.get(:responses, %{})
|> Map.get(conn.status, %{})
|> Map.get(:content, %{})
|> Map.get(content_type, %{})
|> Map.get(:schema)

if is_nil(resolved_schema) do
flunk(
Expand Down
2 changes: 1 addition & 1 deletion test/test_assertions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule OpenApiSpex.TestAssertionsTest do
rescue
e in ExUnit.AssertionError ->
assert e.message =~
"Failed to resolve schema. Unable to find a response for operation_id: not_a_real_operation_id for response status code: 200"
"Failed to resolve a response schema for operation_id: not_a_real_operation_id for status code: 200"
end
end

Expand Down

0 comments on commit 81a7fc5

Please sign in to comment.