{"action":"created","issue":{"url":"https://api.github.com/repos/epoberezkin/ajv/issues/291","repository_url":"https://api.github.com/repos/epoberezkin/ajv","labels_url":"https://api.github.com/repos/epoberezkin/ajv/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/epoberezkin/ajv/issues/291/comments","events_url":"https://api.github.com/repos/epoberezkin/ajv/issues/291/events","html_url":"https://github.com/epoberezkin/ajv/issues/291","id":173361279,"number":291,"title":"Format keyword mismatch from specification","user":{"login":"jeremykentbgross","id":2185076,"avatar_url":"https://avatars.githubusercontent.com/u/2185076?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremykentbgross","html_url":"https://github.com/jeremykentbgross","followers_url":"https://api.github.com/users/jeremykentbgross/followers","following_url":"https://api.github.com/users/jeremykentbgross/following{/other_user}","gists_url":"https://api.github.com/users/jeremykentbgross/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremykentbgross/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremykentbgross/subscriptions","organizations_url":"https://api.github.com/users/jeremykentbgross/orgs","repos_url":"https://api.github.com/users/jeremykentbgross/repos","events_url":"https://api.github.com/users/jeremykentbgross/events{/privacy}","received_events_url":"https://api.github.com/users/jeremykentbgross/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-26T03:19:52Z","updated_at":"2016-08-27T08:09:06Z","closed_at":null,"body":"The readme currently indicates that custom format validation is only applied to string properties. However my understanding from reading the draft 4 specifications is that any property could have a format attribute, it just so happens that all the predefined formats only apply to strings.\r\n\r\nI have not (yet) checked if your implementation does indeed only support custom formats for strings and not other types, but that is what is currently stated in the readme. As noted in another issue, the readme currently broken/out of date in some other places, so perhaps this information is incorrect, however assuming it is correct, ideally when defining custom format validation functions you should be allowed to specifying the type they apply to.\r\n\r\nThere are many use cases for applying formats to other property types, some examples may be found even in software linked/recommend by the main json schema website.\r\n\r\nI have several possible use cases for custom formats on other types in upcoming projects. For example on objects, the custom format matcher \"isA:\\w*\" could trigger a custom format validation function to verify that the object represents data serialized from a class derived from the class matched by \"\\w*\". While in theory this could be achieved with features such as \"oneOf\", that would assume the schema must know all possible descendant classes at the time it is authored, or be dynamically updated and recompiled whenever a new class factory is registered. This method on the other hand allows traversing inheritance tree information that may not be available to the schema, and even custom recursive validation by another schema found in said tree.\r\n\r\nMany more examples abound, but the important thing is that the draft 4 specification implies custom formats can be applied to any type, unless i misunderstand their meaning. Ideally ajv stays in line with the standard on this point, and/or updates it's documentation to indicate it's existing compliance."},"comment":{"url":"https://api.github.com/repos/epoberezkin/ajv/issues/comments/242903775","html_url":"https://github.com/epoberezkin/ajv/issues/291#issuecomment-242903775","issue_url":"https://api.github.com/repos/epoberezkin/ajv/issues/291","id":242903775,"user":{"login":"epoberezkin","id":2769109,"avatar_url":"https://avatars.githubusercontent.com/u/2769109?v=3","gravatar_id":"","url":"https://api.github.com/users/epoberezkin","html_url":"https://github.com/epoberezkin","followers_url":"https://api.github.com/users/epoberezkin/followers","following_url":"https://api.github.com/users/epoberezkin/following{/other_user}","gists_url":"https://api.github.com/users/epoberezkin/gists{/gist_id}","starred_url":"https://api.github.com/users/epoberezkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epoberezkin/subscriptions","organizations_url":"https://api.github.com/users/epoberezkin/orgs","repos_url":"https://api.github.com/users/epoberezkin/repos","events_url":"https://api.github.com/users/epoberezkin/events{/privacy}","received_events_url":"https://api.github.com/users/epoberezkin/received_events","type":"User","site_admin":false},"created_at":"2016-08-27T08:09:06Z","updated_at":"2016-08-27T08:09:06Z","body":"The draft 4 spec describes `format` keyword as optional, it only says that if it is implemented, some predefined attributes should be present too - see [7.2](http://json-schema.org/latest/json-schema-validation.html#anchor106). To me it seems semantically wrong using it for anything but strings, so Ajv indeed only supports formats for strings.\r\nThe validation scenario you describe is not really a \"format\" (i.e. shape/size/pattern/plan/arrangement/presentation), it is some complex requirement. Ajv allows to implement any such requirements, including those that require asynchronous calls, using [custom keywords](https://github.com/epoberezkin/ajv#defining-custom-keywords) - I think a custom keyword would better fit your use case (and you are not constrained with a string as a value, where you need to cram several things in one string as you are trying to do).\r\nI will think again whether it's worth extending format to support other data types in addition to strings."}}
{"actor":{"display_login":"epoberezkin"}}