在云端点从v1迁移到V2的过程中,我们注意到在客户端生成的服务定义类的名称没有使用@Api注释定义中定义的canonicalName
例如
@Api(name = "customer",
canonicalName = "CustomerAPI",
version = "v1",
...
public class CustomerEndpoint {
...生成customer-v1-java.zip,并使用名称Customer而不是CustomerAPI生成服务定义类。
我们应用程序的build.gradle如下所示
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'
apply plugin: 'io.fabric'
...
dependencies {
...
endpointsServer project(path: ':servers:api', configuration: 'endpoints')
}而servers/api中的build.gradle如下
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
// App Engine Gradle plugin
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
// Endpoints Frameworks Gradle plugin
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
}
}
...
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
...
dependencies {
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
compile 'jstl:jstl:1.2'
compile group: 'javax.inject', name: 'javax.inject', version: '1'
compile group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '1.9.49'
compile group: 'com.google.endpoints', name: 'endpoints-framework', version: '2.0.8'
...
}
appengine {
deploy { // deploy configuration
version = findProperty("appengine.deploy.version")
def promoteProp = findProperty("appengine.deploy.promote")
if (promoteProp != null) {
promote = new Boolean(promoteProp)
}
}
run {
host = "0.0.0.0"
port = 8080
jvmFlags = ['-Ddatastore.backing_store=../../../local_db.bin']
}
}
def projectId = 'some-api-project'
endpointsServer {
hostname = "${projectId}.appspot.com"
}
endpointsClientLibs {
hostname = "${projectId}.appspot.com"
}你知道为什么canonicalName不被尊重吗?
发布于 2018-02-27 08:42:30
简单地说,这是一个bug/意外遗漏。我会在下一个版本中修复它。
发布于 2018-02-28 10:30:28
解决方法
正如saiyr所指出的,这是一个将在下一个版本中修复的bug。
对于任何正在寻找解决办法的人来说,这就是我在此期间所做的绕过这个问题的方法。原来问题出在发现文档的生成上。如果您有正确的discovery文档,其他一切都可以正常工作。
在应用程序的build.gradle中使用标准gradle依赖项生成客户端库
endpointsServer project(path: ':servers:api', configuration: 'endpoints')这将在该文件夹下生成发现文档
app/build/endpointsDiscoveryDocsFromDependencies将此文件夹中的发现文档复制到新文件夹中
app/docs/api/discovery现在编辑应用程序的build.gradle,注释掉端点依赖项,并添加一个目标,以便从给定的一组发现文档生成客户端库
dependencies {
...
// Commented out to suppress generation of client library
// endpointsServer project(path: ':servers:api', configuration: 'endpoints')
}
// Use this target to generate client library instead
endpointsClient {
discoveryDocs = [
'docs/api/discovery/customer-v1-rest.discovery',
]
}希望这能有所帮助。
https://stackoverflow.com/questions/48948719
复制相似问题