I'm developing a json schema generator (json schema from Go ast and the other way around). There is a keyword "oneOf" which requires exactly one schema to be valid in this keyword's value. In Go I translate it by using an empty interface{}. The issue is that when I convert the interface{} to json schema I can only say that the object can be of any type even if I know that it can hold only a small subset.
Therefore I'm wondering if placing some constrains on the types that could be implemented by the interface would be a good idea. For example instead of `type interface{}` which implements any type we could define the types it can implement (e.g. type X interface{T1, T2, T3} ). This way we don't have a totally black box so it improves the documentation/semantics and we avoid specific bugs using static analysis. Currently the practice seems to be documenting the types in pure comments[0] which cannot be analysed statically. Another option that I'm considering now is to use the empty interface but with specific tags [1] and use an external tool. This might have been proposed before but I can't find it on the mailing list. What do you think?
[1]
type Object struct {
Name string // declared name
Decl interface{} `interface:"Field,FuncDecl,LabeledStmt,external.Scope" //
}