Skip to content

Commit c0dcd58

Browse files
committed
integrate rswag and swagger-ui-react (wip)
1 parent 3b01231 commit c0dcd58

File tree

15 files changed

+379
-80
lines changed

15 files changed

+379
-80
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,3 @@ gem "image_processing", "~> 1.2"
129129

130130
# Document API
131131
gem 'rswag-api'
132-
gem 'rswag-ui'

app/assets/javascripts/application.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@
77
// = require x3dom
88
// = require data-confirm-modal
99
// = require_tree .
10-
11-

app/javascript/api_doc_viewer/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SwaggerApiDoc extends React.Component {
2222
return (
2323
<SwaggerUI
2424
ref={this.ref}
25-
url={api.apiUrl('/api_doc')}
25+
url={api.docUrl()}
2626
onComplete={this.preAuthorize}
2727
/>
2828
);

app/javascript/utils/WhatsOptApi.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class WhatsOptApi {
4545
return `${this.relativeUrlRoot}${API_URL}${path}`;
4646
}
4747

48+
// eslint-disable-next-line class-methods-use-this
49+
docUrl() {
50+
return '/api_doc/v1/swagger.yaml';
51+
}
52+
4853
openmdaoChecking(mdaId, callback) {
4954
const path = `/analyses/${mdaId}/openmdao_checking`;
5055
axios.post(this.apiUrl(path))

app/views/api_docs/show.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<% if current_user %>
2-
<div id="apidoc" data-api-key="<%=current_user.api_key%>"></div>
2+
<div id="apidoc" data-api-key="<%=current_user.api_key%>"></div>
33
<% else %>
4-
<div id="apidoc"></div>
4+
<div id="apidoc"></div>
55
<% end %>
6+
<div id="swagger-ui-config" data-swagger-ui-config="<%= @config_object.to_json %>"></div>>
67

7-
<%= javascript_pack_tag 'api_doc_viewer_application' %>
8-
8+
<%= javascript_pack_tag 'api_doc_viewer_application' %>

config/initializers/rswag-ui.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

config/routes.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
Rails.application.routes.draw do
22

3-
mount Rswag::Ui::Engine => '/api-docs'
4-
mount Rswag::Api::Engine => '/api-docs'
53
devise_for :users
64
resources :users, only: [:show]
75
resource :api_doc, only: [:show]
@@ -49,4 +47,5 @@
4947
end
5048
root to: redirect('users/sign_in')
5149

50+
mount Rswag::Api::Engine => '/api_doc'
5251
end

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"react-promise-tracker": "^2.0.5",
2929
"react-table": "^7.0.0-rc.10",
3030
"save-svg-as-png": "^1.4.14",
31-
"swagger-ui-react": "3.24.0",
31+
"swagger-ui-react": "^3.25.0",
3232
"trix": "^1.0.0",
3333
"x3dom": "^1.7.2"
3434
},
@@ -53,4 +53,4 @@
5353
"lint": "yarn run eslint --ext .js --ext .jsx app/javascript",
5454
"lintfix": "yarn run eslint --fix --ext .js --ext .jsx app/javascript"
5555
}
56-
}
56+
}

spec/rails_helper.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This file is copied to spec/ when you run 'rails generate rspec:install'
2+
require 'spec_helper'
3+
ENV['RAILS_ENV'] ||= 'test'
4+
require File.expand_path('../config/environment', __dir__)
5+
# Prevent database truncation if the environment is production
6+
abort("The Rails environment is running in production mode!") if Rails.env.production?
7+
require 'rspec/rails'
8+
# Add additional requires below this line. Rails is not loaded until this point!
9+
10+
# Requires supporting ruby files with custom matchers and macros, etc, in
11+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12+
# run as spec files by default. This means that files in spec/support that end
13+
# in _spec.rb will both be required and run as specs, causing the specs to be
14+
# run twice. It is recommended that you do not name files matching this glob to
15+
# end with _spec.rb. You can configure this pattern with the --pattern
16+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17+
#
18+
# The following line is provided for convenience purposes. It has the downside
19+
# of increasing the boot-up time by auto-requiring all files in the support
20+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
21+
# require only the support files necessary.
22+
#
23+
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
24+
25+
# Checks for pending migrations and applies them before tests are run.
26+
# If you are not using ActiveRecord, you can remove these lines.
27+
begin
28+
ActiveRecord::Migration.maintain_test_schema!
29+
rescue ActiveRecord::PendingMigrationError => e
30+
puts e.to_s.strip
31+
exit 1
32+
end
33+
RSpec.configure do |config|
34+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
35+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
36+
37+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
38+
# examples within a transaction, remove the following line or assign false
39+
# instead of true.
40+
config.use_transactional_fixtures = true
41+
42+
# You can uncomment this line to turn off ActiveRecord support entirely.
43+
# config.use_active_record = false
44+
45+
# RSpec Rails can automatically mix in different behaviours to your tests
46+
# based on their file location, for example enabling you to call `get` and
47+
# `post` in specs under `spec/controllers`.
48+
#
49+
# You can disable this behaviour by removing the line below, and instead
50+
# explicitly tag your specs with their type, e.g.:
51+
#
52+
# RSpec.describe UsersController, type: :controller do
53+
# # ...
54+
# end
55+
#
56+
# The different available types are documented in the features, such as in
57+
# https://relishapp.com/rspec/rspec-rails/docs
58+
config.infer_spec_type_from_file_location!
59+
60+
# Filter lines from Rails gems in backtraces.
61+
config.filter_rails_from_backtrace!
62+
# arbitrary gems may also be filtered via:
63+
# config.filter_gems_from_backtrace("gem name")
64+
end

0 commit comments

Comments
 (0)