private/apigen: fix URL construction in generated TypeScript code

This change fixes an incorrect invocation of the URL object constructor
in generated TypeScript HTTP clients.

Change-Id: I9011bc535f2096374d20b74b401d4cc38a0451fb
This commit is contained in:
Jeremy Wharton 2023-11-15 01:06:11 -06:00 committed by Jeremy Wharton
parent cfb7f55220
commit 032faefa4b
3 changed files with 5 additions and 5 deletions

View File

@ -114,7 +114,7 @@ export class DocumentsHttpApiV0 {
}
public async updateContent(request: DocsUpdateContentRequest, path: string, id: UUID, date: Time): Promise<DocsUpdateContentResponse> {
const u = new URL(`${this.ROOT_PATH}/${path}`);
const u = new URL(`${this.ROOT_PATH}/${path}`, window.location.href);
u.searchParams.set('id', id);
u.searchParams.set('date', date);
const fullPath = u.toString();

View File

@ -114,7 +114,7 @@ func (f *tsGenFile) createAPIClient(group *EndpointGroup) {
f.pf("\tpublic async %s(%s): Promise<%s> {", method.TypeScriptName, funcArgs, returnType)
if len(method.QueryParams) > 0 {
f.pf("\t\tconst u = new URL(`%s`);", path)
f.pf("\t\tconst u = new URL(`%s`, window.location.href);", path)
for _, p := range method.QueryParams {
f.pf("\t\tu.searchParams.set('%s', %s);", p.Name, p.Name)
}

View File

@ -148,7 +148,7 @@ export class ProjectManagementHttpApiV0 {
}
public async getBucketRollup(projectID: UUID, bucket: string, since: Time, before: Time): Promise<BucketUsageRollup> {
const u = new URL(`${this.ROOT_PATH}/bucket-rollup`);
const u = new URL(`${this.ROOT_PATH}/bucket-rollup`, window.location.href);
u.searchParams.set('projectID', projectID);
u.searchParams.set('bucket', bucket);
u.searchParams.set('since', since);
@ -163,7 +163,7 @@ export class ProjectManagementHttpApiV0 {
}
public async getBucketRollups(projectID: UUID, since: Time, before: Time): Promise<BucketUsageRollup[]> {
const u = new URL(`${this.ROOT_PATH}/bucket-rollups`);
const u = new URL(`${this.ROOT_PATH}/bucket-rollups`, window.location.href);
u.searchParams.set('projectID', projectID);
u.searchParams.set('since', since);
u.searchParams.set('before', before);
@ -177,7 +177,7 @@ export class ProjectManagementHttpApiV0 {
}
public async getAPIKeys(projectID: UUID, search: string, limit: number, page: number, order: number, orderDirection: number): Promise<APIKeyPage> {
const u = new URL(`${this.ROOT_PATH}/apikeys/${projectID}`);
const u = new URL(`${this.ROOT_PATH}/apikeys/${projectID}`, window.location.href);
u.searchParams.set('search', search);
u.searchParams.set('limit', limit);
u.searchParams.set('page', page);