rswag / rswag

Seamlessly adds a Swagger to Rails-based API's
MIT License
2.02k stars 435 forks source link

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

Open stevegeek opened 1 year ago

stevegeek commented 1 year ago

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:

perfetti commented 1 year ago

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..

https://github.com/rswag/rswag/blob/01067749fdaf31296e32db8faf7764a98b02650f/rswag-specs/lib/tasks/rswag-specs_tasks.rake#L21

stevegeek commented 1 year ago

@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 commented 1 year ago

@stevegeek, see https://github.com/rswag/rswag/issues/359#issuecomment-728836401

stevegeek commented 1 year ago

@romanblanco ok thanks!

stale[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If the issue is still relevant to you, please leave a comment stating so to keep the issue from being closed. Thank you for your contributions.