apiaryio / apiary-client

Apiary CLI client
https://help.apiary.io/tools/apiary-cli/
MIT License
204 stars 70 forks source link

uninitialized constant Apiary::Command::Fetch::OpenStruct (NameError) #219

Open mark-young-atg opened 4 months ago

mark-young-atg commented 4 months ago

The apiary fetch command is giving me an OpenStruct error:

➜  apiary fetch --api-name="api" --output="api.apib"
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
/Users/user/.rvm/gems/ruby-3.3.1@apidocs/gems/apiaryio-0.17.0/lib/apiary/command/fetch.rb:12:in `initialize': uninitialized constant Apiary::Command::Fetch::OpenStruct (NameError)

      @options = OpenStruct.new(opts)
                 ^^^^^^^^^^
    from /Users/user/.rvm/gems/ruby-3.3.1@apidocs/gems/apiaryio-0.17.0/lib/apiary/cli.rb:28:in `new'

This can be fixed by adding require 'ostruct' after the require 'json' in gems/apiaryio-0.17.0/lib/apiary/command/fetch.rb e.g.

➜  head -7 /Users/user/.rvm/gems/ruby-3.3.1@apidocs/gems/apiaryio-0.17.0/lib/apiary/command/fetch.rb
# encoding: utf-8

require 'rest-client'
require 'json'
require 'ostruct'

require 'apiary/agent'

I have not raised this as a pull request at this point as I felt it was worth a discussion first. I'm not sure if this is related to the version of Ruby. I'm using v3.3.1. Please let me know your thoughts and whether I should raise this as a PR?

amnerip-fubotv commented 3 months ago

I went ahead and submitted a simple PR to fix this. I'd love to hear the maintainers' comments on how to improve it though. https://github.com/apiaryio/apiary-client/pull/220

QuentinLemCode commented 3 weeks ago

A workaround is to use the environment variable RUBYOPT='-rostruct'

Example : RUBYOPT='-rostruct' apiary preview