mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
revert: revert auto camelCase for ts types as requires custom json marshal
This commit is contained in:
parent
2c7ea1849b
commit
053a8980f6
@ -24,6 +24,14 @@ linters-settings:
|
||||
settings:
|
||||
hugeParam:
|
||||
sizeThreshold: 512
|
||||
# https://golangci-lint.run/usage/linters/#tagliatelle
|
||||
tagliatelle:
|
||||
case:
|
||||
use-field-name: true
|
||||
rules:
|
||||
json: camel
|
||||
yaml: camel
|
||||
bson: camel
|
||||
|
||||
linters:
|
||||
enable:
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
@ -102,7 +102,7 @@ func Reply(response []interface{}, stats *CallStats, r *http.Request, w http.Res
|
||||
|
||||
if stats != nil {
|
||||
stats.ResponseSize = writer.length
|
||||
stats.Marshalling = time.Now().Sub(serializationStart)
|
||||
stats.Marshalling = time.Since(serializationStart)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,6 @@ func readServiceFile(file *ast.File, packageName string, services ServiceList) e
|
||||
if funcDecl.Recv != nil {
|
||||
trace("that is a method named", funcDecl.Name)
|
||||
if len(funcDecl.Recv.List) == 1 {
|
||||
|
||||
firstReceiverField := funcDecl.Recv.List[0]
|
||||
if "*ast.StarExpr" == reflect.ValueOf(firstReceiverField.Type).Type().String() {
|
||||
starExpr := firstReceiverField.Type.(*ast.StarExpr)
|
||||
@ -69,7 +68,6 @@ func readServiceFile(file *ast.File, packageName string, services ServiceList) e
|
||||
ident := typeSpec.Name
|
||||
trace("that is an interface named", ident.Name)
|
||||
if service, ok := findService(ident.Name); ok {
|
||||
|
||||
if iSpec, ok := typeSpec.Type.(*ast.InterfaceType); ok {
|
||||
service.IsInterface = true
|
||||
for _, fieldDecl := range iSpec.Methods.List {
|
||||
|
||||
@ -2,9 +2,7 @@ package gotsrpc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@ -13,18 +11,12 @@ import (
|
||||
"github.com/foomo/gotsrpc/v2/config"
|
||||
)
|
||||
|
||||
func (f *Field) tsName(camelCase bool) string {
|
||||
name := f.Name
|
||||
if camelCase {
|
||||
name = strcase.ToLowerCamel(name)
|
||||
}
|
||||
func (f *Field) tsName() string {
|
||||
n := f.Name
|
||||
if f.JSONInfo != nil && len(f.JSONInfo.Name) > 0 {
|
||||
if camelCase && f.JSONInfo.Name != name && strcase.ToLowerCamel(f.JSONInfo.Name) == name {
|
||||
fmt.Fprintf(os.Stderr, "WARN: json struct field annotation for `%s` does not match the camelCase pattern (expected: `%s`, got: `%s`)\n", f.Name, name, f.JSONInfo.Name)
|
||||
}
|
||||
name = f.JSONInfo.Name
|
||||
n = f.JSONInfo.Name
|
||||
}
|
||||
return name
|
||||
return n
|
||||
}
|
||||
|
||||
func (v *Value) tsType(mappings config.TypeScriptMappings, scalars map[string]*Scalar, structs map[string]*Struct, ts *code, jsonInfo *JSONInfo) {
|
||||
@ -122,7 +114,7 @@ func renderStructFields(fields []*Field, mappings config.TypeScriptMappings, sca
|
||||
} else if f.JSONInfo != nil && f.JSONInfo.Ignore {
|
||||
continue
|
||||
}
|
||||
ts.app(f.tsName(true))
|
||||
ts.app(f.tsName())
|
||||
if f.JSONInfo != nil && f.JSONInfo.OmitEmpty {
|
||||
ts.app("?")
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func renderTypescriptClient(service *Service, mappings config.TypeScriptMappings
|
||||
if index > argOffset {
|
||||
ts.app(", ")
|
||||
}
|
||||
ts.app(arg.tsName(false))
|
||||
ts.app(arg.tsName())
|
||||
ts.app(":")
|
||||
arg.Value.tsType(mappings, scalars, structs, ts, arg.JSONInfo)
|
||||
callArgs = append(callArgs, arg.Name)
|
||||
@ -67,7 +67,7 @@ func renderTypescriptClient(service *Service, mappings config.TypeScriptMappings
|
||||
|
||||
for index, retField := range method.Return {
|
||||
countInnerReturns++
|
||||
retArgName := retField.tsName(false)
|
||||
retArgName := retField.tsName()
|
||||
|
||||
if len(retArgName) == 0 {
|
||||
retArgName = "ret"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user