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

[BUG] rswag:specs:swaggerize does not respect rswag_dry_run set in RSpec config #679

Open
stevegeek opened this issue Oct 9, 2023 · 4 comments

Comments

@stevegeek
Copy link

Describe the bug

The rake task rswag:specs:swaggerize checks Rswag::Specs.config.rswag_dry_run to determine if --dry-run should be used.

However, if Im not mistaken, this check happens before an application's test/RSpec configuration has even been parsed so all the Rswag configuration values that are proxied from RSpec configuration will always be nil.

Steps to Test or Reproduce

Follow docs and add to test.rb:

RSpec.configure do |config|
  config.rswag_dry_run = false
end

Run rake task, notice that it is not observed as test.rb is not loaded till later.

Expected behavior

Documentation implies I should expect to not run a dry run, but rswag_dry_run is always nil at the point of the check

Screenshots

Eg adding a couple of log lines:

$ rails rswag:specs:swaggerize

** Checking Rswag::Specs.config.rswag_dry_run in rake task

<snip>/rspec-core-3.12.2/exe/rspec --pattern spec/requests/\*\*/\*_spec.rb,\ spec/api/\*\*/\*_spec.rb,\ spec/integration/\*\*/\*_spec.rb --format Rswag::Specs::OpenapiFormatter --dry-run --order defined

** Setting RSpec.config.rswag_dry_run

Generating OpenAPI spec...
...

Additional context

Add any other context about the problem here.

Dependency versions

The version of are you using for:

  • Rswag: 2.10.1
  • RSpec: 3.12.2
  • Rails: 7.0.8
  • Ruby: 3.2.2
@perfetti
Copy link

perfetti commented Oct 24, 2023

That config variable is supposed to be swagger_dry_run not rswag_dry_run that's probably your problem.

If you check this, you can see you've got the variable name wrong..

if Rswag::Specs::RSPEC_VERSION > 2 && Rswag::Specs.config.swagger_dry_run

@stevegeek
Copy link
Author

@perfetti right sorry, you are correct in the case of the main branch, but this config has been renamed in v3 (see #574). I've been working off that branch for a while now and completely forgot it had a different name before!

See:

https://github.com/romanblanco/rswag/blob/drop-openapi-v2/rswag-specs/lib/tasks/rswag-specs_tasks.rake#L21

I believe the problem still stands, even with the v2 naming. I will double check when I get a second and update this issue.

I assume the problem is as described, that setting this value in your swagger/openapi spec helper wont help as that wont be evaluated yet at the point the rake task is running

@romanblanco
Copy link
Member

@stevegeek, see #359 (comment)

@stevegeek
Copy link
Author

@romanblanco ok thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants