cloudendpoints / endpoints-python

A Python framework for building RESTful APIs on Google App Engine
Apache License 2.0
51 stars 17 forks source link

After upgrading to 4.6.1, Generated client library for java is using "none" instead of "com". #172

Closed zonito closed 5 years ago

zonito commented 6 years ago
╰─$ sh generate_api.sh 
INFO:endpoints:Initializing Endpoints Framework version 4.6.1
API client library written to ../PGAPIs/PGAndAPI/fan-v1.zip
INFO:endpoints:Initializing Endpoints Framework version 4.6.1
OpenAPI spec written to ./fanv1openapi.json
Archive:  fan-v1.zip
   creating: fan/
   creating: fan/src/
   creating: fan/src/main/
   creating: fan/src/main/java/
   creating: fan/src/main/java/none/
   creating: fan/src/main/java/none/fan/
 extracting: fan/src/main/java/none/fan/FanScopes.java  
 extracting: fan/src/main/java/none/fan/FanRequest.java  
 extracting: fan/src/main/java/none/fan/Fan.java  
   creating: fan/src/main/java/none/fan/model/
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/model/somefile.java  
 extracting: fan/src/main/java/none/fan/FanRequestInitializer.java  
 extracting: fan/readme.html     
 extracting: fan/build.gradle    
 extracting: fan/LICENSE.txt     
 extracting: fan/proguard-google-api-client.txt 
@endpoints.api(name='fan', version='v1',
               description='API',
               title='Fan API',
               auth=_AUTH_CONFIG,
               owner_domain='fan.com')
class AuthApi(remote.Service):
inklesspen commented 6 years ago

What version are you upgrading from, please?

inklesspen commented 6 years ago

Also, if possible, please share the discovery doc generated with endpointscfg.py gen_discovery_doc. (This discovery doc is what's used to generate the Java client; inspecting it may help me find where the problem lies.)

zonito commented 6 years ago

I have upgraded to 4.6.1

zonito commented 6 years ago

Discovery content

"auth": {
    "oauth2": {
      "scopes": {
        "https://www.googleapis.com/auth/userinfo.email": {
          "description": "View your email address"
        }
      }
    }
  },
  "basePath": "/_ah/api/fan/v1/",
  "baseUrl": "https://None/_ah/api/fan/v1/",
  "batchPath": "batch",
  "description": "API",
  "discoveryVersion": "v1",

Baseurl is also showing None.

I am using gcloud to deploy application so in my app.yaml the "application" and "version" is commented.

Earlier, it was using owner_domain to create package.

zonito commented 6 years ago

With application and version, here is the list of files generated which is different from old versions (it was using owner_domain):

╰─$ sh generate_api.sh 
INFO:endpoints:Initializing Endpoints Framework version 4.6.1
API client library written to ../PGAPIs/PGAndAPI/fan-v1.zip
INFO:endpoints:Initializing Endpoints Framework version 4.6.1
API discovery document written to ./fan-v1.discovery
Archive:  fan-v1.zip
   creating: fan/
   creating: fan/src/
   creating: fan/src/main/
   creating: fan/src/main/java/
   creating: fan/src/main/java/com/
   creating: fan/src/main/java/com/appspot/
   creating: fan/src/main/java/com/appspot/fan_api_pg/
   creating: fan/src/main/java/com/appspot/fan_api_pg/fan/
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/fanScopes.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/fanRequest.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/fan.java  
   creating: fan/src/main/java/com/appspot/fan_api_pg/fan/model/
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsBlockInfoResponse.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsBlockListResponse.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsBlockModel.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsCreateTeamRequest.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsCreateTeamResponse.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsLeaderboardTeams.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsPlayerModel.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsStatusResponse.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsTeamModel.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/model/ApiStructsApiModelsWinnerFormatModel.java  
 extracting: fan/src/main/java/com/appspot/fan_api_pg/fan/fanRequestInitializer.java  
 extracting: fan/readme.html     
 extracting: fan/build.gradle    
 extracting: fan/LICENSE.txt     
 extracting: fan/proguard-google-api-client.txt  
total 4400
inklesspen commented 6 years ago

Yes, but what version did you upgrade from? What's the last version at which it works?

Note that generating discovery docs and clients also requires specifying the hostname, either in the api decorator or on the command line, or in the app.yaml (in that case by using the application specified in the app.yaml). In your second example, it is generating a hostname based on the app.yaml file.

Please make sure that your generate_api.sh script is properly setting a hostname when calling these commands.

zonito commented 6 years ago

Came from 2.5.0 to 4.6.1

--hostname=com.fan will do?

inklesspen commented 6 years ago

That's quite a version jump... But I'll look into it.

And no, when you specify the hostname, you must specify the actual domain name at which your api will be served. If you're using a custom domain, that could be fan.com, but it can't be com.fan.

zonito commented 6 years ago

--hostname works! 👍

zonito commented 6 years ago

Yes, that's the issue. It creates the package with it and the endpoint as well. For now, I can the domain manually inside the Fan.Java, is there any automated way to update both?

inklesspen commented 6 years ago

Nothing changed regarding the handling of owner_domain between 2.5.0 and 4.6.1. However, what did change was that the framework no longer calls an external service to generate discovery docs. (It does still call an external service to generate the Java client files.)

I will investigate whether the external service treated owner_domain differently.

zonito commented 6 years ago

Thanks

inklesspen commented 5 years ago

4.6.1 generates discovery docs that are missing the 'etag' and 'ownerDomain' keys. Neither of those keys is documented at https://developers.google.com/discovery/v1/reference/apis but at least the 'ownerDomain' key seems to be important.

inklesspen commented 5 years ago

Turns out there's actually two ways to specify the owner domain. One way is with owner_domain='example.com'; the other is with namespace=endpoints.Namespace(owner_domain='example.com', owner_name='Example').

The discovery document generation which fed into the Java client generation used to use the first value; now it uses the second value. The problem is this second value is nowhere documented.

https://github.com/cloudendpoints/endpoints-python/blob/efd350c07e742ed34c98c9edb3b35f113d6f7e92/endpoints/discovery_generator.py#L880-L883 should be extended to use the non-namespace values.

inklesspen commented 5 years ago

A new version with this fix will be released after the Thanksgiving holiday.

inklesspen commented 5 years ago

Frameworks version 4.8.0 has been released, which includes a fix for this issue.

zonito commented 5 years ago

Thanks