Skip to content

Commit

Permalink
feat: auto use camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Feb 17, 2022
1 parent 7a72317 commit 094ce27
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
38 changes: 19 additions & 19 deletions example/basic/client/src/service-vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@ export enum StringTypeMapValue {
}
// github.com/foomo/gotsrpc/v2/example/basic/service.Struct
export interface Struct {
Int:number;
Int32:number;
Int64:number;
UInt:number;
UInt32:number;
UInt64:number;
Float32:number;
Float64:number;
String:string;
Interface:any;
IntTypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.IntTypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.IntTypeMapValue>|null;
Int32TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Int32TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Int32TypeMapValue>|null;
Int64TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Int64TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Int64TypeMapValue>|null;
UIntTypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.UIntTypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.UIntTypeMapValue>|null;
UInt32TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.UInt32TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.UInt32TypeMapValue>|null;
UInt64TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.UInt64TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.UInt64TypeMapValue>|null;
Float32TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Float32TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Float32TypeMapValue>|null;
Float64TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Float64TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Float64TypeMapValue>|null;
StringTypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.StringTypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.StringTypeMapValue>|null;
int:number;
int32:number;
int64:number;
uInt:number;
uInt32:number;
uInt64:number;
float32:number;
float64:number;
string:string;
interface:any;
intTypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.IntTypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.IntTypeMapValue>|null;
int32TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Int32TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Int32TypeMapValue>|null;
int64TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Int64TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Int64TypeMapValue>|null;
uIntTypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.UIntTypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.UIntTypeMapValue>|null;
uInt32TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.UInt32TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.UInt32TypeMapValue>|null;
uInt64TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.UInt64TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.UInt64TypeMapValue>|null;
float32TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Float32TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Float32TypeMapValue>|null;
float64TypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.Float64TypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.Float64TypeMapValue>|null;
stringTypeMapTyped:Record<github_com_foomo_gotsrpc_v2_example_basic_service.StringTypeMapKey,github_com_foomo_gotsrpc_v2_example_basic_service.StringTypeMapValue>|null;
}
// github.com/foomo/gotsrpc/v2/example/basic/service.UInt32Type
export enum UInt32Type {
Expand Down
20 changes: 10 additions & 10 deletions example/nullable/client/src/service-vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ export interface Base {
f1:github_com_foomo_gotsrpc_v2_example_nullable_service.ACustomTypesMap|null;
f2?:github_com_foomo_gotsrpc_v2_example_nullable_service.ACustomTypesMap;
f3:github_com_foomo_gotsrpc_v2_example_nullable_service.ACustomTypesMap|null;
Two:Array<github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null;
Two1:Array<Array<github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null>|null;
Two2:Array<Record<string,github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null>|null;
Three:Array<github_com_foomo_gotsrpc_v2_example_nullable_service.Nested|null>|null;
Three1:Array<string|null>|null;
Four:Record<string,github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null;
Five:Record<string,github_com_foomo_gotsrpc_v2_example_nullable_service.Nested|null>|null;
Six:{
Foo:string;
two:Array<github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null;
two1:Array<Array<github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null>|null;
two2:Array<Record<string,github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null>|null;
three:Array<github_com_foomo_gotsrpc_v2_example_nullable_service.Nested|null>|null;
three1:Array<string|null>|null;
four:Record<string,github_com_foomo_gotsrpc_v2_example_nullable_service.Nested>|null;
five:Record<string,github_com_foomo_gotsrpc_v2_example_nullable_service.Nested|null>|null;
six:{
foo:string;
}|null;
}
// github.com/foomo/gotsrpc/v2/example/nullable/service.Nested
export interface Nested {
Foo:string;
foo:string;
}
// end of common js
9 changes: 6 additions & 3 deletions typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
"github.com/foomo/gotsrpc/v2/config"
)

func (f *Field) tsName() string {
func (f *Field) tsName(camelCase bool) string {
n := f.Name
if camelCase {
n = strcase.ToLowerCamel(n)
}
if f.JSONInfo != nil && len(f.JSONInfo.Name) > 0 {
n = f.JSONInfo.Name
}
Expand Down Expand Up @@ -106,7 +109,7 @@ func renderStructFields(fields []*Field, mappings config.TypeScriptMappings, sca
if f.JSONInfo != nil && f.JSONInfo.Ignore {
continue
}
ts.app(f.tsName())
ts.app(f.tsName(true))
if f.JSONInfo != nil && f.JSONInfo.OmitEmpty {
ts.app("?")
}
Expand Down Expand Up @@ -260,7 +263,7 @@ func RenderTypeScriptServices(services ServiceList, mappings config.TypeScriptMa
if !target.IsTSRPC(service.Name) {
continue
}
err = renderTypescriptClientAsync(service, mappings, scalars, structs, ts)
err = renderTypescriptClient(service, mappings, scalars, structs, ts)
if err != nil {
return
}
Expand Down
7 changes: 3 additions & 4 deletions typscriptclientasync.go → typscriptclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/foomo/gotsrpc/v2/config"
)

func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMappings, scalars map[string]*Scalar, structs map[string]*Struct, ts *code) error {
func renderTypescriptClient(service *Service, mappings config.TypeScriptMappings, scalars map[string]*Scalar, structs map[string]*Struct, ts *code) error {
clientName := service.Name + "Client"

ts.l("export class " + clientName + " {")
Expand Down Expand Up @@ -47,7 +47,7 @@ func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMap
if index > argOffset {
ts.app(", ")
}
ts.app(arg.tsName())
ts.app(arg.tsName(false))
ts.app(":")
arg.Value.tsType(mappings, scalars, structs, ts, arg.JSONInfo)
callArgs = append(callArgs, arg.Name)
Expand All @@ -63,7 +63,6 @@ func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMap
innerReturnTypeTS := newCode(" ")
innerReturnTypeTS.app("{")
firstReturnType := ""
//firstReturnFieldName := ""
countReturns := 0
countInnerReturns := 0
errIndex := 0
Expand All @@ -72,7 +71,7 @@ func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMap

for index, retField := range method.Return {
countInnerReturns++
retArgName := retField.tsName()
retArgName := retField.tsName(false)

if len(retArgName) == 0 {
retArgName = "ret"
Expand Down

0 comments on commit 094ce27

Please sign in to comment.