An automatic JSON response validator for testing in Rails
SchemaConformist is an automatic JSON response validator for your API testing in Rails.
Add this line to your application's Gemfile:
That's all. Then all JSON responses in integration-test/request-spec are validated according to your schema.
Writing the Schema
Write your API schema in either JSON Hyper Schema or OpenAPI 2. For now, the default driver is set to JSON Hyper Schema and default schema paths are following:
- JSON Hyper Schema:
- OpenAPI 2:
test/dummy app for examples.
Configuration options are following:
:hyper_schema: Use JSON Hyper Schema as schema format
:open_api_2: Use OpenAPI 2 as schema format (both JSON and YAML are available as schema files)
- The array of API paths not to validate. Each path can be described in regular expression.
- The path where the schema is placed
Rails.application.config.schema_conformist.driver = :open_api_2 Rails.application.config.schema_conformist.ignored_api_paths << /private/ Rails.application.config.schema_conformist.schema_path = Rails.root.join('doc', 'swagger.yaml')
Bug reports and pull requests are welcome on GitHub at https://github.com/kymmt90/schema_conformist.
The gem is available as open source under the terms of the MIT License.