ruby-grape / grape-swagger-rails

Swagger UI as Rails Engine for grape-swagger gem.
MIT License
251 stars 197 forks source link

Ensure that ostruct is loaded #116

Closed jrmhaig closed 7 months ago

jrmhaig commented 7 months ago

Following an upgrade of the json gem we are seeing the following error:

.../.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/grape-swagger-rails-0.4.0/lib/grape-swagger-rails.rb:4:in `<module:GrapeSwaggerRails>': uninitialized constant GrapeSwaggerRails::OpenStruct (NameError)

  class Options < OpenStruct

It turns out that grape-swagger-rails depends on ostruct being required elsewhere in the app. This was being done for us by json and with version 2.7.2 ostruct has become optional. See https://github.com/flori/json/pull/565

One solution is to add require 'ostruct' immediately prior to where it is used. This is done in this PR.

Another solution would be to not use OpenStruct as it is now discouraged - see https://docs.ruby-lang.org/en/3.0/OpenStruct.html#class-OpenStruct-label-Caveats

grape-bot commented 7 months ago
1 Warning
:warning: There're library changes, but not tests. That's OK as long as you're refactoring existing code.

Generated by :no_entry_sign: Danger

dblock commented 7 months ago

Thanks. This works, want to add a line to CHANGELOG? I'll merge and cut a release, been a while.

dblock commented 7 months ago

Merged, thanks. ~If you have more cycles, https://github.com/ruby-grape/grape-swagger-rails/issues/115 is one that could use some attention :)~

dblock commented 7 months ago

I fixed up the test matrix and release 0.5.0 with this change.