{"id":13509152,"url":"https://github.com/coryodaniel/apocryphal","last_synced_at":"2025-03-21T19:33:20.489Z","repository":{"id":57478896,"uuid":"67638133","full_name":"coryodaniel/apocryphal","owner":"coryodaniel","description":"Swagger based document driven development for ExUnit","archived":false,"fork":false,"pushed_at":"2016-10-16T23:16:18.000Z","size":45,"stargazers_count":17,"open_issues_count":11,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T04:42:49.624Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coryodaniel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-07T19:44:27.000Z","updated_at":"2023-09-01T08:53:50.000Z","dependencies_parsed_at":"2022-09-17T04:31:34.720Z","dependency_job_id":null,"html_url":"https://github.com/coryodaniel/apocryphal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fapocryphal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fapocryphal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fapocryphal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coryodaniel%2Fapocryphal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coryodaniel","download_url":"https://codeload.github.com/coryodaniel/apocryphal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244855720,"owners_count":20521694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:01:03.678Z","updated_at":"2025-03-21T19:33:20.168Z","avatar_url":"https://github.com/coryodaniel.png","language":"Elixir","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"# Apocryphal\n\nSwagger based documentation driven development for ExUnit\n\n## Installation\n\n```elixir\ndef deps do\n  [{:apocryphal, \"~\u003e 0.2.0\", only: [:test, :dev]}]\nend\n```\n\n```bash\nmix deps.get\nmix apocryphal.init\n```\n\nAdd `HTTPoison.start` to test_helper.exs:\n\n```elixir\nExUnit.start\nHTTPoison.start\nEcto.Adapters.SQL.Sandbox.mode(PetStore.Repo, :manual)\n```\n\n### Configure for Phoenix (HTTP Requests, SQL Sandbox)\n\nConfigure `test.exs` env to use Ecto SQL Sandbox and serve content\n\n```elixir\nconfig :YOUR_APP, YOUR_APP.Endpoint,\n  http: [port: 4001],\n  server: true\n\nconfig :YOUR_APP, :sql_sandbox, true\n```\n\nConfigure `lib/YOUR_APP/endpoint.ex`\n```elixir\nif Application.get_env(:YOUR_APP, :sql_sandbox) do\n  plug Phoenix.Ecto.SQL.Sandbox\nend\n```\n\nConfigure Apocryphal\n\n```elixir\nconfig :apocryphal,\n  port: 4001,\n  host: \"localhost\",\n  serializers: %{\n    \"application/json\" =\u003e fn(body) -\u003e Poison.encode!(body) end\n  },\n  deserializers: %{\n    \"application/json\" =\u003e fn(body) -\u003e Poison.decode!(body) end\n  }\n```\n\n### Configure for Plug\n\n[TBD](https://github.com/coryodaniel/apocryphal/issues/4)\n\n\n## Usage\n\n### Generating an API verification test\n\nParse swagger documentation into ExUnit tests\n```bash\nmix apocryphal.gen.test V1.Pets --only=^\\/pets --swagger-file=./docs/pet_store.yml\nmix apocryphal.gen.test V1.Stores --only=^\\/stores --swagger-file=./docs/pet_store.yml\n```\n\n\"One big file\" mode:\n```bash\nmix apocryphal.gen.test V1.PetAPI --swagger-file=./docs/pet_store.yml\n```\n\nThen just run `mix test`.\n\n### Full Example\n\nCheck out the [Petz Sample Phoenix app](http://github.com/coryodaniel/petz)\n\n\n```elixir\ndefmodule PetStore.V1.PetAPITest do\n  use Apocryphal.Case\n  alias PetStore.Pet\n  alias PetStore.Store\n\n  @swagger \"./docs/pet_store.yml\"\n  @mime \"application/json\"\n\n  test \"[GET] /stores (200)\" do\n    %Store{ address: \"123 Ship St.\",\n            city: \"Los Angeles\",\n            state: \"CA\",\n            postal_code: \"90210\" } |\u003e Repo.insert!\n\n\n    # assert_schema/1 will dispatch the transaction if a request isn't\n    # present, or it can be manually dispatched\n    @swagger\n    |\u003e Apocryphal.Transaction.get(\"/stores\", 200, @mime)\n    |\u003e Apocryphal.Transaction.dispatch\n    |\u003e assert_schema\n\n    # @swagger\n    # |\u003e Apocryphal.Transaction.get(\"/stores\", 200, @mime)\n    # |\u003e assert_schema\n  end\n\n  test \"[GET] /pets (200)\" do\n    %Pet{ name: \"Chauncy\", type: \"dog\" } |\u003e Repo.insert!\n\n    @swagger\n    |\u003e Apocryphal.Transaction.get(\"/pets\", 200, @mime)\n    |\u003e put_in([:request, :params], [limit: 20])\n    |\u003e assert_schema\n  end\n\n  test \"[POST] /pets (201)\" do\n    pet_params = %{ pet: %{ name: \"Chuancy\", type: \"cat\" } }\n    @swagger\n    |\u003e Apocryphal.Transaction.post(\"/pets\", 201, @mime)\n    |\u003e put_in([:request, :body], pet_params)\n    |\u003e assert_schema\n  end\n\n  test \"[POST] /pets 422\" do\n    pet_params = %{ pet: %{ name: \"Doge\", type: \"pupperino\" } }\n    @swagger\n    |\u003e Apocryphal.Transaction.post(\"/pets\", 422, @mime)\n    |\u003e put_in([:request, :body], pet_params)\n    |\u003e assert_schema\n  end\n\n  test \"[GET] /pets/{id} (200)\" do\n    pet = %Pet{name: \"Chauncy\", type: \"cat\"} |\u003e Repo.insert!\n\n    @swagger\n    |\u003e Apocryphal.Transaction.get(\"/pets/{id}\", 200, @mime)\n    |\u003e put_in([:request, :path_params], %{\"id\" =\u003e pet.id})\n    |\u003e assert_schema\n  end\n\n  test \"[GET] /pets/{id} (404)\" do\n    @swagger\n    |\u003e Apocryphal.Transaction.get(\"/pets/{id}\", 404, @mime)\n    |\u003e put_in([:request, :path_params], %{\"id\" =\u003e \"-1\"})\n    |\u003e assert_schema\n  end\nend\n```\n\n### Using remote swagger files\n\nUnder the hood Apocryphal uses ExJsonSchema. To set up resolves for remote schemas see the [ExJsonSchema docs](https://github.com/jonasschmidt/ex_json_schema#installation)\n\n\n### Note for Umbrella apps\n\nIf you are creating an umbrella app `YOUR_APP` above should be the app containing the ecto repo!\n\nIssues have been experience with async tests with umbrella apps where Ecto raises an `Ownership.Error`. Setting the tests explicitly as `async: false` fixes this.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoryodaniel%2Fapocryphal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoryodaniel%2Fapocryphal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoryodaniel%2Fapocryphal/lists"}