interagent / schematic

A Go point of view on JSON Schema
https://godoc.org/github.com/interagent/schematic
MIT License
321 stars 33 forks source link

Check that generated code can be compiled #23

Open brandur opened 10 years ago

brandur commented 10 years ago

I've run into a few instances where Schematic will generated something like this:

// Restart formation.
func (s *Service) FormationRestart(appIdentity int, formationIdentity string) (*Formation, error) {
    var formation Formation
    return &formation, s.Post(&formation, fmt.Sprintf("/apps/%v/formations/%v/actions/restart", appIdentity, formationIdentity), o)
}

(Which is Go code that cannot compile.)

It can usually be fixed by tweaking some parameters around in a schema, but it might be cool if Schematic performed some kind of sanity check after generating code.

cyberdelia commented 10 years ago

Can you provide the compiler error too?

brandur commented 10 years ago

Oh, definitely! It'll look something like this:

kpi/kpi.go:383: undefined: o

Easiest repro is to set a link's rel attribute to anything that Schematic doesn't expect, say "restart". An o for incoming options will get added to the return line, but will not be defined in the function parameters. These non-standard rel values are a little unusual, but I don't think they're restricted in any way.