{"action":"created","comment":{"url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/comments/267591161","pull_request_review_id":217037202,"id":267591161,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI2NzU5MTE2MQ==","diff_hunk":"@@ -1,60 +1,79 @@\n defmodule OpenApiSpex.Cast.String do\n-  @moduledoc false\n-  alias OpenApiSpex.Cast\n+  @moduledoc \"\"\"\n \n-  def cast(%{value: value} = ctx) when is_binary(value) do\n-    case cast_binary(ctx) do\n-      {:cast, ctx} -> cast(ctx)\n-      result -> result\n-    end\n-  end\n+  This module will cast a binary to either an Elixir DateTime or Date. Otherwise it will\n+  validate a binary based on maxLength, minLength, or a Regex pattern passed through the\n+  schema struct.\n \n-  def cast(ctx) do\n-    Cast.error(ctx, {:invalid_type, :string})\n-  end\n+  \"\"\"\n+  alias OpenApiSpex.{Cast, Cast.Error}\n \n-  ## Private functions\n+  @schema_fields [:maxLength, :minLength, :pattern]\n \n-  defp cast_binary(%{value: value, schema: %{format: :\"date-time\"}} = ctx)\n-       when is_binary(value) do\n+  def cast(%{value: value, schema: %{format: :date}} = ctx) when is_binary(value) do\n+    case Date.from_iso8601(value) do\n+      {:ok, %Date{} = date} ->\n+        {:ok, date}\n+      _ -> Cast.error(ctx, {:invalid_format, :date})\n+    end\n+  end\n+\n+  def cast(%{value: value, schema: %{format: :\"date-time\"}} = ctx) when is_binary(value) do\n     case DateTime.from_iso8601(value) do\n-      {:ok, %DateTime{}, _offset} -> Cast.success(ctx, :format)\n+      {:ok, %DateTime{} = datetime, _offset} ->\n+        {:ok, datetime}\n       _ -> Cast.error(ctx, {:invalid_format, :\"date-time\"})\n     end\n   end\n \n-  defp cast_binary(%{value: value, schema: %{format: :date}} = ctx) do\n-    case Date.from_iso8601(value) do\n-      {:ok, %Date{}} -> Cast.success(ctx, :format)\n-      _ -> Cast.error(ctx, {:invalid_format, :date})\n-    end\n+  def cast(%{value: value} = ctx) when is_binary(value) do\n+    apply_validation(ctx, @schema_fields)\n   end\n \n-  defp cast_binary(%{value: value, schema: %{pattern: pattern}} = ctx) when not is_nil(pattern) do\n-    if Regex.match?(pattern, value) do\n-      Cast.success(ctx, :pattern)\n+  def cast(ctx) do\n+    Cast.error(ctx, {:invalid_type, :string})\n+  end\n+\n+  ## Private functions\n+\n+  defp apply_validation(%{value: value, schema: %{maxLength: max_length}} = ctx, [:maxLength|fields])","path":"lib/open_api_spex/cast/string.ex","position":62,"original_position":62,"commit_id":"44b5c3cf861e468cf528797654e155320cb759da","original_commit_id":"44b5c3cf861e468cf528797654e155320cb759da","user":{"login":"moxley","id":86996,"node_id":"MDQ6VXNlcjg2OTk2","avatar_url":"https://avatars2.githubusercontent.com/u/86996?v=4","gravatar_id":"","url":"https://api.github.com/users/moxley","html_url":"https://github.com/moxley","followers_url":"https://api.github.com/users/moxley/followers","following_url":"https://api.github.com/users/moxley/following{/other_user}","gists_url":"https://api.github.com/users/moxley/gists{/gist_id}","starred_url":"https://api.github.com/users/moxley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moxley/subscriptions","organizations_url":"https://api.github.com/users/moxley/orgs","repos_url":"https://api.github.com/users/moxley/repos","events_url":"https://api.github.com/users/moxley/events{/privacy}","received_events_url":"https://api.github.com/users/moxley/received_events","type":"User","site_admin":false},"body":"I like the rewrite of the multi-try validation!","created_at":"2019-03-20T23:57:34Z","updated_at":"2019-03-20T23:57:34Z","html_url":"https://github.com/GhostGroup/open_api_spex/pull/12#discussion_r267591161","pull_request_url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/comments/267591161"},"html":{"href":"https://github.com/GhostGroup/open_api_spex/pull/12#discussion_r267591161"},"pull_request":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12"}},"in_reply_to_id":267590851},"pull_request":{"url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12","id":263058927,"node_id":"MDExOlB1bGxSZXF1ZXN0MjYzMDU4OTI3","html_url":"https://github.com/GhostGroup/open_api_spex/pull/12","diff_url":"https://github.com/GhostGroup/open_api_spex/pull/12.diff","patch_url":"https://github.com/GhostGroup/open_api_spex/pull/12.patch","issue_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/12","number":12,"state":"open","locked":false,"title":"String casts binary to Date or DateTime","user":{"login":"nurugger07","id":353129,"node_id":"MDQ6VXNlcjM1MzEyOQ==","avatar_url":"https://avatars2.githubusercontent.com/u/353129?v=4","gravatar_id":"","url":"https://api.github.com/users/nurugger07","html_url":"https://github.com/nurugger07","followers_url":"https://api.github.com/users/nurugger07/followers","following_url":"https://api.github.com/users/nurugger07/following{/other_user}","gists_url":"https://api.github.com/users/nurugger07/gists{/gist_id}","starred_url":"https://api.github.com/users/nurugger07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nurugger07/subscriptions","organizations_url":"https://api.github.com/users/nurugger07/orgs","repos_url":"https://api.github.com/users/nurugger07/repos","events_url":"https://api.github.com/users/nurugger07/events{/privacy}","received_events_url":"https://api.github.com/users/nurugger07/received_events","type":"User","site_admin":false},"body":"The more I look at this the less I agree with it. Looking at other Cast modules they are implemented as I would expect. The Integer module is a good example. Given a string as the value it is converted to an integer. Given an integer it returns an integer.","created_at":"2019-03-20T22:21:38Z","updated_at":"2019-03-20T23:57:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"731d3dc51efad2d4609e38bcac2ac62c29833dbd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12/commits","review_comments_url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12/comments","review_comment_url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/12/comments","statuses_url":"https://api.github.com/repos/GhostGroup/open_api_spex/statuses/44b5c3cf861e468cf528797654e155320cb759da","head":{"label":"GhostGroup:fix_casting_formats","ref":"fix_casting_formats","sha":"44b5c3cf861e468cf528797654e155320cb759da","user":{"login":"GhostGroup","id":4304538,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQzMDQ1Mzg=","avatar_url":"https://avatars0.githubusercontent.com/u/4304538?v=4","gravatar_id":"","url":"https://api.github.com/users/GhostGroup","html_url":"https://github.com/GhostGroup","followers_url":"https://api.github.com/users/GhostGroup/followers","following_url":"https://api.github.com/users/GhostGroup/following{/other_user}","gists_url":"https://api.github.com/users/GhostGroup/gists{/gist_id}","starred_url":"https://api.github.com/users/GhostGroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GhostGroup/subscriptions","organizations_url":"https://api.github.com/users/GhostGroup/orgs","repos_url":"https://api.github.com/users/GhostGroup/repos","events_url":"https://api.github.com/users/GhostGroup/events{/privacy}","received_events_url":"https://api.github.com/users/GhostGroup/received_events","type":"Organization","site_admin":false},"repo":{"id":152454494,"node_id":"MDEwOlJlcG9zaXRvcnkxNTI0NTQ0OTQ=","name":"open_api_spex","full_name":"GhostGroup/open_api_spex","private":false,"owner":{"login":"GhostGroup","id":4304538,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQzMDQ1Mzg=","avatar_url":"https://avatars0.githubusercontent.com/u/4304538?v=4","gravatar_id":"","url":"https://api.github.com/users/GhostGroup","html_url":"https://github.com/GhostGroup","followers_url":"https://api.github.com/users/GhostGroup/followers","following_url":"https://api.github.com/users/GhostGroup/following{/other_user}","gists_url":"https://api.github.com/users/GhostGroup/gists{/gist_id}","starred_url":"https://api.github.com/users/GhostGroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GhostGroup/subscriptions","organizations_url":"https://api.github.com/users/GhostGroup/orgs","repos_url":"https://api.github.com/users/GhostGroup/repos","events_url":"https://api.github.com/users/GhostGroup/events{/privacy}","received_events_url":"https://api.github.com/users/GhostGroup/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/GhostGroup/open_api_spex","description":"Open API Specifications for Elixir Plug applications","fork":true,"url":"https://api.github.com/repos/GhostGroup/open_api_spex","forks_url":"https://api.github.com/repos/GhostGroup/open_api_spex/forks","keys_url":"https://api.github.com/repos/GhostGroup/open_api_spex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GhostGroup/open_api_spex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GhostGroup/open_api_spex/teams","hooks_url":"https://api.github.com/repos/GhostGroup/open_api_spex/hooks","issue_events_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/events{/number}","events_url":"https://api.github.com/repos/GhostGroup/open_api_spex/events","assignees_url":"https://api.github.com/repos/GhostGroup/open_api_spex/assignees{/user}","branches_url":"https://api.github.com/repos/GhostGroup/open_api_spex/branches{/branch}","tags_url":"https://api.github.com/repos/GhostGroup/open_api_spex/tags","blobs_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/refs{/sha}","trees_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GhostGroup/open_api_spex/statuses/{sha}","languages_url":"https://api.github.com/repos/GhostGroup/open_api_spex/languages","stargazers_url":"https://api.github.com/repos/GhostGroup/open_api_spex/stargazers","contributors_url":"https://api.github.com/repos/GhostGroup/open_api_spex/contributors","subscribers_url":"https://api.github.com/repos/GhostGroup/open_api_spex/subscribers","subscription_url":"https://api.github.com/repos/GhostGroup/open_api_spex/subscription","commits_url":"https://api.github.com/repos/GhostGroup/open_api_spex/commits{/sha}","git_commits_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/commits{/sha}","comments_url":"https://api.github.com/repos/GhostGroup/open_api_spex/comments{/number}","issue_comment_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/comments{/number}","contents_url":"https://api.github.com/repos/GhostGroup/open_api_spex/contents/{+path}","compare_url":"https://api.github.com/repos/GhostGroup/open_api_spex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GhostGroup/open_api_spex/merges","archive_url":"https://api.github.com/repos/GhostGroup/open_api_spex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GhostGroup/open_api_spex/downloads","issues_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues{/number}","pulls_url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls{/number}","milestones_url":"https://api.github.com/repos/GhostGroup/open_api_spex/milestones{/number}","notifications_url":"https://api.github.com/repos/GhostGroup/open_api_spex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GhostGroup/open_api_spex/labels{/name}","releases_url":"https://api.github.com/repos/GhostGroup/open_api_spex/releases{/id}","deployments_url":"https://api.github.com/repos/GhostGroup/open_api_spex/deployments","created_at":"2018-10-10T16:24:49Z","updated_at":"2019-03-12T21:15:03Z","pushed_at":"2019-03-20T22:27:27Z","git_url":"git://github.com/GhostGroup/open_api_spex.git","ssh_url":"git@github.com:GhostGroup/open_api_spex.git","clone_url":"https://github.com/GhostGroup/open_api_spex.git","svn_url":"https://github.com/GhostGroup/open_api_spex","homepage":null,"size":337,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0","node_id":"MDc6TGljZW5zZTE0"},"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"GhostGroup:master","ref":"master","sha":"d0ff1ae53d5c019aa87b7af8239faa650ddfa6f4","user":{"login":"GhostGroup","id":4304538,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQzMDQ1Mzg=","avatar_url":"https://avatars0.githubusercontent.com/u/4304538?v=4","gravatar_id":"","url":"https://api.github.com/users/GhostGroup","html_url":"https://github.com/GhostGroup","followers_url":"https://api.github.com/users/GhostGroup/followers","following_url":"https://api.github.com/users/GhostGroup/following{/other_user}","gists_url":"https://api.github.com/users/GhostGroup/gists{/gist_id}","starred_url":"https://api.github.com/users/GhostGroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GhostGroup/subscriptions","organizations_url":"https://api.github.com/users/GhostGroup/orgs","repos_url":"https://api.github.com/users/GhostGroup/repos","events_url":"https://api.github.com/users/GhostGroup/events{/privacy}","received_events_url":"https://api.github.com/users/GhostGroup/received_events","type":"Organization","site_admin":false},"repo":{"id":152454494,"node_id":"MDEwOlJlcG9zaXRvcnkxNTI0NTQ0OTQ=","name":"open_api_spex","full_name":"GhostGroup/open_api_spex","private":false,"owner":{"login":"GhostGroup","id":4304538,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQzMDQ1Mzg=","avatar_url":"https://avatars0.githubusercontent.com/u/4304538?v=4","gravatar_id":"","url":"https://api.github.com/users/GhostGroup","html_url":"https://github.com/GhostGroup","followers_url":"https://api.github.com/users/GhostGroup/followers","following_url":"https://api.github.com/users/GhostGroup/following{/other_user}","gists_url":"https://api.github.com/users/GhostGroup/gists{/gist_id}","starred_url":"https://api.github.com/users/GhostGroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GhostGroup/subscriptions","organizations_url":"https://api.github.com/users/GhostGroup/orgs","repos_url":"https://api.github.com/users/GhostGroup/repos","events_url":"https://api.github.com/users/GhostGroup/events{/privacy}","received_events_url":"https://api.github.com/users/GhostGroup/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/GhostGroup/open_api_spex","description":"Open API Specifications for Elixir Plug applications","fork":true,"url":"https://api.github.com/repos/GhostGroup/open_api_spex","forks_url":"https://api.github.com/repos/GhostGroup/open_api_spex/forks","keys_url":"https://api.github.com/repos/GhostGroup/open_api_spex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GhostGroup/open_api_spex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GhostGroup/open_api_spex/teams","hooks_url":"https://api.github.com/repos/GhostGroup/open_api_spex/hooks","issue_events_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/events{/number}","events_url":"https://api.github.com/repos/GhostGroup/open_api_spex/events","assignees_url":"https://api.github.com/repos/GhostGroup/open_api_spex/assignees{/user}","branches_url":"https://api.github.com/repos/GhostGroup/open_api_spex/branches{/branch}","tags_url":"https://api.github.com/repos/GhostGroup/open_api_spex/tags","blobs_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/refs{/sha}","trees_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GhostGroup/open_api_spex/statuses/{sha}","languages_url":"https://api.github.com/repos/GhostGroup/open_api_spex/languages","stargazers_url":"https://api.github.com/repos/GhostGroup/open_api_spex/stargazers","contributors_url":"https://api.github.com/repos/GhostGroup/open_api_spex/contributors","subscribers_url":"https://api.github.com/repos/GhostGroup/open_api_spex/subscribers","subscription_url":"https://api.github.com/repos/GhostGroup/open_api_spex/subscription","commits_url":"https://api.github.com/repos/GhostGroup/open_api_spex/commits{/sha}","git_commits_url":"https://api.github.com/repos/GhostGroup/open_api_spex/git/commits{/sha}","comments_url":"https://api.github.com/repos/GhostGroup/open_api_spex/comments{/number}","issue_comment_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/comments{/number}","contents_url":"https://api.github.com/repos/GhostGroup/open_api_spex/contents/{+path}","compare_url":"https://api.github.com/repos/GhostGroup/open_api_spex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GhostGroup/open_api_spex/merges","archive_url":"https://api.github.com/repos/GhostGroup/open_api_spex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GhostGroup/open_api_spex/downloads","issues_url":"https://api.github.com/repos/GhostGroup/open_api_spex/issues{/number}","pulls_url":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls{/number}","milestones_url":"https://api.github.com/repos/GhostGroup/open_api_spex/milestones{/number}","notifications_url":"https://api.github.com/repos/GhostGroup/open_api_spex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GhostGroup/open_api_spex/labels{/name}","releases_url":"https://api.github.com/repos/GhostGroup/open_api_spex/releases{/id}","deployments_url":"https://api.github.com/repos/GhostGroup/open_api_spex/deployments","created_at":"2018-10-10T16:24:49Z","updated_at":"2019-03-12T21:15:03Z","pushed_at":"2019-03-20T22:27:27Z","git_url":"git://github.com/GhostGroup/open_api_spex.git","ssh_url":"git@github.com:GhostGroup/open_api_spex.git","clone_url":"https://github.com/GhostGroup/open_api_spex.git","svn_url":"https://github.com/GhostGroup/open_api_spex","homepage":null,"size":337,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0","node_id":"MDc6TGljZW5zZTE0"},"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12"},"html":{"href":"https://github.com/GhostGroup/open_api_spex/pull/12"},"issue":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/12"},"comments":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/GhostGroup/open_api_spex/statuses/44b5c3cf861e468cf528797654e155320cb759da"}},"author_association":"NONE"}}
{"actor":{"display_login":"moxley"}}