An automatic JSON request/response validator for testing in Rails
SchemaConformist is an automatic JSON request/response validator for your API testing in Rails.
This library automatically validates that JSON requests/responses are conformant with the schema. The schema can be described as one of JSON Hyper Schema, OpenAPI 2.0 and OpenAPI 3 (currently 3.0.2 is latest).
This library uses Committee to validate JSONs.
Add this line to your application's Gemfile:
gem 'schema_conformist'
and execute bundle install
.
Configure schema_path
as follows (ex. using an OpenAPI 3 schema):
Rails.application.config.schema_conformist.schema_path = Rails.root.join('doc', 'openapi.yaml')
That's all. Then all JSON requests/responses in integration-test/request-spec are validated according to your schema.
Write your API schema in one of JSON Hyper Schema, OpenAPI 2 and OpenAPI 3.
See test/dummy
app for examples.
Configuration options are following:
schema_conformist.schema_path
- Required. The path where the schema is placed
schema_conformist.ignored_api_paths
- Optional. The array of API paths not to validate. Each path can be described in String literal (used for prefix search) or regular expression.
schema_conformist.committee.old_assert_behavior
- Optional. Set
true
if you want to skip validating request parameters. The default value isfalse
. - cf. "Test Assertions" in Committee README
- Optional. Set
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.