Skip to content

Commit 267a371

Browse files
committed
fixup cookie only types
1 parent 1f46128 commit 267a371

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

pkg/clientgen/testdata/tsapp/expected_shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export namespace svc {
119119
this.root = this.root.bind(this)
120120
}
121121

122-
public async cookieDummy(params: RequestType<typeof api_svc_svc_cookieDummy>): Promise<ResponseType<typeof api_svc_svc_cookieDummy>> {
122+
public async cookieDummy(params: RequestType<typeof api_svc_svc_cookieDummy>): Promise<void> {
123123
// Convert our params into the objects we need for the request
124124
const headers = makeRecord<string, string>({
125125
baz: params.headerBaz,
@@ -140,7 +140,7 @@ export namespace svc {
140140
await this.baseClient.callTypedAPI(`/cookie-dummy`, {headers, query, method: "POST", body: JSON.stringify(body)})
141141
}
142142

143-
public async cookiesOnly(params: RequestType<typeof api_svc_svc_cookiesOnly>): Promise<ResponseType<typeof api_svc_svc_cookiesOnly>> {
143+
public async cookiesOnly(): Promise<void> {
144144
await this.baseClient.callTypedAPI(`/cookies-only`, {method: "POST", body: undefined})
145145
}
146146

pkg/clientgen/testdata/tsapp/expected_typescript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export namespace svc {
177177
await this.baseClient.callTypedAPI("POST", `/cookie-dummy`, JSON.stringify(body), {headers, query})
178178
}
179179

180-
public async cookiesOnly(params: void): Promise<void> {
180+
public async cookiesOnly(): Promise<void> {
181181
await this.baseClient.callTypedAPI("POST", `/cookies-only`)
182182
}
183183

pkg/clientgen/typescript.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,8 @@ func (ts *typescript) getFields(typ *schema.Type) []*schema.Field {
149149
}
150150
}
151151

152-
func (ts *typescript) isAuthCookieOnly() bool {
153-
if ts.md.AuthHandler == nil {
154-
return false
155-
}
156-
fields := ts.getFields(ts.md.AuthHandler.Params)
152+
func (ts *typescript) isEmptyObject(typ *schema.Type) bool {
153+
fields := ts.getFields(typ)
157154
if fields == nil {
158155
return false
159156
}
@@ -165,6 +162,13 @@ func (ts *typescript) isAuthCookieOnly() bool {
165162
return true
166163
}
167164

165+
func (ts *typescript) isAuthCookieOnly() bool {
166+
if ts.md.AuthHandler == nil {
167+
return false
168+
}
169+
return ts.isEmptyObject(ts.md.AuthHandler.Params)
170+
}
171+
168172
func hasPathParams(rpc *meta.RPC) bool {
169173
return fns.Any(rpc.Path.Segments, func(s *meta.PathSegment) bool {
170174
return s.Type != meta.PathSegment_LITERAL
@@ -331,7 +335,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
331335
segmentPrefix = payloadName + "."
332336
}
333337
var isStream = rpc.StreamingRequest || rpc.StreamingResponse
334-
var hasHandshake = rpc.HandshakeSchema != nil
338+
var hasHandshake = rpc.HandshakeSchema != nil && !ts.isEmptyObject(rpc.HandshakeSchema)
335339
var inlinePathParams = (isRaw || (rpc.RequestSchema == nil && !hasHandshake)) && hasPathParams(rpc) && ts.sharedTypes
336340
if inlinePathParams {
337341
ts.WriteString(payloadName + ": { ")
@@ -376,7 +380,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
376380
ts.WriteString(" }")
377381
}
378382

379-
if (!isStream && rpc.RequestSchema != nil) || (isStream && hasHandshake) {
383+
if (!isStream && (rpc.RequestSchema != nil && !ts.isEmptyObject(rpc.RequestSchema))) || (isStream && hasHandshake) {
380384
if !ts.sharedTypes && nParams > 0 {
381385
ts.WriteString(", ")
382386
}
@@ -415,7 +419,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
415419
}
416420

417421
writeStreamRequest := func(ns string, numIndents int) {
418-
if rpc.RequestSchema == nil {
422+
if rpc.RequestSchema == nil || ts.isEmptyObject(rpc.RequestSchema) {
419423
ts.WriteString("void")
420424
} else if ts.sharedTypes {
421425
fmt.Fprintf(ts, "StreamRequest<typeof %s>", rpcImportName(rpc))
@@ -424,7 +428,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
424428
}
425429
}
426430
writeStreamResponse := func(ns string, numIndents int) {
427-
if rpc.ResponseSchema == nil {
431+
if rpc.ResponseSchema == nil || ts.isEmptyObject(rpc.ResponseSchema) {
428432
ts.WriteString("void")
429433
} else if ts.sharedTypes {
430434
ts.seenStream = true
@@ -456,7 +460,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
456460
writeStreamResponse(ns, 0)
457461
ts.WriteString(">")
458462
}
459-
} else if rpc.ResponseSchema != nil {
463+
} else if rpc.ResponseSchema != nil && !ts.isEmptyObject(rpc.ResponseSchema) {
460464
if ts.sharedTypes {
461465
fmt.Fprintf(ts, "ResponseType<typeof %s>", rpcImportName(rpc))
462466
} else {
@@ -825,6 +829,10 @@ func (ts *typescript) writeNamespace(ns string) {
825829
}
826830

827831
func (ts *typescript) writeDeclDef(ns string, decl *schema.Decl) {
832+
if ts.isEmptyObject(decl.Type) {
833+
return
834+
}
835+
828836
if decl.Doc != "" {
829837
scanner := bufio.NewScanner(strings.NewReader(decl.Doc))
830838
ts.WriteString(" /**\n")

0 commit comments

Comments
 (0)