jsonapi_swagger_helpers 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/jsonapi_swagger_helpers/version.rb +1 -1
 - data/lib/tasks/swagger_diff.rake +19 -13
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: abb83bf2b0e772c1a1cc03a52e73166a2bbdd7df
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bd30366f11ccdf800c455de0d18b5d2e61d70122
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d2dfb9d76a78f713f83d4a1fad0745f104e9ca5037ffda8b31930b4a1badc7e4f1cd92c048b2ecdc3bc5fea881112abfd9afff19fc5d448dbf572efc0fddd0eb
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8bee607c72c241a36e7a2390c7691c342f8a20f13b8c91a99f1fa2771b4f33f5d994a429fcb4e3959de4bd39a38c6cf7a48ea30dda1a0770caf8c5f5a9e42d8c
         
     | 
    
        data/lib/tasks/swagger_diff.rake
    CHANGED
    
    | 
         @@ -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  
     | 
| 
       10 
     | 
    
         
            -
              token = ENV['JSONAPI_TOKEN']
         
     | 
| 
      
 10 
     | 
    
         
            +
            def get_local_swagger(path)
         
     | 
| 
       11 
11 
     | 
    
         
             
              session = ActionDispatch::Integration::Session.new(Rails.application)
         
     | 
| 
       12 
     | 
    
         
            -
              session.get path 
     | 
| 
       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, 
     | 
| 
      
 28 
     | 
    
         
            +
            Usage: swagger_diff[namespace,remote_host]
         
     | 
| 
       22 
29 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
            Example swagger_diff["api","http:// 
     | 
| 
      
 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, : 
     | 
| 
       28 
     | 
    
         
            -
               
     | 
| 
       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  =  
     | 
| 
       33 
     | 
    
         
            -
              new  =  
     | 
| 
      
 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  
     | 
| 
      
 46 
     | 
    
         
            +
                pp diff.incompatibilities.inspect
         
     | 
| 
       41 
47 
     | 
    
         
             
                exit(1)
         
     | 
| 
       42 
48 
     | 
    
         
             
              end
         
     | 
| 
       43 
49 
     | 
    
         
             
            end
         
     |