oapi-codegen / oapi-codegen

Generate Go client and server boilerplate from OpenAPI 3 specifications
Apache License 2.0
6.3k stars 865 forks source link

Consider adding a mode where the generated code is dependency-free #303

Open eliben opened 3 years ago

eliben commented 3 years ago

Currently the generated code has a dependency on pkg/runtime in this module, mostly to support Bind* functions.

While generated methods of the wrapper know exactly which types are needed in Go for the params, they call fairly generic Bind* functions that take these params via interface{}. This seems a bit backward - if we already have a concrete type, why bind it through a generic function that uses runtime dispatch?

It should be possible for the generated code to directly bind parameters - given a known concrete type it should be only a few lines of code per parameter. This would be faster, but more importantly dependency-free - the generated code would only be dependent on Echo (or other framework used).

deepmap-marcinr commented 3 years ago

Yes, I've been meaning to do that, but it's really tricky. I've got a branch where it kinda works, but I have to break out all the special cases we have into their own functions and insert those into the spec. We'd also need to inline a whole lot of string manipulation functions. One day :)