rswag_schema_export 0.2.4 → 0.3.0

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
  SHA256:
3
- metadata.gz: 6f5365e70225088820039474c2a86d974be33d467f8e13c58df1c3ec188b0b6f
4
- data.tar.gz: eee348c31709d7e0480eef9b57b49377fb105ea356468f7a9af1861b25e74799
3
+ metadata.gz: f24a3d058e7de831bcb2c6d757e9c222a4c31b74ccf60bb40b78921c966cc047
4
+ data.tar.gz: e99c297dcdc2fa906d63218234996aea66cfe802f64e882c4f00371775ef3980
5
5
  SHA512:
6
- metadata.gz: a4c75d96589614953a8d2cd666f701db04bafe65041f72acabc044842a82b4d98546abe424c0edb89b9540fea0329edc1196725d65d429464a209c8a39f8998e
7
- data.tar.gz: 6f0dc260aa5e48188eb6c975a6839efe19cd3686a20065fbf3a90da2328252873944d788049d6db36351d95f11800220eb72b4a67050b6ed644ab92478f76a04
6
+ metadata.gz: ec81ef26bf39543e9a25b7bae9a18ebc24f4057b1fa0523ae5d1ee6fac8dab961c2f78c0d76e43fad73e45633a81cfeb6fac1dcc87af68912217cca2aab07135
7
+ data.tar.gz: 79e0648d094184b35b966f64d03934ddffac74b8815fa82e23ebb6eac50eb83c7d54865c647487016ec1942059933ac87b31490f77b11dc3fcd93b89f74cfbcc
@@ -10,6 +10,12 @@ jobs:
10
10
  keys:
11
11
  - rswag_schema_export-{{ checksum "Gemfile.lock" }}
12
12
  - rswag_schema_export-
13
+ - run:
14
+ name: Configure Bundler
15
+ command: |
16
+ echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
17
+ source $BASH_ENV
18
+ gem install bundler:2.0.2
13
19
 
14
20
  - run:
15
21
  name: install dependencies
@@ -1,44 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rswag_schema_export (0.2.4)
4
+ rswag_schema_export (0.3.0)
5
5
  aws-sdk-s3 (~> 1)
6
6
  azure-storage-blob (~> 1.1)
7
+ slack-notifier (~> 2.3.2)
8
+ swagger-diff (~> 1.1.2)
7
9
 
8
10
  GEM
9
11
  remote: https://rubygems.org/
10
12
  specs:
11
- actionpack (5.2.3)
12
- actionview (= 5.2.3)
13
- activesupport (= 5.2.3)
13
+ actionpack (6.0.1)
14
+ actionview (= 6.0.1)
15
+ activesupport (= 6.0.1)
14
16
  rack (~> 2.0)
15
17
  rack-test (>= 0.6.3)
16
18
  rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
- actionview (5.2.3)
19
- activesupport (= 5.2.3)
19
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
20
+ actionview (6.0.1)
21
+ activesupport (= 6.0.1)
20
22
  builder (~> 3.1)
21
23
  erubi (~> 1.4)
22
24
  rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
- activesupport (5.2.3)
25
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
26
+ activesupport (6.0.1)
25
27
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
28
  i18n (>= 0.7, < 2)
27
29
  minitest (~> 5.1)
28
30
  tzinfo (~> 1.1)
31
+ zeitwerk (~> 2.2)
32
+ addressable (2.7.0)
33
+ public_suffix (>= 2.0.2, < 5.0)
29
34
  ast (2.4.0)
30
35
  aws-eventstream (1.0.3)
31
- aws-partitions (1.210.0)
32
- aws-sdk-core (3.66.0)
36
+ aws-partitions (1.251.0)
37
+ aws-sdk-core (3.84.0)
33
38
  aws-eventstream (~> 1.0, >= 1.0.2)
34
- aws-partitions (~> 1.0)
39
+ aws-partitions (~> 1, >= 1.239.0)
35
40
  aws-sigv4 (~> 1.1)
36
41
  jmespath (~> 1.0)
37
- aws-sdk-kms (1.24.0)
38
- aws-sdk-core (~> 3, >= 3.61.1)
42
+ aws-sdk-kms (1.26.0)
43
+ aws-sdk-core (~> 3, >= 3.71.0)
39
44
  aws-sigv4 (~> 1.1)
40
- aws-sdk-s3 (1.48.0)
41
- aws-sdk-core (~> 3, >= 3.61.1)
45
+ aws-sdk-s3 (1.59.0)
46
+ aws-sdk-core (~> 3, >= 3.83.0)
42
47
  aws-sdk-kms (~> 1)
43
48
  aws-sigv4 (~> 1.1)
44
49
  aws-sigv4 (1.1.0)
@@ -57,64 +62,67 @@ GEM
57
62
  builder (3.2.3)
58
63
  coderay (1.1.2)
59
64
  concurrent-ruby (1.1.5)
60
- crass (1.0.4)
65
+ crass (1.0.5)
61
66
  diff-lcs (1.3)
62
67
  docile (1.3.2)
63
- erubi (1.8.0)
64
- faraday (0.15.4)
68
+ erubi (1.9.0)
69
+ faraday (0.17.1)
65
70
  multipart-post (>= 1.2, < 3)
66
71
  faraday_middleware (0.13.1)
67
72
  faraday (>= 0.7.4, < 1.0)
68
- i18n (1.6.0)
73
+ i18n (1.7.0)
69
74
  concurrent-ruby (~> 1.0)
70
- jaro_winkler (1.5.3)
75
+ jaro_winkler (1.5.4)
71
76
  jmespath (1.4.0)
72
77
  json (2.2.0)
73
- loofah (2.2.3)
78
+ json-schema (2.8.1)
79
+ addressable (>= 2.4)
80
+ loofah (2.3.1)
74
81
  crass (~> 1.0.2)
75
82
  nokogiri (>= 1.5.9)
76
83
  method_source (0.9.2)
77
84
  mini_portile2 (2.4.0)
78
- minitest (5.11.3)
85
+ minitest (5.13.0)
79
86
  multipart-post (2.1.1)
80
- nokogiri (1.10.4)
87
+ nokogiri (1.10.5)
81
88
  mini_portile2 (~> 2.4.0)
82
- parallel (1.17.0)
83
- parser (2.6.3.0)
89
+ parallel (1.18.0)
90
+ parser (2.6.5.0)
84
91
  ast (~> 2.4.0)
85
92
  pry (0.12.2)
86
93
  coderay (~> 1.1.0)
87
94
  method_source (~> 0.9.0)
95
+ public_suffix (4.0.1)
88
96
  rack (2.0.7)
89
97
  rack-test (1.1.0)
90
98
  rack (>= 1.0, < 3)
91
99
  rails-dom-testing (2.0.3)
92
100
  activesupport (>= 4.2.0)
93
101
  nokogiri (>= 1.6)
94
- rails-html-sanitizer (1.0.4)
95
- loofah (~> 2.2, >= 2.2.2)
96
- railties (5.2.3)
97
- actionpack (= 5.2.3)
98
- activesupport (= 5.2.3)
102
+ rails-html-sanitizer (1.3.0)
103
+ loofah (~> 2.3)
104
+ railties (6.0.1)
105
+ actionpack (= 6.0.1)
106
+ activesupport (= 6.0.1)
99
107
  method_source
100
108
  rake (>= 0.8.7)
101
- thor (>= 0.19.0, < 2.0)
109
+ thor (>= 0.20.3, < 2.0)
102
110
  rainbow (3.0.0)
103
- rake (10.5.0)
104
- rspec (3.8.0)
105
- rspec-core (~> 3.8.0)
106
- rspec-expectations (~> 3.8.0)
107
- rspec-mocks (~> 3.8.0)
108
- rspec-core (3.8.1)
109
- rspec-support (~> 3.8.0)
110
- rspec-expectations (3.8.4)
111
+ rake (13.0.1)
112
+ rspec (3.9.0)
113
+ rspec-core (~> 3.9.0)
114
+ rspec-expectations (~> 3.9.0)
115
+ rspec-mocks (~> 3.9.0)
116
+ rspec-core (3.9.0)
117
+ rspec-support (~> 3.9.0)
118
+ rspec-expectations (3.9.0)
111
119
  diff-lcs (>= 1.2.0, < 2.0)
112
- rspec-support (~> 3.8.0)
113
- rspec-mocks (3.8.1)
120
+ rspec-support (~> 3.9.0)
121
+ rspec-mocks (3.9.0)
114
122
  diff-lcs (>= 1.2.0, < 2.0)
115
- rspec-support (~> 3.8.0)
116
- rspec-support (3.8.2)
117
- rubocop (0.72.0)
123
+ rspec-support (~> 3.9.0)
124
+ rspec-support (3.9.0)
125
+ rubocop (0.76.0)
118
126
  jaro_winkler (~> 1.5.1)
119
127
  parallel (~> 1.10)
120
128
  parser (>= 2.6)
@@ -122,29 +130,34 @@ GEM
122
130
  ruby-progressbar (~> 1.7)
123
131
  unicode-display_width (>= 1.4.0, < 1.7)
124
132
  ruby-progressbar (1.10.1)
125
- simplecov (0.17.0)
133
+ simplecov (0.17.1)
126
134
  docile (~> 1.1)
127
135
  json (>= 1.8, < 3)
128
136
  simplecov-html (~> 0.10.0)
129
137
  simplecov-html (0.10.2)
138
+ slack-notifier (2.3.2)
139
+ swagger-diff (1.1.2)
140
+ json-schema (~> 2.6)
141
+ rspec-expectations (~> 3.3)
130
142
  thor (0.20.3)
131
143
  thread_safe (0.3.6)
132
144
  tzinfo (1.2.5)
133
145
  thread_safe (~> 0.1)
134
146
  unicode-display_width (1.6.0)
147
+ zeitwerk (2.2.1)
135
148
 
136
149
  PLATFORMS
137
150
  ruby
138
151
 
139
152
  DEPENDENCIES
140
- bundler (~> 1.17)
153
+ bundler (~> 2.0)
141
154
  pry
142
- railties (>= 3.1, < 6.0)
143
- rake (~> 10.0)
155
+ railties (>= 3.1, < 7.0)
156
+ rake (~> 13.0)
144
157
  rspec (~> 3.0)
145
158
  rswag_schema_export!
146
159
  rubocop
147
160
  simplecov
148
161
 
149
162
  BUNDLED WITH
150
- 1.17.2
163
+ 2.0.2
data/README.md CHANGED
@@ -93,6 +93,13 @@ require 'rswag_schema_export/capistrano'
93
93
  + set :rswag_schema_export_disable_import, true
94
94
  ```
95
95
 
96
+ ## Slack notifications
97
+
98
+ ```diff
99
+ # config/deploy/develop.rb
100
+ + set :rswag_schema_export_slack_webhook_url, ENV.fetch('SLACK_WEBHOOK_URL')
101
+ ```
102
+
96
103
  ## Configuration
97
104
 
98
105
  Set up ENVIRONMENT VARIABLES on your CI
@@ -4,6 +4,9 @@ require "rswag_schema_export/client"
4
4
  require "rswag_schema_export/railtie" if defined?(Rails)
5
5
  require "rswag_schema_export/schema_export"
6
6
  require "rswag_schema_export/schema_import"
7
+ require "rswag_schema_export/differ"
8
+ require "swagger/diff"
9
+ require "slack-notifier"
7
10
 
8
11
  module RswagSchemaExport
9
12
  def self.configure
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+
3
+ module RswagSchemaExport
4
+ class Differ
5
+ def self.call(previews_schema, new_schema)
6
+ previews_schema_json = JSON.parse(File.read(previews_schema))
7
+ previews_schema_json["host"] = "localhost"
8
+
9
+ File.write(previews_schema, JSON.pretty_generate(previews_schema_json))
10
+
11
+ new_schema_json = JSON.parse(File.read(new_schema))
12
+ new_schema_json["host"] = "localhost"
13
+
14
+ File.write(new_schema, JSON.pretty_generate(new_schema_json))
15
+
16
+ diff = ::Swagger::Diff::Diff.new(previews_schema, new_schema)
17
+ changes = []
18
+ report = ""
19
+
20
+ diff.changes.map do |topic|
21
+ report += "#{topic.first}: #{topic.last} \n"
22
+ changes << topic.last unless topic.last.empty?
23
+ end
24
+ if changes.empty?
25
+ nil
26
+ else
27
+ report
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module RswagSchemaExport
2
4
  class Import
3
5
  def run
@@ -6,6 +8,9 @@ module RswagSchemaExport
6
8
  begin
7
9
  client = ::RswagSchemaExport::Client.new(ENV["STAGE"])
8
10
  RswagSchemaExport.config.schemas.map do |schema|
11
+ # Copy previous version
12
+ FileUtils.cp(schema, "#{schema}.previous") if File.exist?(schema)
13
+
9
14
  schema_id = schema.gsub(/[^a-zA-Z0-9\-]/, "_")
10
15
 
11
16
  # Copy latest version to root
@@ -19,6 +24,18 @@ module RswagSchemaExport
19
24
  client.clean(versions)
20
25
 
21
26
  puts("Schema has been successfully imported. Stage: #{client.stage} | Key: #{last_schema_key}")
27
+ if ENV["SLACK_WEBHOOK_URL"]
28
+ begin
29
+ changes = Differ.call("#{schema}.previous", schema)
30
+
31
+ unless changes.nil?
32
+ Slack::Notifier.new(ENV["SLACK_WEBHOOK_URL"], username: 'Swagger API Differ').post(
33
+ text: '', attachments: [{ color: 'good', text: "_Swagger schema has been updated:_ \n #{changes}"}])
34
+ end
35
+ rescue StandardError => e
36
+ puts("Slack notification error: #{e}")
37
+ end
38
+ end
22
39
  end
23
40
  yield if block_given?
24
41
  puts("Import finished")
@@ -5,7 +5,7 @@ namespace :rswag do
5
5
  on roles(fetch(:rswag_schema_export_roles, :app)) do
6
6
  within current_path do
7
7
  with rails_env: fetch(:rails_env) do
8
- execute :rake, "rswag:schema_import STAGE=#{fetch(:stage)}"
8
+ execute :rake, "rswag:schema_import STAGE=#{fetch(:stage)} SLACK_WEBHOOK_URL=#{fetch(:rswag_schema_export_slack_webhook_url)}"
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module RswagSchemaExport
2
- VERSION = "0.2.4".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -21,11 +21,13 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "aws-sdk-s3", "~> 1"
23
23
  spec.add_dependency "azure-storage-blob", "~> 1.1"
24
+ spec.add_dependency "swagger-diff", "~> 1.1.2"
25
+ spec.add_dependency "slack-notifier", "~> 2.3.2"
24
26
 
25
- spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "bundler", "~> 2.0"
26
28
  spec.add_development_dependency "pry"
27
- spec.add_development_dependency "railties", ">= 3.1", "< 6.0"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "railties", ">= 3.1", "< 7.0"
30
+ spec.add_development_dependency "rake", "~> 13.0"
29
31
  spec.add_development_dependency "rspec", "~> 3.0"
30
32
  spec.add_development_dependency "rubocop"
31
33
  spec.add_development_dependency "simplecov"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rswag_schema_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Tolstov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -38,20 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: swagger-diff
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: slack-notifier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.2
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '1.17'
75
+ version: '2.0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '1.17'
82
+ version: '2.0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: pry
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +103,7 @@ dependencies:
75
103
  version: '3.1'
76
104
  - - "<"
77
105
  - !ruby/object:Gem::Version
78
- version: '6.0'
106
+ version: '7.0'
79
107
  type: :development
80
108
  prerelease: false
81
109
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,21 +113,21 @@ dependencies:
85
113
  version: '3.1'
86
114
  - - "<"
87
115
  - !ruby/object:Gem::Version
88
- version: '6.0'
116
+ version: '7.0'
89
117
  - !ruby/object:Gem::Dependency
90
118
  name: rake
91
119
  requirement: !ruby/object:Gem::Requirement
92
120
  requirements:
93
121
  - - "~>"
94
122
  - !ruby/object:Gem::Version
95
- version: '10.0'
123
+ version: '13.0'
96
124
  type: :development
97
125
  prerelease: false
98
126
  version_requirements: !ruby/object:Gem::Requirement
99
127
  requirements:
100
128
  - - "~>"
101
129
  - !ruby/object:Gem::Version
102
- version: '10.0'
130
+ version: '13.0'
103
131
  - !ruby/object:Gem::Dependency
104
132
  name: rspec
105
133
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +198,7 @@ files:
170
198
  - lib/rswag_schema_export/capistrano.rb
171
199
  - lib/rswag_schema_export/client.rb
172
200
  - lib/rswag_schema_export/configuration.rb
201
+ - lib/rswag_schema_export/differ.rb
173
202
  - lib/rswag_schema_export/railtie.rb
174
203
  - lib/rswag_schema_export/schema_export.rb
175
204
  - lib/rswag_schema_export/schema_import.rb
@@ -196,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
225
  - !ruby/object:Gem::Version
197
226
  version: '0'
198
227
  requirements: []
199
- rubygems_version: 3.0.3
228
+ rubygems_version: 3.0.6
200
229
  signing_key:
201
230
  specification_version: 4
202
231
  summary: Export/Import your rswag schema.json during deploy with CI