kymmt90 / schema_conformist

An automatic JSON response validator for testing in Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SchemaConformist

Gem Version Build Status

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.

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 requests/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.
  • schema_conformist.committee.old_assert_behavior

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.

About

An automatic JSON response validator for testing in Rails

License:MIT License


Languages

Language:Ruby 82.9%Language:HTML 12.8%Language:JavaScript 2.6%Language:CSS 1.7%