Skip to content

Commit

Permalink
fix: service host and port undefined, apiEndpoint incorrect (#62)
Browse files Browse the repository at this point in the history
* expose service options

* update baseline

* fix showcase localhost

* fix failure

* update baselne

* add fields tob api

* format
  • Loading branch information
xiaozhenliu-gg5 authored Oct 19, 2019
1 parent 72bcb4c commit b172087
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,21 @@ export class {{ service.name }}Client {
* The DNS address for this API service.
*/
static get servicePath() {
return '{{ service.hostname }}';
return '{{ api.hostName }}';
}
/**
* The DNS address for this API service - same as servicePath(),
* exists for compatibility reasons.
*/
static get apiEndpoint() {
return 'localhost';
return '{{ api.hostName }}';
}

/**
* The port for this API service.
*/
static get port() {
return {{ service.port }};
return {{ api.port }};
}

/**
Expand Down
19 changes: 19 additions & 0 deletions typescript/src/schema/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as plugin from '../../../pbjs-genfiles/plugin';

import { Naming } from './naming';
import { Proto } from './proto';
import { fstat } from 'fs-extra';

export interface ProtosMap {
[filename: string]: Proto;
Expand All @@ -10,6 +11,9 @@ export interface ProtosMap {
export class API {
naming: Naming;
protos: ProtosMap;
hostName?: string;
port?: string;
// oauth_scopes: plugin.google.protobuf.IServiceOptions.prototype[".google.api.oauthScopes"];
// TODO: subpackages

constructor(
Expand All @@ -30,6 +34,21 @@ export class API {
},
{} as ProtosMap
);
fileDescriptors.forEach(fd => {
if (fd.service) {
fd.service.forEach(service => {
if (service.options) {
const serviceOption = service.options;
if (serviceOption['.google.api.defaultHost']) {
const defaultHost = serviceOption['.google.api.defaultHost'];
const arr = defaultHost.split(':');
this.hostName = arr[0] || 'localhost';
this.port = arr.length > 1 ? arr[1] : '443';
}
}
});
}
});
}

get services() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ export class KeyManagementServiceClient {
* The DNS address for this API service.
*/
static get servicePath() {
return '';
return 'cloudkms.googleapis.com';
}
/**
* The DNS address for this API service - same as servicePath(),
* exists for compatibility reasons.
*/
static get apiEndpoint() {
return 'localhost';
return 'cloudkms.googleapis.com';
}

/**
* The port for this API service.
*/
static get port() {
return 0;
return 443;
}

/**
Expand Down

0 comments on commit b172087

Please sign in to comment.