jsonapi_swagger_helpers 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c590130598ec385f7cd5f751daebc434134dbcbd
4
- data.tar.gz: 88ebb028ff3384493e81e0f2f1ede2c99387c8fe
3
+ metadata.gz: abb83bf2b0e772c1a1cc03a52e73166a2bbdd7df
4
+ data.tar.gz: bd30366f11ccdf800c455de0d18b5d2e61d70122
5
5
  SHA512:
6
- metadata.gz: 0e539c0912d897ac4a99dd4e231f74746dc763974890096c8b15e4205319627a0ff95cb2ec38f1344a86146a8f9850a3c9ea7a6089493dd868b67df81412c61c
7
- data.tar.gz: b27dbe4c58645933105a45f9b1779a57000c9e9228b086ecb2cecb63b36abd9778685b0fb509dea83785225b146c0c9f4d0b4204554cf41c695c2b5c2d957d6b
6
+ metadata.gz: d2dfb9d76a78f713f83d4a1fad0745f104e9ca5037ffda8b31930b4a1badc7e4f1cd92c048b2ecdc3bc5fea881112abfd9afff19fc5d448dbf572efc0fddd0eb
7
+ data.tar.gz: 8bee607c72c241a36e7a2390c7691c342f8a20f13b8c91a99f1fa2771b4f33f5d994a429fcb4e3959de4bd39a38c6cf7a48ea30dda1a0770caf8c5f5a9e42d8c
@@ -1,3 +1,3 @@
1
1
  module JsonapiSwaggerHelpers
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'pp'
2
+ require 'net/http'
2
3
  begin
3
4
  require 'swagger/diff'
4
5
  rescue LoadError
@@ -6,38 +7,43 @@ rescue LoadError
6
7
  exit(1)
7
8
  end
8
9
 
9
- def get_swagger(path)
10
- token = ENV['JSONAPI_TOKEN']
10
+ def get_local_swagger(path)
11
11
  session = ActionDispatch::Integration::Session.new(Rails.application)
12
- session.get path, headers: {
13
- 'Authorization' => "Token token=\"#{token}\""
14
- }
12
+ session.get path
15
13
  session.response.body
16
14
  end
17
15
 
16
+ def get_remote_swagger(path)
17
+ uri = URI(path)
18
+ http = Net::HTTP.new(uri.host, uri.port)
19
+ req = Net::HTTP::Get.new(uri)
20
+ req['Authorization'] = "Token token=\"#{ENV['JSONAPI_TOKEN']}\""
21
+ res = http.request(req)
22
+ res.body
23
+ end
24
+
18
25
  desc <<-DESC
19
26
  Compare a local swagger.json to a remote swagger.json
20
27
 
21
- Usage: swagger_diff[namespace,local_host,remote_host]
28
+ Usage: swagger_diff[namespace,remote_host]
22
29
 
23
- Example swagger_diff["api","http://localhost:3000","http://myapp.com"]
30
+ Example swagger_diff["api","http://myapp.com"]
24
31
 
25
32
  If your app relies on JSON Web Tokens, you can set JSONAPI_TOKEN for authentication
26
33
  DESC
27
- task :swagger_diff, [:namespace, :local_host, :remote_host] => [:environment] do |_, args|
28
- local_host = args[:local_host] || 'http://localhost:3000'
29
- remote_host = args[:remote_host] || 'http://localhost:3000'
34
+ task :swagger_diff, [:namespace, :remote_host] => [:environment] do |_, args|
35
+ remote_host = args[:remote_host] || 'http://localhost:3001'
30
36
  namespace = args[:namespace] || 'api'
31
37
 
32
- old = get_swagger("#{remote_host}/#{namespace}/swagger.json")
33
- new = get_swagger("#{local_host}/#{namespace}/swagger.json")
38
+ old = get_remote_swagger("#{remote_host}/#{namespace}/swagger.json")
39
+ new = get_local_swagger("/#{namespace}/swagger.json")
34
40
  diff = Swagger::Diff::Diff.new(old, new)
35
41
 
36
42
  if diff.compatible?
37
43
  puts 'No backwards incompatibilities found!'
38
44
  else
39
45
  puts "Found backwards incompatibilities!\n\n"
40
- pp JSON.parse(diff.incompatibilities)
46
+ pp diff.incompatibilities.inspect
41
47
  exit(1)
42
48
  end
43
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_swagger_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond