Skip to content

Commit

Permalink
fixed bug in pointers to objects as field types
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Mar 28, 2021
1 parent ac0caf1 commit 4ff0094
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,14 @@ func (p *Parser) parseFieldType(pkg *packages.Package, obj types.Object) (FieldT
ftype.ObjectName = types.TypeString(typ, func(other *types.Package) string { return "" })
ftype.ObjectNameLowerCamel = camelizeDown(ftype.ObjectName)
ftype.TypeID = pkgPath + "." + ftype.ObjectName
typeWithoutPointer := strings.TrimPrefix(ftype.TypeName, "*")
ftype.JSType = typeWithoutPointer
ftype.SwiftType = typeWithoutPointer
if ftype.IsObject {
ftype.JSType = "object"
ftype.SwiftType = "Any"
} else {
switch ftype.TypeName {
switch typeWithoutPointer {
case "interface{}":
ftype.JSType = "any"
ftype.SwiftType = "Any"
Expand Down
11 changes: 6 additions & 5 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ You will love it.`)
is.True(welcomeInputObject.Fields[0].Metadata != nil) // no metadata shouldn't be nil
is.Equal(welcomeInputObject.Fields[1].NameLowerCamel, "name")
is.Equal(welcomeInputObject.Fields[1].OmitEmpty, false)
is.Equal(welcomeInputObject.Fields[1].Type.TypeName, "string")
is.Equal(welcomeInputObject.Fields[1].Type.TypeName, "*string")
is.Equal(welcomeInputObject.Fields[1].Type.JSType, "string")
is.Equal(welcomeInputObject.Fields[1].Type.SwiftType, "String")
is.Equal(welcomeInputObject.Fields[1].Type.Multiple, false)
Expand All @@ -147,9 +147,10 @@ You will love it.`)
is.Equal(welcomeInputObject.Fields[2].Type.JSType, "number")
is.Equal(welcomeInputObject.Fields[2].Type.SwiftType, "Double")

is.Equal(welcomeInputObject.Fields[3].Example, true)
is.Equal(welcomeInputObject.Fields[3].Type.JSType, "boolean")
is.Equal(welcomeInputObject.Fields[3].Type.SwiftType, "Bool")
is.Equal(welcomeInputObject.Fields[3].Type.TypeName, "*CustomerDetails")
is.Equal(welcomeInputObject.Fields[3].Type.JSType, "CustomerDetails")
is.Equal(welcomeInputObject.Fields[3].Example, nil)
is.Equal(welcomeInputObject.Fields[3].Type.SwiftType, "CustomerDetails")

welcomeOutputObject, err := def.Object(def.Services[2].Methods[0].OutputObject.TypeName)
is.NoErr(err)
Expand All @@ -172,7 +173,7 @@ You will love it.`)
is.Equal(welcomeOutputObject.Fields[1].Type.SwiftType, "String")
is.True(welcomeOutputObject.Metadata != nil)

is.Equal(len(def.Objects), 10)
is.Equal(len(def.Objects), 11)
for i := range def.Objects {
switch def.Objects[i].Name {
case "Greeting":
Expand Down
15 changes: 10 additions & 5 deletions parser/testdata/services/pleasantries/welcomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ type WelcomeRequest struct {
To string
// Name is the name of the person to welcome.
// example: "John Smith"
Name string
Name *string
// The number of times to send the message.
// example: 3
Times int
// NewCustomer indicates whether this is a new customer
// or not.
// example: true
NewCustomer bool
// CustomerDetails are the details about the customer.
CustomerDetails *CustomerDetails
}

// WelcomeResponse is the response object for Welcomer.Welcome.
Expand All @@ -30,3 +28,10 @@ type WelcomeResponse struct {
// example: "Welcome John Smith."
Message string
}

type CustomerDetails struct {
// NewCustomer indicates whether this is a new customer
// or not.
// example: true
NewCustomer bool
}

0 comments on commit 4ff0094

Please sign in to comment.