SchemaConformist

Gem Version Build Status

An automatic JSON response validator for testing in Rails

SchemaConformist is an automatic JSON response validator for your API testing in Rails.

This library automatically validates that JSON 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.

Usage

Installation

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 responses in integration-test/request-spec are validated according to your schema.

Writing the Schema

Write your API schema in one of JSON Hyper Schema, OpenAPI 2 and OpenAPI 3.

See test/dummy app for examples.

Configurations

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kymmt90/schema_conformist.

License

The gem is available as open source under the terms of the MIT License.