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?
[0] https://golang.org/pkg/go/ast/#Object [1] type Object struct { Name string <https://golang.org/pkg/builtin/#string> // declared name Decl interface{} `interface:"Field,FuncDecl,LabeledStmt,external.Scope" // } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.