Skip to content

Commit b477928

Browse files
committed
show value on failing pattern
1 parent a064054 commit b477928

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/open_api_spex/schema.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ defmodule OpenApiSpex.Schema do
421421
:ok
422422
423423
iex> OpenApiSpex.Schema.validate(%OpenApiSpex.Schema{type: :string, pattern: "(.*)@(.*)"}, "joegmail.com", %{})
424-
{:error, "#: Value does not match pattern: (.*)@(.*)"}
424+
{:error, "#: Value \\"joegmail.com\\" does not match pattern: (.*)@(.*)"}
425425
"""
426426
@spec validate(Schema.t | Reference.t, any, %{String.t => Schema.t | Reference.t}) :: :ok | {:error, String.t}
427427
def validate(schema, val, schemas), do: validate(schema, val, "#", schemas)
@@ -555,7 +555,7 @@ defmodule OpenApiSpex.Schema do
555555
defp validate_pattern(%{pattern: regex = %Regex{}}, val, path) do
556556
case Regex.match?(regex, val) do
557557
true -> :ok
558-
_ -> {:error, "#{path}: Value does not match pattern: #{regex.source}"}
558+
_ -> {:error, "#{path}: Value #{inspect(val)} does not match pattern: #{regex.source}"}
559559
end
560560
end
561561

test/open_api_spex_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ defmodule OpenApiSpexTest do
6161

6262
conn = OpenApiSpexTest.Router.call(conn, [])
6363
assert conn.status == 422
64-
assert conn.resp_body == "#/user/name: Value does not match pattern: [a-zA-Z][a-zA-Z0-9_]+"
64+
assert conn.resp_body == "#/user/name: Value \"*1234\" does not match pattern: [a-zA-Z][a-zA-Z0-9_]+"
6565
end
6666
end
67-
end
67+
end

0 commit comments

Comments
 (0)