示例#1
0
    def get(self, name, version):
      host = self.request.headers['Host']
      services = service_map.get((name, version))
      if not services:
        self.abort(404, 'Not Found')

      self.response.headers['Content-Type'] = 'application/json'
      json.dump(
          discovery.generate(services, host, base_path),
          self.response, indent=2, sort_keys=True, separators=(',', ':'))
示例#2
0
 def test_generate(self):
     """Tests for discovery.generate."""
     expected = {
         'auth': {
             'oauth2': {
                 'scopes': {
                     'https://www.googleapis.com/auth/userinfo.email': {
                         'description':
                         'https://www.googleapis.com/auth/userinfo.email',
                     },
                 },
             },
         },
         'basePath': '/api/service/v1',
         'baseUrl': 'https://None/api/service/v1',
         'batchPath': 'batch',
         'description': 'A service to test with.',
         'discoveryVersion': 'v1',
         'icons': {
             'x16':
             'https://www.google.com/images/icons/product/search-16.gif',
             'x32':
             'https://www.google.com/images/icons/product/search-32.gif',
         },
         'id': 'service:v1',
         'kind': 'discovery#restDescription',
         'methods': {
             'get_method': {
                 'description': 'An HTTP GET method.',
                 'httpMethod': 'GET',
                 'id': 'service.get_method',
                 'path': 'get_method',
                 'response': {
                     '$ref': 'discovery_test.Message',
                 },
                 'scopes': [
                     'https://www.googleapis.com/auth/userinfo.email',
                 ],
             },
             'path_parameter_method': {
                 'description': 'A method supporting path parameters.',
                 'httpMethod': 'POST',
                 'id': 'service.path_parameter_method',
                 'parameterOrder': [
                     'path',
                 ],
                 'parameters': {
                     'path': {
                         'location': 'path',
                         'type': 'string',
                     },
                 },
                 'path': '{path}/method',
                 'request': {
                     '$ref': 'discovery_test.Message',
                     'parameterName': 'resource',
                 },
                 'response': {
                     '$ref': 'discovery_test.Message',
                 },
                 'scopes': [
                     'https://www.googleapis.com/auth/userinfo.email',
                 ],
             },
             'post_method': {
                 'description':
                 'An HTTP POST method. Has a multi-line description.',
                 'httpMethod': 'POST',
                 'id': 'service.post_method',
                 'path': 'post_method',
                 'request': {
                     '$ref': 'discovery_test.Message',
                     'parameterName': 'resource',
                 },
                 'response': {
                     '$ref': 'discovery_test.Message',
                 },
                 'scopes': [
                     'https://www.googleapis.com/auth/userinfo.email',
                 ],
             },
             'query_string_method': {
                 'description': 'A method supporting query strings.',
                 'httpMethod': 'POST',
                 'id': 'service.query_string_method',
                 'parameters': {
                     'string': {
                         'location': 'query',
                         'type': 'string',
                     },
                 },
                 'path': 'query_string_method',
                 'request': {
                     '$ref': 'discovery_test.Message',
                     'parameterName': 'resource',
                 },
                 'response': {
                     '$ref': 'discovery_test.Message',
                 },
                 'scopes': [
                     'https://www.googleapis.com/auth/userinfo.email',
                 ],
             },
         },
         'name': 'service',
         'parameters': {
             'alt': {
                 'default':
                 'json',
                 'description':
                 'Data format for the response.',
                 'enum': ['json'],
                 'enumDescriptions': [
                     'Responses with Content-Type of application/json',
                 ],
                 'location':
                 'query',
                 'type':
                 'string',
             },
             'fields': {
                 'description':
                 ('Selector specifying which fields to include in a partial'
                  ' response.'),
                 'location':
                 'query',
                 'type':
                 'string',
             },
             'key': {
                 'description':
                 ('API key. Your API key identifies your project and provides you'
                  ' with API access, quota, and reports. Required unless you'
                  ' provide an OAuth 2.0 token.'),
                 'location':
                 'query',
                 'type':
                 'string',
             },
             'oauth_token': {
                 'description': 'OAuth 2.0 token for the current user.',
                 'location': 'query',
                 'type': 'string',
             },
             'prettyPrint': {
                 'default': 'true',
                 'description':
                 'Returns response with indentations and line breaks.',
                 'location': 'query',
                 'type': 'boolean',
             },
             'quotaUser': {
                 'description':
                 ('Available to use for quota purposes for server-side'
                  ' applications. Can be any arbitrary string assigned to a user,'
                  ' but should not exceed 40 characters. Overrides userIp if both'
                  ' are provided.'),
                 'location':
                 'query',
                 'type':
                 'string',
             },
             'userIp': {
                 'description':
                 ('IP address of the site where the request originates. Use this if'
                  ' you want to enforce per-user limits.'),
                 'location':
                 'query',
                 'type':
                 'string',
             },
         },
         'protocol': 'rest',
         'rootUrl': 'https://None/api/',
         'servicePath': 'service/v1/',
         'schemas': {
             'discovery_test.Message': {
                 'description': 'A message to test with.',
                 'id': 'discovery_test.Message',
                 'properties': {
                     'boolean': {
                         'type': 'boolean',
                     },
                     'integer': {
                         'format': 'int64',
                         'type': 'string',
                     },
                     'required': {
                         'required': True,
                         'type': 'boolean',
                     },
                     'string': {
                         'type': 'string',
                     },
                 },
                 'type': 'object',
             },
         },
         'version': 'v1',
     }
     self.assertEqual(discovery.generate(Service, '/api'), expected)