Generate non-preferred APIs by default

Warn instead of failing on Discovery URL requests that error. Some
URLs on the Discovery index return 404s, so skipping them saves trouble.
This commit is contained in:
Google APIs 2017-08-25 16:44:26 -07:00 committed by Sai Cheemalapati
parent f93e0a00f0
commit 4759ffb5dd
2 changed files with 8 additions and 6 deletions

View File

@ -28,7 +28,6 @@ module Google
desc 'gen OUTDIR', 'Generate ruby API from an API description'
method_options url: :array, file: :array, from_discovery: :boolean, preferred_only: :boolean,
verbose: :boolean, names: :string, names_out: :string
method_option :preferred_only, default: true
def gen(dir)
ensure_active_support
require 'google/apis/generator'
@ -55,7 +54,12 @@ module Google
no_commands do
def generate_from_url(urls)
Array(urls).each do |url|
json = discovery.http(:get, url)
begin
json = discovery.http(:get, url)
rescue Google::Apis::ClientError
warn sprintf('Failed request, skipping %s', url)
next
end
generate_api(json)
end
end

View File

@ -8,9 +8,7 @@ URLS=(https://content.googleapis.com/discovery/v1/apis/appsmarket/v2/rest \
https://content.googleapis.com/discovery/v1/apis/youtubePartner/v1/rest \
https://content.googleapis.com/discovery/v1/apis/compute/beta/rest \
https://developers.google.com/my-business/samples/mybusiness_google_rest_v3.json \
https://monitoring.googleapis.com/\$discovery/rest?version=v3 \
https://www.googleapis.com/discovery/v1/apis/admin/datatransfer_v1/rest \
https://www.googleapis.com/discovery/v1/apis/admin/directory_v1/rest
https://monitoring.googleapis.com/\$discovery/rest?version=v3
)
echo 'a' | bundle exec bin/generate-api gen generated --from_discovery=true --names_out=$DIR/api_names_out.yaml --url=${URLS[*]}
echo 'a' | bundle exec bin/generate-api gen generated --from-discovery --no-preferred-only --names-out=$DIR/api_names_out.yaml --url=${URLS[*]}