Created
December 28, 2017 00:26
-
-
Save metaskills/674d819f24f41ddb9664b0386d147ce0 to your computer and use it in GitHub Desktop.
Parse AWS SAM YAML Templates & Validate JSON Schema
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'pp' | |
require 'json' | |
require 'yaml' | |
require 'open-uri' | |
require 'json-schema' | |
SCHEMA = begin | |
file = open('https://raw.githubusercontent.com/awslabs/goformation/master/schema/sam.schema.json') | |
JSON.parse File.read(file) | |
end | |
FILE = ARGV[0] || 'template.yaml' | |
PATH = File.expand_path(File.join(ENV['PWD'], FILE)) | |
DATA = YAML.load(File.read(PATH)) | |
begin | |
JSON::Validator.validate! SCHEMA, DATA | |
puts 'Valid!' | |
rescue JSON::Schema::ValidationError => e | |
puts e.message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment