Skip to content

Instantly share code, notes, and snippets.

@duncanjbrown
Created February 27, 2018 13:13
Show Gist options
  • Save duncanjbrown/0f2e81d5ed914659a0f5ba145ebcb429 to your computer and use it in GitHub Desktop.
Save duncanjbrown/0f2e81d5ed914659a0f5ba145ebcb429 to your computer and use it in GitHub Desktop.
OpenAPI validation for an Apiary spec
source 'https://rubygems.org'
gem 'open_api_parser'
gem 'pry'
gem 'json_schema'
require 'open_api_parser'
require 'pry'
require 'json_schema'
specification = OpenApiParser::Specification.resolve("spec.yml")
endpoint = specification.endpoint('/generic', 'POST')
theschema = endpoint.body_schema
schema = JsonSchema.parse!(theschema)
payload = {"data" => { "type" => "blooooooooooop", "attributes" => {}}}
errors = schema.validate(payload)
err = errors[1][0]
puts errors.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment