How do I specify my own icons so they show up in a Google Endpoints API discovery document? -
i've tried icons section contain own icons, rather google search ones trying monkey patch apiconfiggenerator.get_descriptor_defaults
. unfortunately these ignored/discarded when discovery document finalized.
{ "kind": "discovery#restdescription", "etag": "...", "discoveryversion": "v1", "id": "acme:v1", "name": "acme", "version": "v1", "description": "acme api", "ownerdomain": "google.com", "ownername": "google", "icons": { "x16": "http://www.google.com/images/icons/product/search-16.gif", # <-- acme icon url here! "x32": "http://www.google.com/images/icons/product/search-32.gif" # <-- }, "protocol": "rest", "baseurl": "http://acme.appspot.com/_ah/api/acme/v1/", "basepath": "/_ah/api/acme/v1/", "rooturl": "http://acme.appspot.com/_ah/api/", "servicepath": "acme/v1/", "batchpath": "batch", "parameters": {
how work around this, if @ all?
this not supported yet in google.appengine.api.endpoints
library possible if specify icon16
, icon32
in api config. this, can monkey patch pretty_print_config_to_json
method on apiconfiggenerator
class, or subclass , monkey patch class in google.appengine.ext.endpoints.api_config
module.
for example, import module , save original class before monkey patching module:
import json google.appengine.ext.endpoints import api_config originalconfiggenerator = api_config.apiconfiggenerator
then define subclass replace it:
class newconfiggenerator(originalconfiggenerator):
and override method produces api config:
def pretty_print_config_to_json(self, services, hostname=none): descriptor = super(newconfiggenerator, self).pretty_print_config_to_json( services, hostname=hostname) descriptor = json.loads(descriptor)
once have config dictionary, can add own keys , return it:
descriptor['icon16'] = 'your-16x16-icon-link' descriptor['icon32'] = 'your-32x32-icon-link' # slower overwriting __api_descriptor # due json.parse/json.loads having occur twice # hacking around private methods pain. return json.dumps(descriptor, sort_keys=true, indent=2)
and finally, sure monkey patch module before creating api:
api_config.apiconfiggenerator = newconfiggenerator
this done, example, putting monkey patch in file monkey_patch.py
, using
import monkey_patch
in file api classes defined. hope helps.
Comments
Post a Comment