Created
February 27, 2018 13:13
-
-
Save duncanjbrown/0f2e81d5ed914659a0f5ba145ebcb429 to your computer and use it in GitHub Desktop.
OpenAPI validation for an Apiary spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'open_api_parser' | |
gem 'pry' | |
gem 'json_schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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