rswag_schema_export 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +25 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +52 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +137 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/capistrano/tasks/rswag.rake +12 -0
- data/lib/rswag_schema_export/railtie.rb +7 -0
- data/lib/rswag_schema_export/schema_export.rb +34 -0
- data/lib/rswag_schema_export/schema_import.rb +41 -0
- data/lib/rswag_schema_export/version.rb +3 -0
- data/lib/rswag_schema_export.rb +7 -0
- data/lib/tasks/rswag_tasks.rake +12 -0
- data/rswag_schema_export.gemspec +32 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d19845a0a45eee3cf8889e7d29d4f63a46e7eaf29249f1fb27b2214568cd2cb4
|
4
|
+
data.tar.gz: 2b44e6cc3c52689682f9373cfc3bfbc1a912cdd24b1886d6abe3505e5fb4e671
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97556f82b88bafc6dea9dbfef087b10cfc73349a6f80ac00e8ec0ee3e06b094bf4f7e3987ddb9746db52b98f094fb10d11b139e195794ea1d284d1e48e10c1c2
|
7
|
+
data.tar.gz: ec69cda869372645d2548ed8c5f9cac63c0a54ebd093a51b7ab0119453a006aece4c109b844be399f36ae6bc4fa2ba57c2c2faf45318f337df4f33ef22841341
|
@@ -0,0 +1,25 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.6.2-node-browsers
|
6
|
+
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
keys:
|
11
|
+
- rswag_schema_export-{{ checksum "Gemfile.lock" }}
|
12
|
+
- rswag_schema_export-
|
13
|
+
|
14
|
+
- run:
|
15
|
+
name: install dependencies
|
16
|
+
command: bundle check || bundle install
|
17
|
+
|
18
|
+
- save_cache:
|
19
|
+
paths:
|
20
|
+
- ./vendor/bundle
|
21
|
+
key: rswag_schema_export-{{ checksum "Gemfile.lock" }}
|
22
|
+
|
23
|
+
- run:
|
24
|
+
name: run tests
|
25
|
+
command: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
DisplayCopNames: true
|
4
|
+
TargetRubyVersion: 2.6
|
5
|
+
|
6
|
+
Metrics/LineLength:
|
7
|
+
Max: 120
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Lint/AmbiguousBlockAssociation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Naming/UncommunicativeMethodParamName:
|
16
|
+
MinNameLength: 2
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/Alias:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/ClassAndModuleChildren:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/DateTime:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/FrozenStringLiteralComment:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/ModuleFunction:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/RaiseArgs:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/RescueModifier:
|
40
|
+
Exclude:
|
41
|
+
- '**/*_spec.rb'
|
42
|
+
|
43
|
+
Style/Semicolon:
|
44
|
+
Exclude:
|
45
|
+
- '**/*_spec.rb'
|
46
|
+
|
47
|
+
Style/StringLiterals:
|
48
|
+
EnforcedStyle: double_quotes
|
49
|
+
|
50
|
+
Style/SingleLineMethods:
|
51
|
+
Exclude:
|
52
|
+
- '**/*_spec.rb'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.2
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rswag_schema_export (0.1.0)
|
5
|
+
aws-sdk-s3 (~> 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (5.2.3)
|
11
|
+
actionview (= 5.2.3)
|
12
|
+
activesupport (= 5.2.3)
|
13
|
+
rack (~> 2.0)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
17
|
+
actionview (5.2.3)
|
18
|
+
activesupport (= 5.2.3)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
23
|
+
activesupport (5.2.3)
|
24
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
|
+
i18n (>= 0.7, < 2)
|
26
|
+
minitest (~> 5.1)
|
27
|
+
tzinfo (~> 1.1)
|
28
|
+
ast (2.4.0)
|
29
|
+
aws-eventstream (1.0.3)
|
30
|
+
aws-partitions (1.181.0)
|
31
|
+
aws-sdk-core (3.56.0)
|
32
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
33
|
+
aws-partitions (~> 1.0)
|
34
|
+
aws-sigv4 (~> 1.1)
|
35
|
+
jmespath (~> 1.0)
|
36
|
+
aws-sdk-kms (1.22.0)
|
37
|
+
aws-sdk-core (~> 3, >= 3.56.0)
|
38
|
+
aws-sigv4 (~> 1.1)
|
39
|
+
aws-sdk-s3 (1.43.0)
|
40
|
+
aws-sdk-core (~> 3, >= 3.56.0)
|
41
|
+
aws-sdk-kms (~> 1)
|
42
|
+
aws-sigv4 (~> 1.1)
|
43
|
+
aws-sigv4 (1.1.0)
|
44
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
45
|
+
builder (3.2.3)
|
46
|
+
coderay (1.1.2)
|
47
|
+
concurrent-ruby (1.1.5)
|
48
|
+
crass (1.0.4)
|
49
|
+
diff-lcs (1.3)
|
50
|
+
docile (1.3.2)
|
51
|
+
erubi (1.8.0)
|
52
|
+
generator_spec (0.9.4)
|
53
|
+
activesupport (>= 3.0.0)
|
54
|
+
railties (>= 3.0.0)
|
55
|
+
i18n (1.6.0)
|
56
|
+
concurrent-ruby (~> 1.0)
|
57
|
+
jaro_winkler (1.5.3)
|
58
|
+
jmespath (1.4.0)
|
59
|
+
json (2.2.0)
|
60
|
+
loofah (2.2.3)
|
61
|
+
crass (~> 1.0.2)
|
62
|
+
nokogiri (>= 1.5.9)
|
63
|
+
method_source (0.9.2)
|
64
|
+
mini_portile2 (2.4.0)
|
65
|
+
minitest (5.11.3)
|
66
|
+
nokogiri (1.10.3)
|
67
|
+
mini_portile2 (~> 2.4.0)
|
68
|
+
parallel (1.17.0)
|
69
|
+
parser (2.6.3.0)
|
70
|
+
ast (~> 2.4.0)
|
71
|
+
pry (0.12.2)
|
72
|
+
coderay (~> 1.1.0)
|
73
|
+
method_source (~> 0.9.0)
|
74
|
+
rack (2.0.7)
|
75
|
+
rack-test (1.1.0)
|
76
|
+
rack (>= 1.0, < 3)
|
77
|
+
rails-dom-testing (2.0.3)
|
78
|
+
activesupport (>= 4.2.0)
|
79
|
+
nokogiri (>= 1.6)
|
80
|
+
rails-html-sanitizer (1.0.4)
|
81
|
+
loofah (~> 2.2, >= 2.2.2)
|
82
|
+
railties (5.2.3)
|
83
|
+
actionpack (= 5.2.3)
|
84
|
+
activesupport (= 5.2.3)
|
85
|
+
method_source
|
86
|
+
rake (>= 0.8.7)
|
87
|
+
thor (>= 0.19.0, < 2.0)
|
88
|
+
rainbow (3.0.0)
|
89
|
+
rake (10.5.0)
|
90
|
+
rspec (3.8.0)
|
91
|
+
rspec-core (~> 3.8.0)
|
92
|
+
rspec-expectations (~> 3.8.0)
|
93
|
+
rspec-mocks (~> 3.8.0)
|
94
|
+
rspec-core (3.8.1)
|
95
|
+
rspec-support (~> 3.8.0)
|
96
|
+
rspec-expectations (3.8.4)
|
97
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
98
|
+
rspec-support (~> 3.8.0)
|
99
|
+
rspec-mocks (3.8.1)
|
100
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
101
|
+
rspec-support (~> 3.8.0)
|
102
|
+
rspec-support (3.8.2)
|
103
|
+
rubocop (0.72.0)
|
104
|
+
jaro_winkler (~> 1.5.1)
|
105
|
+
parallel (~> 1.10)
|
106
|
+
parser (>= 2.6)
|
107
|
+
rainbow (>= 2.2.2, < 4.0)
|
108
|
+
ruby-progressbar (~> 1.7)
|
109
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
110
|
+
ruby-progressbar (1.10.1)
|
111
|
+
simplecov (0.17.0)
|
112
|
+
docile (~> 1.1)
|
113
|
+
json (>= 1.8, < 3)
|
114
|
+
simplecov-html (~> 0.10.0)
|
115
|
+
simplecov-html (0.10.2)
|
116
|
+
thor (0.20.3)
|
117
|
+
thread_safe (0.3.6)
|
118
|
+
tzinfo (1.2.5)
|
119
|
+
thread_safe (~> 0.1)
|
120
|
+
unicode-display_width (1.6.0)
|
121
|
+
|
122
|
+
PLATFORMS
|
123
|
+
ruby
|
124
|
+
|
125
|
+
DEPENDENCIES
|
126
|
+
bundler (~> 1.17)
|
127
|
+
generator_spec
|
128
|
+
pry
|
129
|
+
railties (>= 3.1, < 6.0)
|
130
|
+
rake (~> 10.0)
|
131
|
+
rspec (~> 3.0)
|
132
|
+
rswag_schema_export!
|
133
|
+
rubocop
|
134
|
+
simplecov
|
135
|
+
|
136
|
+
BUNDLED WITH
|
137
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ruslan Tolstov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Rswag::Schema::Export
|
2
|
+
|
3
|
+
|
4
|
+
Export your schema.json file to AWS s3 bucket and import back after deploy.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rswag_schema_export'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rswag_schema_export
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Gem contains two rake tasks:
|
25
|
+
|
26
|
+
$ rake rswag:schema_export
|
27
|
+
$ rake rswag:schema_import
|
28
|
+
|
29
|
+
## Lifecicle
|
30
|
+
```bash
|
31
|
+
# Pipeline
|
32
|
+
stages:
|
33
|
+
staging:
|
34
|
+
- rspec spec
|
35
|
+
- rails rswag:specs:swaggerize
|
36
|
+
- STAGE=staging rails rswag:schema_export
|
37
|
+
- cap staging deploy
|
38
|
+
- STAGE=staging rails rswag:schema_import
|
39
|
+
```
|
40
|
+
|
41
|
+
## Capistrano
|
42
|
+
|
43
|
+
```diff
|
44
|
+
# config/deploy.rb
|
45
|
+
+ folders = %w[tmp/swagger]
|
46
|
+
namespace :deploy do
|
47
|
+
after :restart, :clear_cache do
|
48
|
+
on roles(:web), in: :groups, limit: 3, wait: 10 do
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
+ after :finishing, 'rswag:schema_import'
|
53
|
+
end
|
54
|
+
````
|
55
|
+
|
56
|
+
## Configuration
|
57
|
+
|
58
|
+
Set up ENVIRONMENT VARIABLES on your CI
|
59
|
+
|
60
|
+
```bash
|
61
|
+
# Required
|
62
|
+
RSWAG_SCHEMA_PATH='' # Example: tmp/swagger/swagger.json
|
63
|
+
RSWAG_ACCESS_KEY_ID='' # Example: XXXXXXXXXX
|
64
|
+
RSWAG_SECRET_ACCESS_KEY='' # Example: XXXXXXXXXXXXXXXXXXXXX
|
65
|
+
RSWAG_REGION='' # Example: us-west-1
|
66
|
+
RSWAG_BUCKET='' # Example: bucket-name
|
67
|
+
|
68
|
+
# Optional
|
69
|
+
STAGE='' # Default: develop
|
70
|
+
APP_NAME='' # Default: app
|
71
|
+
```
|
72
|
+
|
73
|
+
## Gitlab Variables
|
74
|
+
|
75
|
+
![image](https://user-images.githubusercontent.com/2664467/60773983-c69bdf80-a115-11e9-9f46-57d835ba4561.png)
|
76
|
+
|
77
|
+
|
78
|
+
## rswag-api
|
79
|
+
```diff
|
80
|
+
# config/initializers/rswag_api.rb
|
81
|
+
Rswag::Api.configure do |c|
|
82
|
+
+ c.swagger_root = Rails.root.to_s + '/tmp/swagger'
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
## rswag-specs
|
87
|
+
```diff
|
88
|
+
# spec/swagger_helper.rb
|
89
|
+
|
90
|
+
RSpec.configure do |config|
|
91
|
+
+ config.swagger_root = Rails.root.to_s + '/tmp/swagger'
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork it ( link )
|
98
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
100
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
5. Create a new Pull Request
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The MIT License
|
106
|
+
|
107
|
+
## About MLSDev
|
108
|
+
|
109
|
+
![MLSdev][logo]
|
110
|
+
|
111
|
+
The repo is maintained by MLSDev, Inc. We specialize in providing all-in-one solution in mobile and web development. Our team follows Lean principles and works according to agile methodologies to deliver the best results reducing the budget for development and its timeline.
|
112
|
+
|
113
|
+
Find out more [here][mlsdev] and don't hesitate to [contact us][contact]!
|
114
|
+
|
115
|
+
[mlsdev]: https://mlsdev.com
|
116
|
+
[contact]: https://mlsdev.com/contact_us
|
117
|
+
[logo]: https://raw.githubusercontent.com/MLSDev/development-standards/master/mlsdev-logo.png "Mlsdev"
|
118
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rswag/schema/export"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "aws-sdk-s3"
|
2
|
+
|
3
|
+
namespace :rswag do
|
4
|
+
desc "Import latest schema.json to app"
|
5
|
+
task :schema_import do
|
6
|
+
on roles(:all) do
|
7
|
+
RswagSchemaExport::Import.new.run do
|
8
|
+
upload!("schema.json", "#{current_path}/#{ENV['RSWAG_SCHEMA_PATH']}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RswagSchemaExport
|
2
|
+
class Export
|
3
|
+
def run
|
4
|
+
abort("RSWAG_SCHEMA_PATH is not defined. Example: tmp/swagger/swagger.json") unless ENV["RSWAG_SCHEMA_PATH"]
|
5
|
+
abort("RSWAG_ACCESS_KEY_ID is not defined") unless ENV["RSWAG_ACCESS_KEY_ID"]
|
6
|
+
abort("RSWAG_SECRET_ACCESS_KEY is not defined") unless ENV["RSWAG_SECRET_ACCESS_KEY"]
|
7
|
+
abort("RSWAG_REGION is not defined") unless ENV["RSWAG_REGION"]
|
8
|
+
abort("RSWAG_BUCKET is not defined") unless ENV["RSWAG_BUCKET"]
|
9
|
+
|
10
|
+
stage = ENV["STAGE"] || "develop"
|
11
|
+
app_name = ENV["APP_NAME"] || "app"
|
12
|
+
|
13
|
+
unless File.file?(ENV["RSWAG_SCHEMA_PATH"])
|
14
|
+
message = "Not found schema at #{ENV['RSWAG_SCHEMA_PATH']}.
|
15
|
+
For generate schema run: RAILS_ENV=test rake rswag:specs:swaggerize"
|
16
|
+
abort(message)
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
s3 = Aws::S3::Resource.new(access_key_id: ENV["RSWAG_ACCESS_KEY_ID"],
|
21
|
+
secret_access_key: ENV["RSWAG_SECRET_ACCESS_KEY"],
|
22
|
+
region: ENV["RSWAG_REGION"])
|
23
|
+
|
24
|
+
key = "schemas/#{app_name}/#{stage}_schemas/versions/#{Time.now.getutc.iso8601}.json"
|
25
|
+
# Download latest version to app
|
26
|
+
s3.bucket(ENV["RSWAG_BUCKET"]).object(key).upload_file(ENV["RSWAG_SCHEMA_PATH"])
|
27
|
+
|
28
|
+
puts("Schema has been successfully exported. Stage: #{stage} | Key: #{key}")
|
29
|
+
rescue StandardError => e
|
30
|
+
abort(e.message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RswagSchemaExport
|
2
|
+
class Import
|
3
|
+
def run
|
4
|
+
abort("RSWAG_SCHEMA_PATH is not defined. Example: tmp/swagger/swagger.json") unless ENV["RSWAG_SCHEMA_PATH"]
|
5
|
+
abort("RSWAG_ACCESS_KEY_ID is not defined") unless ENV["RSWAG_ACCESS_KEY_ID"]
|
6
|
+
abort("RSWAG_SECRET_ACCESS_KEY is not defined") unless ENV["RSWAG_SECRET_ACCESS_KEY"]
|
7
|
+
abort("RSWAG_REGION is not defined") unless ENV["RSWAG_REGION"]
|
8
|
+
abort("RSWAG_BUCKET is not defined") unless ENV["RSWAG_BUCKET"]
|
9
|
+
|
10
|
+
stage = ENV["STAGE"] || "develop"
|
11
|
+
app_name = ENV["APP_NAME"] || "app"
|
12
|
+
|
13
|
+
begin
|
14
|
+
s3 = Aws::S3::Resource.new(access_key_id: ENV["RSWAG_ACCESS_KEY_ID"],
|
15
|
+
secret_access_key: ENV["RSWAG_SECRET_ACCESS_KEY"],
|
16
|
+
region: ENV["RSWAG_REGION"])
|
17
|
+
|
18
|
+
bucket = s3.bucket(ENV["RSWAG_BUCKET"])
|
19
|
+
# Copy latest version to root
|
20
|
+
versions = bucket.objects(prefix: "schemas/#{app_name}/#{stage}_schemas/versions").collect(&:key)
|
21
|
+
|
22
|
+
last_schema_key = versions.max
|
23
|
+
bucket.object(last_schema_key).copy_to("#{ENV['RSWAG_BUCKET']}/schemas/#{app_name}/#{stage}_schemas/schema.json")
|
24
|
+
# Download schema.json
|
25
|
+
if block_given?
|
26
|
+
bucket.object("schemas/#{app_name}/#{stage}_schemas/schema.json").download_file("schema.json")
|
27
|
+
yield
|
28
|
+
else
|
29
|
+
bucket.object("schemas/#{app_name}/#{stage}_schemas/schema.json").download_file(ENV["RSWAG_SCHEMA_PATH"])
|
30
|
+
end
|
31
|
+
# Clean versions folder
|
32
|
+
old_versions = versions - versions.sort.last(5)
|
33
|
+
old_versions.each { |key| bucket.object(key).delete }
|
34
|
+
|
35
|
+
puts("Schema has been successfully imported. Stage: #{stage} | Key: #{last_schema_key}")
|
36
|
+
rescue StandardError => e
|
37
|
+
abort(e.message)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "aws-sdk-s3"
|
2
|
+
namespace :rswag do
|
3
|
+
desc "Export schema.json to cloud storage"
|
4
|
+
task schema_export: :environment do
|
5
|
+
RswagSchemaExport::Export.new.run
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Import latest schema.json to app"
|
9
|
+
task schema_import: :environment do
|
10
|
+
RswagSchemaExport::Import.new.run
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rswag_schema_export/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rswag_schema_export"
|
7
|
+
spec.version = RswagSchemaExport::VERSION
|
8
|
+
spec.authors = ["Ruslan Tolstov"]
|
9
|
+
spec.email = ["ruslan.tolstov.ua@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Export/Import your rswag schema.json during deploy with CI"
|
12
|
+
spec.description = "rswag_schema_export"
|
13
|
+
spec.homepage = "https://mlsdev.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "aws-sdk-s3", "~> 1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
25
|
+
spec.add_development_dependency "generator_spec"
|
26
|
+
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 "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "rubocop"
|
31
|
+
spec.add_development_dependency "simplecov"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rswag_schema_export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruslan Tolstov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-s3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: generator_spec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: railties
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '6.0'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.1'
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '6.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rake
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '10.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '10.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '3.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: simplecov
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
description: rswag_schema_export
|
146
|
+
email:
|
147
|
+
- ruslan.tolstov.ua@gmail.com
|
148
|
+
executables:
|
149
|
+
- console
|
150
|
+
- setup
|
151
|
+
extensions: []
|
152
|
+
extra_rdoc_files: []
|
153
|
+
files:
|
154
|
+
- ".circleci/config.yml"
|
155
|
+
- ".gitignore"
|
156
|
+
- ".rspec"
|
157
|
+
- ".rubocop.yml"
|
158
|
+
- ".ruby-version"
|
159
|
+
- CHANGELOG.md
|
160
|
+
- Gemfile
|
161
|
+
- Gemfile.lock
|
162
|
+
- LICENSE.txt
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- bin/console
|
166
|
+
- bin/setup
|
167
|
+
- lib/capistrano/tasks/rswag.rake
|
168
|
+
- lib/rswag_schema_export.rb
|
169
|
+
- lib/rswag_schema_export/railtie.rb
|
170
|
+
- lib/rswag_schema_export/schema_export.rb
|
171
|
+
- lib/rswag_schema_export/schema_import.rb
|
172
|
+
- lib/rswag_schema_export/version.rb
|
173
|
+
- lib/tasks/rswag_tasks.rake
|
174
|
+
- rswag_schema_export.gemspec
|
175
|
+
homepage: https://mlsdev.com
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubygems_version: 3.0.3
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: Export/Import your rswag schema.json during deploy with CI
|
198
|
+
test_files: []
|