@@ -149,11 +149,8 @@ func (ts *typescript) getFields(typ *schema.Type) []*schema.Field {
149
149
}
150
150
}
151
151
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 )
157
154
if fields == nil {
158
155
return false
159
156
}
@@ -165,6 +162,13 @@ func (ts *typescript) isAuthCookieOnly() bool {
165
162
return true
166
163
}
167
164
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
+
168
172
func hasPathParams (rpc * meta.RPC ) bool {
169
173
return fns .Any (rpc .Path .Segments , func (s * meta.PathSegment ) bool {
170
174
return s .Type != meta .PathSegment_LITERAL
@@ -331,7 +335,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
331
335
segmentPrefix = payloadName + "."
332
336
}
333
337
var isStream = rpc .StreamingRequest || rpc .StreamingResponse
334
- var hasHandshake = rpc .HandshakeSchema != nil
338
+ var hasHandshake = rpc .HandshakeSchema != nil && ! ts . isEmptyObject ( rpc . HandshakeSchema )
335
339
var inlinePathParams = (isRaw || (rpc .RequestSchema == nil && ! hasHandshake )) && hasPathParams (rpc ) && ts .sharedTypes
336
340
if inlinePathParams {
337
341
ts .WriteString (payloadName + ": { " )
@@ -376,7 +380,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
376
380
ts .WriteString (" }" )
377
381
}
378
382
379
- if (! isStream && rpc .RequestSchema != nil ) || (isStream && hasHandshake ) {
383
+ if (! isStream && ( rpc .RequestSchema != nil && ! ts . isEmptyObject ( rpc . RequestSchema )) ) || (isStream && hasHandshake ) {
380
384
if ! ts .sharedTypes && nParams > 0 {
381
385
ts .WriteString (", " )
382
386
}
@@ -415,7 +419,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
415
419
}
416
420
417
421
writeStreamRequest := func (ns string , numIndents int ) {
418
- if rpc .RequestSchema == nil {
422
+ if rpc .RequestSchema == nil || ts . isEmptyObject ( rpc . RequestSchema ) {
419
423
ts .WriteString ("void" )
420
424
} else if ts .sharedTypes {
421
425
fmt .Fprintf (ts , "StreamRequest<typeof %s>" , rpcImportName (rpc ))
@@ -424,7 +428,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
424
428
}
425
429
}
426
430
writeStreamResponse := func (ns string , numIndents int ) {
427
- if rpc .ResponseSchema == nil {
431
+ if rpc .ResponseSchema == nil || ts . isEmptyObject ( rpc . ResponseSchema ) {
428
432
ts .WriteString ("void" )
429
433
} else if ts .sharedTypes {
430
434
ts .seenStream = true
@@ -456,7 +460,7 @@ func (ts *typescript) writeService(svc *meta.Service, p clientgentypes.ServiceSe
456
460
writeStreamResponse (ns , 0 )
457
461
ts .WriteString (">" )
458
462
}
459
- } else if rpc .ResponseSchema != nil {
463
+ } else if rpc .ResponseSchema != nil && ! ts . isEmptyObject ( rpc . ResponseSchema ) {
460
464
if ts .sharedTypes {
461
465
fmt .Fprintf (ts , "ResponseType<typeof %s>" , rpcImportName (rpc ))
462
466
} else {
@@ -825,6 +829,10 @@ func (ts *typescript) writeNamespace(ns string) {
825
829
}
826
830
827
831
func (ts * typescript ) writeDeclDef (ns string , decl * schema.Decl ) {
832
+ if ts .isEmptyObject (decl .Type ) {
833
+ return
834
+ }
835
+
828
836
if decl .Doc != "" {
829
837
scanner := bufio .NewScanner (strings .NewReader (decl .Doc ))
830
838
ts .WriteString (" /**\n " )
0 commit comments