Skip to content

Commit

Permalink
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ type FieldType struct {
Package string `json:"package"`
IsObject bool `json:"isObject"`
JSType string `json:"jsType"`
SwiftType string `json:"swiftType"`
}

// Parser parses Oto Go definition packages.
@@ -378,20 +379,26 @@ func (p *Parser) parseFieldType(pkg *packages.Package, obj types.Object) (FieldT
ftype.TypeID = pkgPath + "." + ftype.ObjectName
if ftype.IsObject {
ftype.JSType = "object"
ftype.SwiftType = "Any"
} else {
switch ftype.TypeName {
case "interface{}":
ftype.JSType = "any"
ftype.SwiftType = "Any"
case "map[string]interface{}":
ftype.JSType = "object"
ftype.SwiftType = "Any"
case "string":
ftype.JSType = "string"
ftype.SwiftType = "String"
case "bool":
ftype.JSType = "boolean"
ftype.SwiftType = "Bool"
case "int", "int16", "int32", "int64",
"uint", "uint16", "uint32", "uint64",
"float32", "float64":
ftype.JSType = "number"
ftype.SwiftType = "Double"
}
}

@@ -407,8 +414,9 @@ func (p *Parser) addOutputFields() error {
NameLowerCamel: "error",
Comment: "Error is string explaining what went wrong. Empty if everything was fine.",
Type: FieldType{
TypeName: "string",
JSType: "string",
TypeName: "string",
JSType: "string",
SwiftType: "String",
},
Metadata: map[string]interface{}{},
Example: "something went wrong",
5 changes: 5 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
@@ -133,15 +133,18 @@ You will love it.`)
is.Equal(welcomeInputObject.Fields[1].OmitEmpty, false)
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)
is.Equal(welcomeInputObject.Fields[1].Type.Package, "")
is.Equal(welcomeInputObject.Fields[1].Example, "John Smith")

is.Equal(welcomeInputObject.Fields[2].Example, float64(3))
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")

welcomeOutputObject, err := def.Object(def.Services[1].Methods[0].OutputObject.TypeName)
is.NoErr(err)
@@ -160,6 +163,8 @@ You will love it.`)
is.Equal(welcomeOutputObject.Fields[1].Type.TypeName, "string")
is.Equal(welcomeOutputObject.Fields[1].Type.Multiple, false)
is.Equal(welcomeOutputObject.Fields[1].Type.Package, "")
is.Equal(welcomeOutputObject.Fields[1].Type.JSType, "string")
is.Equal(welcomeOutputObject.Fields[1].Type.SwiftType, "String")
is.True(welcomeOutputObject.Metadata != nil)

is.Equal(len(def.Objects), 8)

0 comments on commit 0c82632

Please sign in to comment.