Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Issue #77

Closed
klobuczek opened this issue Jul 13, 2017 · 8 comments
Closed

Dependency Issue #77

klobuczek opened this issue Jul 13, 2017 · 8 comments

Comments

@klobuczek
Copy link

rswag depends on rswag-specs
rswag-specs requires ''rspec/core' without defining the dependency in gemspec
rswag seems to inject itself into default Rakefile
when run in non test enviroment where rspec-core is not present this causes an error

Step 10/11 : RUN RAILS_ENV=docker bundle exec rake assets:precompile
 ---> Running in 7e0706635cc5
rake aborted!
LoadError: cannot load such file -- rspec/core
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/rswag-specs-1.4.0/lib/rswag/specs.rb:1:in `<top (required)>'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/rswag-1.4.0/lib/rswag.rb:1:in `<top (required)>'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:82:in `require'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:77:in `each'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:77:in `block in require'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:66:in `each'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:66:in `require'
/var/lib/gems/2.4.0/gems/bundler-1.15.1/lib/bundler.rb:108:in `require'
/var/www/org-api/current/config/application.rb:13:in `<top (required)>'
/var/www/org-api/current/Rakefile:4:in `require_relative'
/var/www/org-api/current/Rakefile:4:in `<top (required)>'
/var/www/org-api/current/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
@domaindrivendev
Copy link
Collaborator

Yep - this is an interesting one. If I include rspec in any of the gemspecs it will be added to the application's runtime dependencies and this would be undesirable as it would never be used after initial dev/testing.

In fact rswag-specs itself shouldn't even be added to the application's runtime dependencies. On the one-hand, I like the idea of a single gem (i.e. rswag) that pulls in the complete toolchain. But the downside is that there's no way (at least with my understanding of the Gemfile/gemspec interaction) to say which components should be dev/test vs runtime. You can work around this by avoiding the top-level package and pulling in each component in your Gemfile under the appropriate group:

# Gemfile
gem 'rswag-api'
gem 'rswag-ui'

groups :test do
  gem 'rspec-rails'
  gem 'rswag-specs'
end

But this is just a workaround and I would like to address the bug you've reported. Interested to get other's thoughts?

@domaindrivendev
Copy link
Collaborator

Perhaps keep it as an assumed dependency (i.e. out of the gemspec) and then put some conditional logic to check Rails.env and only require the relevant code if it's "development" OR "test"?

@klobuczek
Copy link
Author

I think you might have not separated sufficiently the subgems. If rswag-specs has any functionality that should ever be run in any other environment than test then this part should be moved to a different subgem. That subgem should not have dependency on any rspec. What depends on rspec must ever only run in test environment. The idea of having 1 super gem encompassing everything is flawed. Nearly all prominent gems have a main gem and in documentation they reference some rspec helper gem to be optionally included in the Gemfile.

@domaindrivendev
Copy link
Collaborator

You've missed my point. I'm saying that rswag-specs DOESN'T CONTAIN any functionality that should ever be run outside of the test environment.

As someone who's been using different Swagger workflows for several years, I'm happy with the separation of concerns with the current gems. They go as follows ...

  1. rswag-specs - for testing and generating a Swagger compatible spec during DEV/TEST.
  2. rswag-api - for exposing the Swagger.json as a JSON endpoint at runtime.
  3. rswag-ui - for exposing the swagger-ui at runtime

These provide value independently and as a composite (hence the top-level gem that combines them). For your information, many prominent gems do in fact use this pattern of combining subgems including Rails and Rspec.

@klobuczek
Copy link
Author

My apologies, you are right, rails does include testing framework inside their subgems. Not in the gemspec you referenced as all those gems are production gems and there is no mix between test and other environments. But this gemspec references mini-test https://github.com/rails/rails/blob/master/activesupport/activesupport.gemspec.
rspec gem does include other subgems, but all those gems are for test environment, so no mix.
In any case putting 'rswag-specs' in the test group solves my problem.
Thanks for the good work.

@supairish
Copy link

I just ran into this same issue when trying to deploy an app with newly added swagger docs. Declaring each gem individually fixed it for me. This should probably be added to the README for clarification and to help others new to rswag, like myself

@loicginoux
Copy link

I also had this issue and used the work around proposed here. The only problem now is that you have to pass the test env to swaggerize your doc. the rake task does not exist on other envs :/

RAILS_ENV=test rake rswag:specs:swaggerize

@domaindrivendev
Copy link
Collaborator

Closing as details for including gems in appropriate bundle groups have been added to readme - https://github.com/domaindrivendev/rswag#getting-started.

stkenny pushed a commit to Digital-Repository-of-Ireland/dri-app that referenced this issue Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants