Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116160
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/open_api_spex/cast_string.ex b/lib/open_api_spex/cast_string.ex
index e67cbbb..9e9d634 100644
--- a/lib/open_api_spex/cast_string.ex
+++ b/lib/open_api_spex/cast_string.ex
@@ -1,41 +1,40 @@
defmodule OpenApiSpex.CastString do
@moduledoc false
alias OpenApiSpex.CastContext
- def cast(%{value: value, schema: %{pattern: pattern}} = ctx)
- when not is_nil(pattern) and is_binary(value) do
- if Regex.match?(pattern, value) do
- {:ok, value}
- else
- CastContext.error(ctx, {:invalid_format, pattern})
- end
- end
-
def cast(%{value: value} = ctx) when is_binary(value) do
cast_binary(ctx)
end
def cast(ctx) do
CastContext.error(ctx, {:invalid_type, :string})
end
## Private functions
+ defp cast_binary(%{value: value, schema: %{pattern: pattern}} = ctx) when not is_nil(pattern) do
+ if Regex.match?(pattern, value) do
+ {:ok, value}
+ else
+ CastContext.error(ctx, {:invalid_format, pattern})
+ end
+ end
+
defp cast_binary(%{value: value, schema: %{minLength: min_length}} = ctx)
when is_integer(min_length) do
# Note: This is not part of the JSON Shema spec: trim string before measuring length
# It's just too important to miss
trimmed = String.trim(value)
length = String.length(trimmed)
if length < min_length do
CastContext.error(ctx, {:min_length, length})
else
{:ok, value}
end
end
defp cast_binary(%{value: value}) do
{:ok, value}
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 30, 2:41 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41462
Default Alt Text
(1 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment