I don't usually work with Ruby, but I've recently needed to generate an API from a downloaded discovery document for this client library. I took the following steps:
rvm install 2.2.2gem install activesupportgem install thorgem install google-api-client
generate-api gen \
/tmp/ruby-client-library \
--file=/usr/local/google/home/$USER/discovery.jsonI would then receive an error output like the following:
/usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/lib/google/apis/generator/annotator.rb:47:in `read': No such file or directory @ rb_sysopen - /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/api_names_out.yaml (Errno::ENOENT)
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/lib/google/apis/generator/annotator.rb:47:in `initialize'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/lib/google/apis/generator.rb:31:in `new'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/lib/google/apis/generator.rb:31:in `initialize'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:107:in `new'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:107:in `generator'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:96:in `generate_api'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:70:in `block (2 levels) in generate_from_file'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:69:in `open'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:69:in `block in generate_from_file'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:68:in `each'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:68:in `generate_from_file'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:38:in `gen'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.15.0/bin/generate-api:124:in `<top (required)>'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/bin/generate-api:23:in `load'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/bin/generate-api:23:in `<main>'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/google/home/$USER/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
I checked the installation directory, and found that it didn't include the api_names_out.yaml file. I added it back in and was able to successfully generate the API files.
@msaniscalchi I tried to replicate the error and couldn't. What OS are you using? I suspect this might be one of those one-off errors due to permissions.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
I don't think it could be a permissions issue given that the google-api-client installation was to an RVM directory to which I have full access. The only thing missing in the installation was the api_names_out.yaml file needed to run generate-api.
generate-api currently expects to find api_names_out.yaml in the working directory. To get generation working you'd either want to run the script in the root directory of google-api-ruby-client, or copy https://github.com/google/google-api-ruby-client/blob/master/api_names_out.yaml into your working directory.
Otherwise, @bantini the generate-api script should probably be modified to accept a flag for the names_out parameter, so this doesn't bug out this way for more people.
So it sounds like it may have worked for the unintended reason that I was in the installation directory after I copied the file there?
Still, after installing the library with gem, I'm not likely to be in the root directory of google-api-ruby-client or be in a directory containing api_names_out.yaml. From my perspective, I see a new generate-api command that doesn't work after running gem install google-api-client. Shouldn't it know where api_names_out.yaml is located by default?
The expectation is that it's in the current working directory by default. I think we should modify it to either look in the gem folder or have it specified as a flag. I'll leave that choice to you, @bantini
This is still broken in v0.23.6:
/Users/kroehrenbeck/src/gs/goldstar/.gem/ruby/2.5.5/gems/google-api-client-0.23.6/lib/google/apis/generator/annotator.rb:47:in `read': No such file or directory @ rb_sysopen - /Users/kroehrenbeck/src/gs/goldstar/.gem/ruby/2.5.5/gems/google-api-client-0.23.6/api_names_out.yaml
I don't fully follow the thread here about the working directory, but this resolves the issue:
cp /Users/kroehrenbeck/src/gs/goldstar/.gem/ruby/2.5.5/gems/google-api-client-0.23.6/api_names{,_out}.yaml
It looks like this file was excluded from the gem package in the following commit. Perhaps this can simply be fixed by not excluding the file from the gem package?
https://github.com/googleapis/google-api-ruby-client/commit/5ce622ccd200a67e749456b33bf95251811595a3#diff-9f1ff4c0bfd372130043e66d2a89e887R17
The api_names_out.yaml file is very large, which is probably why it was excluded. I am not very familiar with how this gem generates files, but it looks to me that generate-api will create the file when passing the names_out option. But there does look to be an issue where that value is not passed to the generator.
Ah, it looks like this was also patched in #746, which was first released in 0.27.0. Because of this I am resolving this issue. Please upgrade to 0.27.0 if you can.
Worked great after upgrading to 0.27.0. Thanks @blowmage!