Export your schema.json file to AWS S3/Azure Blob storage and import back after deploy.
Add this line to your application's Gemfile:
gem 'rswag_schema_export'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rswag_schema_export
$ rails g rswag_schema_export:install
# config/initializers/rswag_schema_export.rb
RswagSchemaExport.configure do |c|
+ c.schemas = ['swagger/client/swagger.json', 'swagger/backoffice/swagger.json']
+ c.client = :aws
end
swaggerize -> export to cloud storage -> deploy -> import from cloud storage
.gitlab-ci.yml
stages:
- test
- export_api_doc
- deploy
test:
tags:
- shell-ruby
before_script:
- RAILS_ENV=test bundle exec rails db:create db:migrate
script:
- rspec
artifacts:
paths:
- coverage/
after_script:
- RAILS_ENV=test bundle exec rails db:drop
rswag_schema_export:
dependencies: []
stage: export_api_doc
before_script:
- RAILS_ENV=test bundle exec rails db:create
tags:
- shell-ruby
script:
- rails db:schema:load rswag:specs:swaggerize RAILS_ENV=test
- STAGE=develop rails rswag:schema_export
develop:
dependencies: []
stage: deploy
tags:
- shell-ruby
script:
- bundle exec cap develop deploy
only:
- develop
# Capfile
require 'rswag_schema_export/capistrano'
# config/deploy.rb
+ append :linked_dirs, "swagger"
# config/deploy/production.rb
+ set :rswag_schema_export_disable_import, true
# config/deploy/develop.rb
+ set :rswag_schema_export_slack_webhook_url, ENV.fetch('SLACK_WEBHOOK_URL')
Set up ENVIRONMENT VARIABLES on your CI
# Required for AWS
RSWAG_AWS_ACCESS_KEY_ID='' # Example: XXXXXXXXXX
RSWAG_AWS_SECRET_ACCESS_KEY='' # Example: XXXXXXXXXXXXXXXXXXXXX
RSWAG_AWS_REGION='' # Example: us-west-1
RSWAG_AWS_BUCKET='' # Example: bucket-name
# Required for AZURE
RSWAG_AZURE_STORAGE_ACCOUNT_NAME='' # Example: XXXXX
RSWAG_AZURE_STORAGE_ACCESS_KEY='' # Example: XXXXXXXXXXXXXXXXXXXXX
RSWAG_AZURE_CONTAINER='' # Example: continter-name
# Optional
STAGE='' # Default: develop
APP_NAME='' # Default: app
# config/initializers/rswag_api.rb
Rswag::Api.configure do |c|
+ c.swagger_root = Rails.root.to_s + '/swagger'
end
- Fork it ( link )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
The MIT License
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.
Find out more here and don't hesitate to contact us!