Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: use struct spec to avoid double % in struct inspect #613

Merged
merged 3 commits into from
Jul 7, 2024
Merged
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
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 @@ -2,9 +2,9 @@
use ExUnit.Case, async: true
alias OpenApiSpex.Schema

test "inspect schema" do

Check failure on line 5 in test/inspect/for_schema_test.exs

View workflow job for this annotation

GitHub Actions / Test (OTP 25 / Elixir 1.13)

test inspect schema (OpenApiSpex.Inspect.ForSchemaTest)

Check failure on line 5 in test/inspect/for_schema_test.exs

View workflow job for this annotation

GitHub Actions / Test (OTP 23 / Elixir 1.12)

test inspect schema (OpenApiSpex.Inspect.ForSchemaTest)

Check failure on line 5 in test/inspect/for_schema_test.exs

View workflow job for this annotation

GitHub Actions / Test (OTP 23 / Elixir 1.11)

test inspect schema (OpenApiSpex.Inspect.ForSchemaTest)

Check failure on line 5 in test/inspect/for_schema_test.exs

View workflow job for this annotation

GitHub Actions / Test (OTP 23 / Elixir 1.13)

test inspect schema (OpenApiSpex.Inspect.ForSchemaTest)
schema = %Schema{title: "Hello"}
output = inspect(schema)
assert output == "%OpenApiSpex.Schema%{title: \"Hello\"}"
assert output == "%OpenApiSpex.Schema{title: \"Hello\"}"
end
end
Loading