rswag_schema_export 0.2.0 → 0.2.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
  SHA256:
3
- metadata.gz: 56dc1566ef40b4689c9546a3f5daa0b62c5aa066f56af01de96e563fb8b796b5
4
- data.tar.gz: 1e3c00c1812d7f1748525263f24573846064394ce34f0e9a989893cc0d7f9323
3
+ metadata.gz: 4ece302cfc94feecbe4036c53b240af0e2fc95d53969f8224a3fd411510f6b6b
4
+ data.tar.gz: 6d7d15132174d2108961ee218f92bcb53d1f419b874572e186430921cac4d939
5
5
  SHA512:
6
- metadata.gz: 3743c24a0de165ae785740537ec41ad3deb3aa76f00b78b354258d907d7f42e049e9fa959b0db6b597765c4f584becb393e6972367b37b3eb3cc9b4d9e7e3f93
7
- data.tar.gz: '09ef3131b1f7ae054a69eda7b0bd57787e9c3bbfc5481cce831fc3edf2f75a0a0ab9c3749c927c77e3de0261a1fff86b1cf40a6fda2c8a6e96c595b2ae6a33a1'
6
+ metadata.gz: d8219a08a4582429b6a1cdbebbc1e02a47268bebe098485b82fea4c82c1e711d480c68002868a896d48a4dec02f7c9574fd7fe9151346abd2a7fb8af6565ba86
7
+ data.tar.gz: 8ea02fe62ff0def8ca211c22107ce82b3bdd34f90984b637715a392313d23d2d722d59df84055a5c93b5c76d03e71360cc8e9e7b93ceb57549f39ccd55b576b8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rswag_schema_export (0.1.1)
4
+ rswag_schema_export (0.2.1)
5
5
  aws-sdk-s3 (~> 1)
6
6
  azure-storage-blob (~> 1.1)
7
7
 
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # [Beta] Rswag::Schema::Export
1
+ # Rswag::Schema::Export
2
2
 
3
3
  [![CircleCI](https://circleci.com/gh/MLSDev/rswag_schema_export.svg?style=svg)](https://circleci.com/gh/MLSDev/rswag_schema_export)
4
4
 
5
5
 
6
- Export your schema.json file to AWS s3 bucket and import back after deploy.
6
+ Export your schema.json file to **AWS S3**/**Azure Blob** storage and import back after deploy.
7
7
 
8
8
  ## Installation
9
9
 
@@ -22,40 +22,73 @@ Or install it yourself as:
22
22
  $ gem install rswag_schema_export
23
23
  $ rails g rswag_schema_export:install
24
24
 
25
- ## Usage
26
-
27
- Gem contains two rake tasks:
28
-
29
- $ rake rswag:schema_export
30
- $ rake rswag:schema_import
25
+ ## Set up
26
+ ```diff
27
+ # config/initializers/rswag_schema_export.rb
28
+ RswagSchemaExport.configure do |c|
29
+ + c.schemas = ['swagger/client/swagger.json', 'swagger/backoffice/swagger.json']
30
+ + c.client = :aws
31
+ end
32
+ ```
33
+ ## Lifecycle
34
+ ```
35
+ swaggerize -> export to cloud storage -> deploy -> import from cloud storage
36
+ ```
31
37
 
32
- ## Lifecicle
33
- ```bash
34
- # Pipeline
38
+ ## Export example with CI
39
+ ```yaml
40
+ .gitlab-ci.yml
35
41
  stages:
36
- staging:
37
- - rspec spec
38
- - rails rswag:specs:swaggerize
39
- - STAGE=staging rails rswag:schema_export
40
- - cap staging deploy
41
- - STAGE=staging rails rswag:schema_import
42
+ - test
43
+ - export_api_doc
44
+ - deploy
45
+ test:
46
+ tags:
47
+ - shell-ruby
48
+ before_script:
49
+ - RAILS_ENV=test bundle exec rails db:create db:migrate
50
+ script:
51
+ - rspec
52
+ artifacts:
53
+ paths:
54
+ - coverage/
55
+ after_script:
56
+ - RAILS_ENV=test bundle exec rails db:drop
57
+ rswag_schema_export:
58
+ dependencies: []
59
+ stage: export_api_doc
60
+ before_script:
61
+ - RAILS_ENV=test bundle exec rails db:create
62
+ tags:
63
+ - shell-ruby
64
+ script:
65
+ - rails db:schema:load rswag:specs:swaggerize RAILS_ENV=test
66
+ - STAGE=develop rails rswag:schema_export
67
+ develop:
68
+ dependencies: []
69
+ stage: deploy
70
+ tags:
71
+ - shell-ruby
72
+ script:
73
+ - bundle exec cap develop deploy
74
+ only:
75
+ - develop
42
76
  ```
43
77
 
44
- ## Capistrano
78
+
79
+ ## Import example with Capistrano
80
+
81
+ ```diff
82
+ # Capfile
83
+ require 'rswag_schema_export/capistrano'
84
+ ```
45
85
 
46
86
  ```diff
47
87
  # config/deploy.rb
48
- + folders = %w[swagger]
49
- namespace :deploy do
50
- after :restart, :clear_cache do
51
- on roles(:web), in: :groups, limit: 3, wait: 10 do
52
-
53
- end
54
- end
55
- + after :finishing, 'rswag:schema_import'
56
- end
88
+ + append :linked_dirs, "swagger"
57
89
  ````
58
90
 
91
+
59
92
  ## Configuration
60
93
 
61
94
  Set up ENVIRONMENT VARIABLES on your CI
@@ -82,16 +115,6 @@ APP_NAME='' # Default: app
82
115
 
83
116
  ![image](https://user-images.githubusercontent.com/2664467/64493266-bc699f00-d286-11e9-8827-e99d0eada9ce.png)
84
117
 
85
- ## rswag_schema_export
86
- ```diff
87
- # config/initializers/rswag_schema_export.rb
88
- RswagSchemaExport.configure do |c|
89
- + c.schemas = ['swagger/client/swagger.json', 'swagger/backoffice/swagger.json']
90
- + c.client = :aws
91
- end
92
-
93
- ```
94
-
95
118
  ## rswag-api
96
119
  ```diff
97
120
  # config/initializers/rswag_api.rb
@@ -1 +1 @@
1
- load File.expand_path("tasks/rswag.rake", __dir__)
1
+ load File.expand_path("../tasks/rswag.rake", __FILE__)
@@ -52,7 +52,7 @@ module RswagSchemaExport
52
52
  def copy_latest_version_to_root(last_schema_key, schema_id)
53
53
  if aws_client?
54
54
  bucket.object(last_schema_key)
55
- .copy_to("#{ENV['RSWAG_BUCKET']}/schemas/#{app_name}/#{stage}_#{schema_id}/schema.json")
55
+ .copy_to("#{ENV['RSWAG_AWS_BUCKET']}/schemas/#{app_name}/#{stage}_#{schema_id}/schema.json")
56
56
  else
57
57
  client.copy_blob(ENV["RSWAG_AZURE_CONTAINER"], "schemas/#{app_name}/#{stage}_#{schema_id}/schema.json",
58
58
  ENV["RSWAG_AZURE_CONTAINER"], last_schema_key)
@@ -60,6 +60,7 @@ module RswagSchemaExport
60
60
  end
61
61
 
62
62
  def download_file(schema_id, path)
63
+ FileUtils.mkdir_p(path.split('/')[0...-1].join('/'))
63
64
  if aws_client?
64
65
  bucket.object("schemas/#{app_name}/#{stage}_#{schema_id}/schema.json").download_file(path)
65
66
  else
@@ -1,15 +1,14 @@
1
- require "rswag_schema_export/schema_import"
2
-
3
1
  namespace :rswag do
4
- desc "Import latest schema.json to app"
2
+ desc 'schema_import'
5
3
  task :schema_import do
6
- on roles(:all) do
7
- stage = ENV["STAGE"] || fetch(:stage, "develop")
8
- RswagSchemaExport::Import.new.run(stage) do
9
- RswagSchemaExport.config.shemas.map do |schema|
10
- upload!(schema, "#{current_path}/#{schema}")
4
+ on roles(fetch(:rswag_schema_export_roles, :app)) do
5
+ within release_path do
6
+ with rails_env: fetch(:rails_env) do
7
+ execute :rake, 'rswag:schema_import'
11
8
  end
12
9
  end
13
10
  end
14
11
  end
15
12
  end
13
+
14
+ after 'deploy:finishing', 'rswag:schema_import'
@@ -1,3 +1,3 @@
1
1
  module RswagSchemaExport
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
@@ -1,11 +1,11 @@
1
1
  namespace :rswag do
2
- desc "Export schema.json to cloud storage"
3
- task schema_export: :environment do
4
- RswagSchemaExport::Export.new.run
5
- end
6
-
7
- desc "Import latest schema.json to app"
8
- task schema_import: :environment do
9
- RswagSchemaExport::Import.new.run
10
- end
11
- end
2
+ desc "Export schema.json to cloud storage"
3
+ task schema_export: :environment do
4
+ RswagSchemaExport::Export.new.run
5
+ end
6
+
7
+ desc "Import latest schema.json to app"
8
+ task schema_import: :environment do
9
+ RswagSchemaExport::Import.new.run
10
+ end
11
+ end
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.0
4
+ version: 0.2.1
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-09-09 00:00:00.000000000 Z
11
+ date: 2019-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3