Skip to content

Instantly share code, notes, and snippets.

@richmolj
Created July 25, 2017 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richmolj/5365109d133d0afc093418dde1bda4c0 to your computer and use it in GitHub Desktop.
Save richmolj/5365109d133d0afc093418dde1bda4c0 to your computer and use it in GitHub Desktop.
require 'swagger/diff'
require 'pp'
def get_swagger(path)
token = ENV['JSONAPI_TOKEN']
session = ActionDispatch::Integration::Session.new(Rails.application)
session.get path, headers: {
'Authorization' => "Token token=\"#{token}\""
}
session.response.body
end
task :swagger_diff, [:namespace, :local_host, :remote_host] => [:environment] do |_, args|
local_host = args[:local_host] || 'http://localhost:3000'
remote_host = args[:remote_host] || 'http://localhost:3000'
namespace = args[:namespace] || 'api'
old = get_swagger("#{remote_host}/#{namespace}/swagger.json")
new = get_swagger("#{local_host}/#{namespace}/swagger.json")
diff = Swagger::Diff::Diff.new(old, new)
if diff.compatible?
puts 'No backwards incompatibilities found!'
else
pp JSON.parse(diff.incompatibilities)
raise 'Uh oh, found a backwards-incompatibility!'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment