Skip to content

Commit

Permalink
improvement: use struct spec to avoid double % in struct inspect (#613
Browse files Browse the repository at this point in the history
)

* improvement: use struct spec to avoid double `%` in struct inspect

currently, inspecting an `OpenApiSpex.Schema` looks like this:

`%OpenApiSpex.Schema%{type: :object}`

with the new change, it looks like this:

`%OpenApiSpex.Schema{type: :object}`

which allows copy/pasting the struct
  • Loading branch information
zachdaniel authored Jul 7, 2024
1 parent 5d3e70f commit 5a79def
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/open_api_spex/inspect/for_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ defimpl Inspect, for: OpenApiSpex.Schema do
end)
|> Map.new()

concat(["%OpenApiSpex.Schema", to_doc(map, opts)])
infos =
for %{field: field} = info <- OpenApiSpex.Schema.__info__(:struct),
Map.has_key?(map, field),
do: info

Inspect.Map.inspect(map, to_doc(OpenApiSpex.Schema, opts), infos, opts)
end
end
2 changes: 1 addition & 1 deletion test/inspect/for_schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ defmodule OpenApiSpex.Inspect.ForSchemaTest do
test "inspect schema" do
schema = %Schema{title: "Hello"}
output = inspect(schema)
assert output == "%OpenApiSpex.Schema%{title: \"Hello\"}"
assert output == "%OpenApiSpex.Schema{title: \"Hello\"}"
end
end

0 comments on commit 5a79def

Please sign in to comment.