{"action":"created","issue":{"url":"https://api.github.com/repos/xerions/phoenix_swagger/issues/163","repository_url":"https://api.github.com/repos/xerions/phoenix_swagger","labels_url":"https://api.github.com/repos/xerions/phoenix_swagger/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/xerions/phoenix_swagger/issues/163/comments","events_url":"https://api.github.com/repos/xerions/phoenix_swagger/issues/163/events","html_url":"https://github.com/xerions/phoenix_swagger/issues/163","id":295922853,"number":163,"title":"Reusing request and response data from exunit controller tests","user":{"login":"vivekg342","id":981781,"avatar_url":"https://avatars0.githubusercontent.com/u/981781?v=4","gravatar_id":"","url":"https://api.github.com/users/vivekg342","html_url":"https://github.com/vivekg342","followers_url":"https://api.github.com/users/vivekg342/followers","following_url":"https://api.github.com/users/vivekg342/following{/other_user}","gists_url":"https://api.github.com/users/vivekg342/gists{/gist_id}","starred_url":"https://api.github.com/users/vivekg342/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivekg342/subscriptions","organizations_url":"https://api.github.com/users/vivekg342/orgs","repos_url":"https://api.github.com/users/vivekg342/repos","events_url":"https://api.github.com/users/vivekg342/events{/privacy}","received_events_url":"https://api.github.com/users/vivekg342/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-09T16:09:50Z","updated_at":"2018-02-10T01:15:43Z","closed_at":null,"author_association":"NONE","body":"What would be the best way to achieve auto generation of request and response schema and examples based on controller tests ? I wonder if there is a way to reuse the payloads specified in the test cases to reduce some boilerplate. \r\nThanks in advance."},"comment":{"url":"https://api.github.com/repos/xerions/phoenix_swagger/issues/comments/364613119","html_url":"https://github.com/xerions/phoenix_swagger/issues/163#issuecomment-364613119","issue_url":"https://api.github.com/repos/xerions/phoenix_swagger/issues/163","id":364613119,"user":{"login":"mbuhot","id":336840,"avatar_url":"https://avatars3.githubusercontent.com/u/336840?v=4","gravatar_id":"","url":"https://api.github.com/users/mbuhot","html_url":"https://github.com/mbuhot","followers_url":"https://api.github.com/users/mbuhot/followers","following_url":"https://api.github.com/users/mbuhot/following{/other_user}","gists_url":"https://api.github.com/users/mbuhot/gists{/gist_id}","starred_url":"https://api.github.com/users/mbuhot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbuhot/subscriptions","organizations_url":"https://api.github.com/users/mbuhot/orgs","repos_url":"https://api.github.com/users/mbuhot/repos","events_url":"https://api.github.com/users/mbuhot/events{/privacy}","received_events_url":"https://api.github.com/users/mbuhot/received_events","type":"User","site_admin":false},"created_at":"2018-02-10T01:15:43Z","updated_at":"2018-02-10T01:15:43Z","author_association":"CONTRIBUTOR","body":"For schema examples, you can simply call the `swagger_definitions` function from your tests:\r\n\r\n```elixir\r\niex> SimpleWeb.UserController.swagger_definitions() |> Map.get(:User) |> Map.get(\"example\")\r\n%{\"email\" => \"joe@gmail.com\", \"id\" => 123, \"name\" => \"Joe\"}\r\n```\r\n\r\nAlternatively, you can put shared examples in a module, and use it from both the swagger and the tests:\r\n\r\n```elixir\r\ndefmodule SharedExamples do\r\n  def user do\r\n    %{\r\n      id: 123,\r\n      name: \"Joe\",\r\n      email: \"joe@gmail.com\"\r\n    }\r\n  end\r\nend\r\n\r\ndefmodule SimpleWeb.UserController do\r\n  use SimpleWeb, :controller\r\n  use PhoenixSwagger\r\n\r\n  alias Simple.Accounts\r\n  alias Simple.Accounts.User\r\n\r\n  action_fallback SimpleWeb.FallbackController\r\n\r\n  def swagger_definitions do\r\n    %{\r\n      User: swagger_schema do\r\n        title \"User\"\r\n        description \"A user of the app\"\r\n        properties do\r\n          id :integer, \"User ID\"\r\n          name :string, \"User name\", required: true\r\n          email :string, \"Email address\", format: :email, required: true\r\n          inserted_at :string, \"Creation timestamp\", format: :datetime\r\n          updated_at :string, \"Update timestamp\", format: :datetime\r\n        end\r\n        example SharedExamples.user()\r\n      end\r\n    }\r\n  end\r\nend\r\n```"}}
{"actor":{"display_login":"mbuhot"}}