Created
July 25, 2017 19:06
-
-
Save richmolj/5365109d133d0afc093418dde1bda4c0 to your computer and use it in GitHub Desktop.
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
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