Skip to content

Instantly share code, notes, and snippets.

@andycmaj
Created May 21, 2013 04:07
Show Gist options
  • Save andycmaj/5617420 to your computer and use it in GitHub Desktop.
Save andycmaj/5617420 to your computer and use it in GitHub Desktop.
Convert swagger JSON api definition to YAML - Requires http://rubygems.org/gems/crack
#!/usr/bin/env ruby
require 'crack'
# json file with api definition
in_file_name = ARGV[0]
# yaml file output
out_file_name = ARGV[1]
# read in json
json = File.read(in_file_name)
# convert json to hash
hash = Crack::JSON.parse(json)
# convert hash to string
yaml = hash.to_yaml
# write string to out_file_name
File.open(out_file_name, 'w') {|f| f.write(yaml) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment