{"action":"created","issue":{"url":"https://api.github.com/repos/Hilzu/express-openapi-validate/issues/8","repository_url":"https://api.github.com/repos/Hilzu/express-openapi-validate","labels_url":"https://api.github.com/repos/Hilzu/express-openapi-validate/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/Hilzu/express-openapi-validate/issues/8/comments","events_url":"https://api.github.com/repos/Hilzu/express-openapi-validate/issues/8/events","html_url":"https://github.com/Hilzu/express-openapi-validate/issues/8","id":297403322,"number":8,"title":"Validate response schema","user":{"login":"codeclown","id":211543,"avatar_url":"https://avatars2.githubusercontent.com/u/211543?v=4","gravatar_id":"","url":"https://api.github.com/users/codeclown","html_url":"https://github.com/codeclown","followers_url":"https://api.github.com/users/codeclown/followers","following_url":"https://api.github.com/users/codeclown/following{/other_user}","gists_url":"https://api.github.com/users/codeclown/gists{/gist_id}","starred_url":"https://api.github.com/users/codeclown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codeclown/subscriptions","organizations_url":"https://api.github.com/users/codeclown/orgs","repos_url":"https://api.github.com/users/codeclown/repos","events_url":"https://api.github.com/users/codeclown/events{/privacy}","received_events_url":"https://api.github.com/users/codeclown/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-15T10:55:14Z","updated_at":"2018-02-16T17:56:15Z","closed_at":null,"author_association":"NONE","body":"To fully comply with openapi the API should also return responses according to what is defined in the spec.\r\n\r\nI can think of two scenarios or use cases for response validation:\r\n\r\n1. Validate response schema in tests (best if easy to slide in to any test)\r\n\r\n```js\r\nit('returns foobar name', () =>\r\n  agent\r\n    .get('/api/foobar')\r\n    .expect(200)\r\n    .then(validator.validateResponse('get', '/api/foobar'))\r\n    .then(res => {\r\n      assert.equal(res.name, 'Sir Smith');\r\n    })\r\n);\r\n```\r\n\r\n2. Validate responses in runtime.\r\n  - Either return a server error status code if response is not valid (probably not the best idea)\r\n  - Or, just log a warning to console whenever an invalid response is served so devs can notice it and act upon (probably a better idea), while app still serves the response to the client\r\n\r\n```js\r\napp.use(validator.logInvalidResponses());\r\n```"},"comment":{"url":"https://api.github.com/repos/Hilzu/express-openapi-validate/issues/comments/366310221","html_url":"https://github.com/Hilzu/express-openapi-validate/issues/8#issuecomment-366310221","issue_url":"https://api.github.com/repos/Hilzu/express-openapi-validate/issues/8","id":366310221,"user":{"login":"Hilzu","id":969840,"avatar_url":"https://avatars1.githubusercontent.com/u/969840?v=4","gravatar_id":"","url":"https://api.github.com/users/Hilzu","html_url":"https://github.com/Hilzu","followers_url":"https://api.github.com/users/Hilzu/followers","following_url":"https://api.github.com/users/Hilzu/following{/other_user}","gists_url":"https://api.github.com/users/Hilzu/gists{/gist_id}","starred_url":"https://api.github.com/users/Hilzu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hilzu/subscriptions","organizations_url":"https://api.github.com/users/Hilzu/orgs","repos_url":"https://api.github.com/users/Hilzu/repos","events_url":"https://api.github.com/users/Hilzu/events{/privacy}","received_events_url":"https://api.github.com/users/Hilzu/received_events","type":"User","site_admin":false},"created_at":"2018-02-16T17:56:14Z","updated_at":"2018-02-16T17:56:14Z","author_association":"OWNER","body":"I've been thinking about validating responses and I pretty much agree with you how it should work. \r\n\r\nI'm heavily leaning towards making it easy to validate the responses in tests. Need to test it out and figure out what the API should look like.\r\n\r\nI agree that this middleware shouldn't try to modify responses if they don't pass validations. Having an easy way to have a development time and/or opt-in response validation is something that I'm open to adding."}}
{"actor":{"display_login":"Hilzu"}}