jsonapi_swagger_helpers 0.4.3 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1feea97f395c500cbf8914d31a2e02a3ad0529cd
4
- data.tar.gz: 1d5e093336798ba21f41020ef8b58c83e8fa979e
3
+ metadata.gz: c590130598ec385f7cd5f751daebc434134dbcbd
4
+ data.tar.gz: 88ebb028ff3384493e81e0f2f1ede2c99387c8fe
5
5
  SHA512:
6
- metadata.gz: 13265b4a6f5f91b060536991587c8be0878537e705230faf04cd8df381e138257d573ad8dbaf6d3fba1e9d6ce9c25448f0e243566af0c29ea3d9f09393c8d9a6
7
- data.tar.gz: c277e20daa4b1785cfbffb826267e34c733179c4ba21a87dd120ffa24508e551d19e52d346d8a9347a119404f11d8aab0b1b8c52acffb65d72b209e627632a69
6
+ metadata.gz: 0e539c0912d897ac4a99dd4e231f74746dc763974890096c8b15e4205319627a0ff95cb2ec38f1344a86146a8f9850a3c9ea7a6089493dd868b67df81412c61c
7
+ data.tar.gz: b27dbe4c58645933105a45f9b1779a57000c9e9228b086ecb2cecb63b36abd9778685b0fb509dea83785225b146c0c9f4d0b4204554cf41c695c2b5c2d957d6b
@@ -11,10 +11,11 @@ require "jsonapi_swagger_helpers/show_action"
11
11
  require "jsonapi_swagger_helpers/create_action"
12
12
  require "jsonapi_swagger_helpers/update_action"
13
13
  require "jsonapi_swagger_helpers/destroy_action"
14
-
15
14
  require "jsonapi_swagger_helpers/resource_mixin"
16
15
  require "jsonapi_swagger_helpers/docs_controller_mixin"
17
16
 
17
+ require "jsonapi_swagger_helpers/railtie" if defined?(Rails)
18
+
18
19
  module JsonapiSwaggerHelpers
19
20
  def self.configure
20
21
  yield config
@@ -43,9 +43,14 @@ module JsonapiSwaggerHelpers
43
43
  _self.util.jsonapi_includes(self)
44
44
 
45
45
  _self.each_association do |association_name, association_resource|
46
+ _self.util.jsonapi_fields(self, association_resource.config[:type])
47
+
48
+ if association_resource.config[:extra_fields].keys.length > 0
49
+ _self.util.jsonapi_extra_fields(self, association_resource)
50
+ end
51
+
46
52
  _self.util.each_filter(association_resource, association_name) do |filter_label|
47
53
  _self.util.jsonapi_filter(self, filter_label)
48
- _self.util.jsonapi_fields(self, association_resource.config[:type])
49
54
  end
50
55
  end
51
56
  end
@@ -0,0 +1,7 @@
1
+ module MyGem
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load 'tasks/swagger_diff.rake'
5
+ end
6
+ end
7
+ end
@@ -68,8 +68,12 @@ module JsonapiSwaggerHelpers
68
68
  end
69
69
 
70
70
  def each_association
71
+ types = [jsonapi_type]
71
72
  resource_map = util.all_resources(resource, include_directive)
72
73
  resource_map.each_pair do |association_name, association_resource|
74
+ resource_type = association_resource.config[:type]
75
+ next if types.include?(resource_type)
76
+ types << resource_type
73
77
  yield association_name, association_resource
74
78
  end
75
79
  end
@@ -37,13 +37,14 @@ module JsonapiSwaggerHelpers
37
37
  _self.util.jsonapi_includes(self)
38
38
 
39
39
  _self.each_association do |association_name, association_resource|
40
+ _self.util.jsonapi_fields(self, association_resource.config[:type])
41
+
42
+ if association_resource.config[:extra_fields].keys.length > 0
43
+ _self.util.jsonapi_extra_fields(self, association_resource)
44
+ end
45
+
40
46
  _self.util.each_filter(association_resource, association_name) do |filter_label|
41
47
  _self.util.jsonapi_filter(self, filter_label)
42
- _self.util.jsonapi_fields(self, association_resource.config[:type])
43
-
44
- if association_resource.config[:extra_fields].keys.length > 0
45
- _self.util.jsonapi_extra_fields(self, association_resource)
46
- end
47
48
  end
48
49
  end
49
50
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiSwaggerHelpers
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,43 @@
1
+ require 'pp'
2
+ begin
3
+ require 'swagger/diff'
4
+ rescue LoadError
5
+ puts "You must install the swagger-diff gem to use the swagger_diff rake task"
6
+ exit(1)
7
+ end
8
+
9
+ def get_swagger(path)
10
+ token = ENV['JSONAPI_TOKEN']
11
+ session = ActionDispatch::Integration::Session.new(Rails.application)
12
+ session.get path, headers: {
13
+ 'Authorization' => "Token token=\"#{token}\""
14
+ }
15
+ session.response.body
16
+ end
17
+
18
+ desc <<-DESC
19
+ Compare a local swagger.json to a remote swagger.json
20
+
21
+ Usage: swagger_diff[namespace,local_host,remote_host]
22
+
23
+ Example swagger_diff["api","http://localhost:3000","http://myapp.com"]
24
+
25
+ If your app relies on JSON Web Tokens, you can set JSONAPI_TOKEN for authentication
26
+ 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'
30
+ namespace = args[:namespace] || 'api'
31
+
32
+ old = get_swagger("#{remote_host}/#{namespace}/swagger.json")
33
+ new = get_swagger("#{local_host}/#{namespace}/swagger.json")
34
+ diff = Swagger::Diff::Diff.new(old, new)
35
+
36
+ if diff.compatible?
37
+ puts 'No backwards incompatibilities found!'
38
+ else
39
+ puts "Found backwards incompatibilities!\n\n"
40
+ pp JSON.parse(diff.incompatibilities)
41
+ exit(1)
42
+ end
43
+ 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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
@@ -105,6 +105,7 @@ files:
105
105
  - lib/jsonapi_swagger_helpers/errors.rb
106
106
  - lib/jsonapi_swagger_helpers/index_action.rb
107
107
  - lib/jsonapi_swagger_helpers/payload_definition.rb
108
+ - lib/jsonapi_swagger_helpers/railtie.rb
108
109
  - lib/jsonapi_swagger_helpers/readable.rb
109
110
  - lib/jsonapi_swagger_helpers/resource_mixin.rb
110
111
  - lib/jsonapi_swagger_helpers/show_action.rb
@@ -112,6 +113,7 @@ files:
112
113
  - lib/jsonapi_swagger_helpers/util.rb
113
114
  - lib/jsonapi_swagger_helpers/version.rb
114
115
  - lib/jsonapi_swagger_helpers/writeable.rb
116
+ - lib/tasks/swagger_diff.rake
115
117
  homepage:
116
118
  licenses:
117
119
  - MIT