Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type aliases, refactor go schema parsing #1493

Merged
merged 13 commits into from
May 16, 2024
2 changes: 1 addition & 1 deletion backend/controller/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pb
Config: c,
})

case *schema.Database, *schema.Enum, *schema.FSM:
case *schema.Database, *schema.Enum, *schema.TypeAlias, *schema.FSM:
}
}

Expand Down
2 changes: 2 additions & 0 deletions backend/controller/ingress/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func transformAliasedFields(sch *schema.Schema, t schema.Type, obj any, aliaser
}
}
}
case *schema.TypeAlias:
return transformAliasedFields(sch, decl.Type, obj, aliaser)
case *schema.Config, *schema.Database, *schema.FSM, *schema.Secret, *schema.Verb:
return fmt.Errorf("%s: unsupported ref type %T", t.Pos, decl)
}
Expand Down
2 changes: 2 additions & 0 deletions backend/controller/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func validateValue(fieldType schema.Type, path path, value any, sch *schema.Sche
}
typeMatches = true
}
case *schema.TypeAlias:
return validateValue(d.Type, path, value, sch)
case *schema.Enum:
var inputName any
inputName = value
Expand Down
25 changes: 24 additions & 1 deletion backend/controller/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,30 @@ func TestValidation(t *testing.T) {
unit Unit
}
}`,
request: obj{}},
request: obj{},
},
{name: "StringAlias",
schema: `module test {
typealias StringAlias String
data Test { stringValue test.StringAlias }
}`,
request: obj{"stringValue": "test"},
},
{name: "IntAlias",
schema: `module test {
typealias IntAlias Int
data Test { intValue test.IntAlias }
}`,
request: obj{"intValue": 10.0},
},
{name: "DataAlias",
schema: `module test {
typealias IntAlias test.Inner
data Inner { string String }
data Test { obj test.IntAlias }
}`,
request: obj{"obj": obj{"string": "test"}},
},
{name: "RequiredFields",
schema: `module test { data Test { int Int } }`,
request: obj{},
Expand Down
Loading
Loading