{"action":"created","issue":{"url":"https://api.github.com/repos/mcollina/fast-json-stringify/issues/5","repository_url":"https://api.github.com/repos/mcollina/fast-json-stringify","labels_url":"https://api.github.com/repos/mcollina/fast-json-stringify/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/mcollina/fast-json-stringify/issues/5/comments","events_url":"https://api.github.com/repos/mcollina/fast-json-stringify/issues/5/events","html_url":"https://github.com/mcollina/fast-json-stringify/issues/5","id":177658424,"number":5,"title":"Pattern and Additional properties","user":{"login":"delvedor","id":4865608,"avatar_url":"https://avatars.githubusercontent.com/u/4865608?v=3","gravatar_id":"","url":"https://api.github.com/users/delvedor","html_url":"https://github.com/delvedor","followers_url":"https://api.github.com/users/delvedor/followers","following_url":"https://api.github.com/users/delvedor/following{/other_user}","gists_url":"https://api.github.com/users/delvedor/gists{/gist_id}","starred_url":"https://api.github.com/users/delvedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delvedor/subscriptions","organizations_url":"https://api.github.com/users/delvedor/orgs","repos_url":"https://api.github.com/users/delvedor/repos","events_url":"https://api.github.com/users/delvedor/events{/privacy}","received_events_url":"https://api.github.com/users/delvedor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-18T15:33:15Z","updated_at":"2016-09-20T20:12:35Z","closed_at":null,"body":"Below the proposal to how implement pattern and additional properties.\r\n\r\n#### patternProperties:\r\nMust be an object, where the key is a valid regex and the value is an object.\r\nExample:\r\n```javascript\r\n\"patternProperties\": {\r\n    \"^S_\": { \"type\": \"string\" },\r\n    \"^I_\": { \"type\": \"integer\" }\r\n  }\r\n```\r\n`patternProperties` will work only for the properties that are not explicitly listed in the properties object.\r\n\r\n#### additionalProperties:\r\nMust be a boolean or an object.\r\nIf the is setted to false and there are properties that are not explicitly listed in the properties object we should throw an error.\r\nIf `additionalProperties` is used in conjunction with `patternProperties` the pecking order will be:\r\n`properties -> patternProperties -> additionalProperties`\r\nExample: \r\n```javascript\r\n\"additionalProperties\": {\r\n  \"type\": \"string\"\r\n}\r\n```\r\n\r\n#### Discussion:\r\nThe json schema is very bad documented, so before start to implement these functionalities we need to discuss about few things.\r\n- **additionalProperties**\r\n  If is setted to `{ type: 'string' }` and any additional property is not a string we have two possible cases:\r\n  1. throw an error\r\n  2. stringify the property as string\r\n\r\n- **patternProperties**\r\n  Basically the same as above, if a property matches to a pattern with `{ type: 'number' }` but the property is not a number we have two cases:\r\n  1. throw an error\r\n  2. stringify the property as number\r\n\r\n\r\nIf I forgot or I didn't see some edge case please write it below."},"comment":{"url":"https://api.github.com/repos/mcollina/fast-json-stringify/issues/comments/248419877","html_url":"https://github.com/mcollina/fast-json-stringify/issues/5#issuecomment-248419877","issue_url":"https://api.github.com/repos/mcollina/fast-json-stringify/issues/5","id":248419877,"user":{"login":"delvedor","id":4865608,"avatar_url":"https://avatars.githubusercontent.com/u/4865608?v=3","gravatar_id":"","url":"https://api.github.com/users/delvedor","html_url":"https://github.com/delvedor","followers_url":"https://api.github.com/users/delvedor/followers","following_url":"https://api.github.com/users/delvedor/following{/other_user}","gists_url":"https://api.github.com/users/delvedor/gists{/gist_id}","starred_url":"https://api.github.com/users/delvedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delvedor/subscriptions","organizations_url":"https://api.github.com/users/delvedor/orgs","repos_url":"https://api.github.com/users/delvedor/repos","events_url":"https://api.github.com/users/delvedor/events{/privacy}","received_events_url":"https://api.github.com/users/delvedor/received_events","type":"User","site_admin":false},"created_at":"2016-09-20T20:12:35Z","updated_at":"2016-09-20T20:12:35Z","body":"Edge case:\r\nSchema:\r\n```javascript\r\n{\r\n  title: 'title',\r\n  type: 'object',\r\n  properties: {...}\r\n  patternProperties: {\r\n    foo: {\r\n      type: 'string'\r\n    }\r\n  }\r\n}\r\n```\r\nif the user tries to stringify `objfoo: {a: true}`what we should do?\r\n1) Stringify as `[object Object]`\r\n2) Stringify with `fast-safe-stringify`\r\n3) throw\r\n\r\nI think the best option is the first one, because the user must know what is passing to `fast-json-stringify`, and if he sets a patternProperty, he's expecting the all the matching property have a specific type.\r\nFurthermore I guess that `[object Object]` is faster than de others (I didn't do any bench).\r\n\r\nIn the other cases, if `foo: { type: 'number' } -stringify-as-> NaN`\r\nIf `{ type: 'boolean' } -stringify-as-> true`"}}
{"actor":{"display_login":"delvedor"}}