Generate all preferred APIs by default (#613)

This commit removes support for the `id` flag from the `generate-api`
script. Additional Discovery documents are still supported via the `url`
flag.

The new behavior is to generate clients for all APIs marked as preferred
by the Discovery index if the `from_discovery` flag is `true`.
This commit is contained in:
Sai Cheemalapati 2017-08-25 14:31:03 -04:00 committed by GitHub
parent b87af01703
commit ed9ec4f787
2 changed files with 16 additions and 139 deletions

View File

@ -26,9 +26,8 @@ module Google
Discovery = Google::Apis::DiscoveryV1
desc 'gen OUTDIR', 'Generate ruby API from an API description'
method_options url: :array, file: :array, from_discovery: :boolean, id: :array,
preferred_only: :boolean, verbose: :boolean, names: :string,
names_out: :string
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
@ -38,7 +37,7 @@ module Google
Google::Apis.logger.level = Logger::DEBUG if options[:verbose]
generate_from_url(options[:url]) if options[:url]
generate_from_file(options[:file]) if options[:file]
generate_from_discovery(preferred_only: options[:preferred_only], id: options[:id] ) if options[:id] || options[:from_discovery]
generate_from_discovery(preferred_only: options[:preferred_only]) if options[:from_discovery]
create_file(options[:names_out]) { |*| generator.dump_api_names } if options[:names_out]
end
@ -69,16 +68,22 @@ module Google
end
end
def generate_from_discovery(preferred_only: false, id: nil)
def generate_from_discovery(preferred_only: false)
say 'Fetching API list'
id = Array(id)
apis = discovery.list_apis
apis.items.each do |api|
if (id.empty? && preferred_only && api.preferred?) || id.include?(api.id)
say sprintf('Loading %s, version %s from %s', api.name, api.version, api.discovery_rest_url)
generate_from_url(api.discovery_rest_url)
else
if (preferred_only && !api.preferred?)
say sprintf('Ignoring disoverable API %s', api.id)
else
# The Discovery service may returned cached versions of a Discovery document that are
# not the most recent revision. That means that subsequent requests to the same
# Discovery document URL can return different documents. The
# `discovery-artifact-manager` repo always holds the most recent revision, so it's
# easier to use that document than to force revision checking against the URL returned
# by the Discovery index.
discovery_rest_url = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/#{api.name}.#{api.version}.json"
say sprintf('Loading %s, version %s from %s', api.name, api.version, discovery_rest_url)
generate_from_url(discovery_rest_url)
end
end
end

View File

@ -4,134 +4,6 @@
DIR=$(dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))
API_IDS=(acceleratedmobilepageurl:v1 \
adexchangebuyer:v1.4 \
adexchangebuyer2:v2beta1 \
adexchangeseller:v2.0 \
admin:directory_v1 \
admin:datatransfer_v1 \
admin:reports_v1 \
adsense:v1.4 \
adsensehost:v4.1 \
analytics:v3 \
analyticsreporting:v4 \
androidenterprise:v1 \
androidpublisher:v2 \
appengine:v1 \
appsactivity:v1 \
appsmarket:v2 \
appstate:v1 \
autoscaler:v1beta2 \
bigquery:v2 \
blogger:v3 \
books:v1 \
calendar:v3 \
civicinfo:v2 \
classroom:v1 \
cloudbilling:v1 \
cloudbuild:v1 \
clouddebugger:v2 \
clouderrorreporting:v1beta1 \
cloudfunctions:v1 \
cloudkms:v1 \
cloudkms:v1beta1 \
cloudlatencytest:v2 \
cloudmonitoring:v2beta2 \
cloudresourcemanager:v1beta1 \
cloudresourcemanager:v1 \
cloudtrace:v1 \
clouduseraccounts:beta \
compute:v1 \
compute:beta \
container:v1 \
content:v2 \
coordinate:v1 \
customsearch:v1 \
dataflow:v1b3 \
dataproc:v1 \
datastore:v1 \
deploymentmanager:v2 \
dfareporting:v2.6 \
dfareporting:v2.7 \
dfareporting:v2.8 \
discovery:v1 \
dns:v1 \
dns:v2beta1 \
doubleclickbidmanager:v1 \
doubleclicksearch:v2 \
drive:v2 \
drive:v3 \
firebasedynamiclinks:v1 \
firebaserules:v1 \
fitness:v1 \
fusiontables:v2 \
games:v1 \
gamesConfiguration:v1configuration \
gamesManagement:v1management \
gan:v1beta1 \
genomics:v1 \
gmail:v1 \
groupsmigration:v1 \
groupssettings:v1 \
iam:v1 \
identitytoolkit:v3 \
kgsearch:v1 \
language:v1beta1 \
language:v1 \
licensing:v1 \
logging:v2beta1 \
logging:v2 \
manager:v1beta2 \
manufacturers:v1 \
mapsengine:v1 \
mirror:v1 \
ml:v1 \
oauth2:v2 \
pagespeedonline:v2 \
partners:v2 \
people:v1 \
plus:v1 \
plusDomains:v1 \
prediction:v1.6 \
proximitybeacon:v1beta1 \
pubsub:v1 \
qpxExpress:v1 \
replicapool:v1beta2 \
replicapoolupdater:v1beta1 \
reseller:v1 \
resourceviews:v1beta2 \
runtimeconfig:v1 \
script:v1 \
searchconsole:v1 \
servicecontrol:v1 \
servicemanagement:v1 \
serviceuser:v1 \
sheets:v4 \
siteVerification:v1 \
slides:v1 \
sourcerepo:v1 \
spanner:v1 \
speech:v1beta1 \
sqladmin:v1beta4 \
storage:v1 \
storagetransfer:v1 \
surveys:v2 \
tagmanager:v1 \
tagmanager:v2 \
taskqueue:v1beta2 \
tasks:v1 \
toolresults:v1beta3 \
tracing:v1 \
translate:v2 \
urlshortener:v1 \
vision:v1 \
webfonts:v1 \
webmasters:v3 \
youtube:v3 \
youtubeAnalytics:v1 \
youtubereporting:v1 \
)
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 \
@ -139,4 +11,4 @@ URLS=(https://content.googleapis.com/discovery/v1/apis/appsmarket/v2/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[*]} --id=${API_IDS[*]}
echo 'a' | bundle exec bin/generate-api gen generated --from_discovery=true --names_out=$DIR/api_names_out.yaml --url=${URLS[*]}