{"id":28640766,"url":"https://github.com/pd/rack-schema","last_synced_at":"2025-06-12T20:08:21.977Z","repository":{"id":9037624,"uuid":"10799583","full_name":"pd/rack-schema","owner":"pd","description":"Validate your rack application's JSON responses against declared schemas","archived":false,"fork":false,"pushed_at":"2015-12-03T16:12:26.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-27T11:06:55.981Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/pd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-19T16:43:06.000Z","updated_at":"2020-11-29T12:43:53.000Z","dependencies_parsed_at":"2022-09-12T22:00:20.204Z","dependency_job_id":null,"html_url":"https://github.com/pd/rack-schema","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/pd/rack-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frack-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frack-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frack-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frack-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pd","download_url":"https://codeload.github.com/pd/rack-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frack-schema/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259522118,"owners_count":22870449,"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":"2025-06-12T20:08:21.365Z","updated_at":"2025-06-12T20:08:21.969Z","avatar_url":"https://github.com/pd.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rack::Schema\n\n[![Gem Version](https://badge.fury.io/rb/rack-schema.svg)](http://badge.fury.io/rb/rack-schema)\n[![Build Status](https://travis-ci.org/pd/rack-schema.svg?branch=master)](https://travis-ci.org/pd/rack-schema)\n[![Dependency Status](https://gemnasium.com/pd/rack-schema.svg)](https://gemnasium.com/pd/rack-schema)\n[![Code Climate](https://codeclimate.com/github/pd/rack-schema.png)](https://codeclimate.com/github/pd/rack-schema)\n[![Coverage Status](https://img.shields.io/coveralls/pd/rack-schema.svg)](https://coveralls.io/r/pd/rack-schema?branch=master)\n\nValidate your application's responses against [JSON Schemas][json-schema].\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'rack-schema'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rack-schema\n\n## Usage\nMount `Rack::Schema` as middleware in one of the normal manners:\n\n~~~~ruby\n# using config.ru:\nuse Rack::Schema\nrun MyApp\n\n# or application.rb:\nconfig.middleware.use Rack::Schema\n~~~~\n\nYour application can now return an HTTP [Link header][link-header]\nwith a `rel` attribute value of `describedby`, and `Rack::Schema` will\nautomatically attempt to validate responses against the specified\nschema (using the [json-schema gem][hoxworth]). An example `Link`\nheader:\n\n    Link: \u003chttp://example.com/schemas/response\u003e; rel=\"describedby\"\n\nIf your schema applies only to a part of the JSON response, you can\nuse the `anchor` attribute to specify a JSON path to the relevant value:\n\n    Link: \u003chttp://example.com/schemas/widget\u003e; rel=\"describedby\"; anchor=\"#/widget\"\n\nThis is actually a mis-use of the `anchor` attribute, which would\ntypically be used to specify an anchor within the *linked* document,\nrather than the document being described. JSON schemas already support\nthe use of the hash fragment on its URI, however, so I've\nre-appropriated it. Suggestions for a more compliant tactic are\nwelcome.\n\nIf your response is actually a collection of objects that should all\nvalidate against the same schema, use the `collection` attribute:\n\n    # Assert that the response is an array, and each object within it is a valid widget.\n    Link: \u003chttp://example.com/schemas/widget\u003e; rel=\"describedby\"; collection=\"collection\"\n\n    # Assert that the object at '#/widgets' is an array, and each object within it is a valid widget.\n    Link: \u003chttp://example.com/schemas/widget\u003e; rel=\"describedby\"; anchor=\"#/widgets\"; collection=\"collection\"\n\nIf the `Link` header contains multiple applicable links, they will\nall be used to validate the response:\n\n    # Assert that '#/teams' is an array of valid teams, and '#/score' is a valid score.\n    Link: \u003chttp://example.com/schemas/team\u003e; rel=\"describedby\"; anchor=\"#/teams\"; collection=\"collection\",\n          \u003chttp://example.com/schemas/score\u003e; rel=\"describedby\"; anchor=\"#/score\"\n\n## Configuration\n\n### Validate Schemas\nBy default, `rack-schema` will also instruct the validator to validate\nyour schema itself *as* a schema. To disable that behavior:\n\n~~~~ruby\nuse Rack::Schema, validate_schemas: false\n~~~~\n\n### Swallow Links\nIf you are running the `rack-schema` response validator in a\nproduction environment -- which you probably *shouldn't* be doing --\nand you don't want to actually expose the `describedby` link header\nentries to the world, you can tell `rack-schema` to remove them from\nthe responses after using them:\n\n~~~~ruby\nuse Rack::Schema, swallow_links: true\n~~~~\n\nWith `swallow_links` on, only the *describedby* links will be removed;\nyour pagination or similar links will not be disturbed.\n\n### Error Handler\nBy default, `rack-schema` will raise a `ValidationError` if it encounters\nany errors in your response JSON. If that's not your bag, you can define\na different error handler by providing a block:\n\n~~~ruby\nuse Rack::Schema do |errors, env, (status, headers, body)|\n  # Preferably, use a less useless error message.\n  my_logger.warn(\"JSON response did not match schema!\")\nend\n~~~\n\n\n## Potential Features?\n\n1. Validate incoming JSON bodies, but I just don't need that right now.\n   And it's unclear how we'd determine what schemas to use, or what we'd\n   do with the errors.\n\n## See Also\n\n1. [HTTP Link Header][link-header]\n2. [json-schema gem][hoxworth]\n\n[json-schema]: http://json-schema.org\n[link-header]: http://tools.ietf.org/html/rfc5988#section-5\n[hoxworth]: https://github.com/hoxworth/json-schema\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpd%2Frack-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpd%2Frack-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpd%2Frack-schema/lists"}