Open zacharyburkett opened 2 years ago
Closed by #47 ?
Not exactly,
This issue is about generating go-chi/render's functions directly alongside the generated code, avoiding the dependency.
Since we already generate the implementation of interfaces, we just need the actual render implementation, which is quite small
Correct, the goal of this issue is to simplify our dependencies.
As a sidenote, I think we're better off changing the generated method signatures to return a *Response
or (*Response, error)
pair directly instead of having the user call the Render
function, since we're already breaking the http.Handler
signature. For example,
func (h handler) Login(w http.ResponseWriter, r *http.Request, params openapi.LoginParams) *openapi.Response {
s, err := h.server.LoginServer().Login(
r.Context(),
params.Username, params.Password,
foodtinder.LoginMetadata{
UserAgent: r.Header.Get("User-Agent"),
},
)
if err != nil {
return openapi.LoginJSON400Response(openapi.Error{Error: err})
}
return openapi.LoginJSON200Response(openapi.Session{
UserID: openapi.ID(s.UserID),
Token: s.Token,
Expiry: s.Expiry,
Metadata: openapi.LoginMetadata{
UserAgent: optstr(s.Metadata.UserAgent),
},
})
}
(package openapi
is autogenerated.)
Created PR #80 to implement this.
Currently we use https://github.com/go-chi/render interfaces for our generated types, simplifying request/response management.
I propose we implement our own alternative that is generated alongside server/type code.
A generated implementation removes the need for a dependency and allows us to easily modify it to suit any future needs (ie more content types).