{"id":19593144,"url":"https://github.com/thoughtbot/json_matchers","last_synced_at":"2025-05-15T18:00:19.730Z","repository":{"id":21722906,"uuid":"25044521","full_name":"thoughtbot/json_matchers","owner":"thoughtbot","description":"Validate your JSON APIs","archived":false,"fork":false,"pushed_at":"2024-07-30T03:28:47.000Z","size":140,"stargazers_count":388,"open_issues_count":15,"forks_count":38,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-25T23:07:33.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"BunkerProtect/BunkerCodeTest","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thoughtbot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-10T16:51:29.000Z","updated_at":"2025-04-04T02:19:41.000Z","dependencies_parsed_at":"2022-09-15T15:12:48.240Z","dependency_job_id":null,"html_url":"https://github.com/thoughtbot/json_matchers","commit_stats":null,"previous_names":["thoughtbot/json-matchers"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fjson_matchers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fjson_matchers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fjson_matchers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fjson_matchers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoughtbot","download_url":"https://codeload.github.com/thoughtbot/json_matchers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254394718,"owners_count":22063984,"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-11-11T08:38:20.222Z","updated_at":"2025-05-15T18:00:19.536Z","avatar_url":"https://github.com/thoughtbot.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonMatchers\n\nValidate the JSON returned by your Rails JSON APIs\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n```ruby\ngroup :test do\n  gem \"json_matchers\"\nend\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install json_matchers\n\n## Usage\n\nInspired by [Validating JSON Schemas with an RSpec Matcher][original-blog-post].\n\n[original-blog-post]: (https://robots.thoughtbot.com/validating-json-schemas-with-an-rspec-matcher)\n\nFirst, configure it in your test suite's helper file:\n\n### Configure\n\n#### RSpec\n\n`spec/spec_helper.rb`\n\n```ruby\nrequire \"json_matchers/rspec\"\n\nJsonMatchers.schema_root = \"spec/support/api/schemas\"\n```\n\n#### Minitest\n\n`test/test_helper.rb`\n\n```ruby\nrequire \"minitest/autorun\"\nrequire \"json_matchers/minitest/assertions\"\n\nJsonMatchers.schema_root = \"test/support/api/schemas\"\n\nMinitest::Test.include(JsonMatchers::Minitest::Assertions)\n```\n\n### Declare\n\nDeclare your [JSON Schema](https://json-schema.org/example1.html) in the schema\ndirectory.\n\n`spec/support/api/schemas/location.json` or\n`test/support/api/schemas/location.json`:\n\nDefine your [JSON Schema](https://json-schema.org/example1.html) in the schema\ndirectory.\n\n```json\n{\n  \"id\": \"https://json-schema.org/geo\",\n  \"$schema\": \"https://json-schema.org/draft-06/schema#\",\n  \"description\": \"A geographical coordinate\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"latitude\": {\n      \"type\": \"number\"\n    },\n    \"longitude\": {\n      \"type\": \"number\"\n    }\n  }\n}\n```\n\n### Validate\n\n#### RSpec\n\nValidate a JSON response, a Hash, or a String against a JSON Schema with\n`match_json_schema`:\n\n`spec/requests/locations_spec.rb`\n\n```ruby\ndescribe \"GET /locations\" do\n  it \"returns Locations\" do\n    get locations_path, format: :json\n\n    expect(response.status).to eq 200\n    expect(response).to match_json_schema(\"locations\")\n  end\nend\n```\n\n#### Minitest\n\nValidate a JSON response, a Hash, or a String against a JSON Schema with\n`assert_matches_json_schema`:\n\n`test/integration/locations_test.rb`\n\n```ruby\ndef test_GET_posts_returns_Locations\n  get locations_path, format: :json\n\n  assert_equal response.status, 200\n  assert_matches_json_schema response, \"locations\"\nend\n```\n\n### Embedding other Schemas\n\nTo re-use other schema definitions, include `$ref` keys that refer to their\ndefinitions.\n\nFirst, declare the singular version of your schema.\n\n`spec/support/api/schemas/user.json`:\n\n```json\n{\n  \"id\": \"file:/user.json#\",\n  \"type\": \"object\",\n  \"required\": [\"id\"],\n  \"properties\": {\n    \"id\": { \"type\": \"integer\" },\n    \"name\": { \"type\": \"string\" },\n    \"address\": { \"type\": \"string\" },\n  },\n}\n```\n\nThen, when you declare your collection schema, reference your singular schemas.\n\n`spec/support/api/schemas/users/index.json`:\n\n```json\n{\n  \"id\": \"file:/users/index.json#\",\n  \"type\": \"object\",\n  \"definitions\": {\n    \"users\": {\n      \"description\": \"A collection of users\",\n      \"example\": [{ \"id\": \"1\" }],\n      \"type\": \"array\",\n      \"items\": {\n        \"$ref\": \"file:/user.json#\"\n      },\n    },\n  },\n  \"required\": [\"users\"],\n  \"properties\": {\n    \"users\": {\n      \"$ref\": \"#/definitions/users\"\n    }\n  },\n}\n```\n\nNOTE: `$ref` resolves paths relative to the schema in question.\n\nIn this case `\"user.json\"` and `\"users/index.json\"` are resolved relative to\n`\"spec/support/api/schemas\"` or `\"test/support/api/schemas\"`.\n\nTo learn more about `$ref`, check out\n[Understanding JSON Schema Structuring][$ref].\n\n[$ref]: https://spacetelescope.github.io/understanding-json-schema/structuring.html\n\n### Declaring a schema in a Subdirectory\n\nNesting a schema within a subdirectory is also supported:\n\n`spec/support/api/schemas/api/v1/location.json`:\n\n\n```json\n{\n  \"id\": \"https://json-schema.org/geo\",\n  \"$schema\": \"https://json-schema.org/draft-06/schema#\",\n  \"description\": \"A geographical coordinate\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"latitude\": {\n      \"type\": \"number\"\n    },\n    \"longitude\": {\n      \"type\": \"number\"\n    }\n  }\n}\n```\n\n`spec/requests/api/v1/locations_spec.rb`:\n\n```ruby\ndescribe \"GET api/v1/locations\" do\n  it \"returns Locations\" do\n    get locations_path, format: :json\n\n    expect(response.status).to eq 200\n    expect(response).to match_json_schema(\"api/v1/location\")\n  end\nend\n```\n\n## Configuration\n\nBy default, the schema directory is `spec/support/api/schemas`.\n\nThis can be configured via `JsonMatchers.schema_root`.\n\n```ruby\n# spec/support/json_matchers.rb\n\nJsonMatchers.schema_root = \"docs/api/schemas\"\n```\n\n## Upgrading from `0.9.x`\n\nCalls to `match_json_schema` and `match_response_schema` no longer accept\noptions, and `JsonMatchers.configure` has been removed.\n\n## Contributing\n\nPlease see [CONTRIBUTING].\n\n`json_matchers` was inspired by [Validating JSON Schemas with an\nRSpec Matcher][blog post] by Laila Winner.\n\n`json_matchers` is maintained by Sean Doyle.\n\nMany improvements and bugfixes were contributed by the [open source community].\n\n[blog post]: https://robots.thoughtbot.com/validating-json-schemas-with-an-rspec-matcher\n[CONTRIBUTING]: https://github.com/thoughtbot/json_matchers/blob/master/CONTRIBUTING.md\n[open source community]: https://github.com/thoughtbot/json_matchers/graphs/contributors\n\n## License\n\n`json_matchers` is Copyright © 2018 thoughtbot.\n\nIt is free software, and may be redistributed under the terms specified in the\n[LICENSE] file.\n\n[LICENSE]: LICENSE.txt\n\n## About thoughtbot\n\n![thoughtbot](https://thoughtbot.com/logo.png)\n\n`json_matchers` is maintained and funded by thoughtbot, inc.\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nWe love open source software!\nSee [our other projects][community].\nWe are [available for hire][hire].\n\n[community]: https://thoughtbot.com/community?utm_source=github\n[hire]: https://thoughtbot.com?utm_source=github\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fjson_matchers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtbot%2Fjson_matchers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fjson_matchers/lists"}