Hi, I think oapi-codegen might benefit from having a bit more modularity with generated parameters. Having separate structs for different parameter types (e.g. headers vs cookies etc) might allow more flexibility to use the type generation without requiring users to use the server code generation also. I'm personally more interested in ensuring accuracy of API docs than reducing the writing of boilerplate and prefer a greater level of control and brevity in my http handlers. So I'd like the option to take or leave certain parts of the generation functionality.
If we had separate structs for different parameter types, then I believe we could leverage json tags without the risk of accidentally overwriting attributes. For example:
func httpHeadersToOAPIHeaderParams(headers http.Header) (models.PostHeaderParams, error) {
headersMap := make(map[string]string)
for key := range headers {
if len(headers[key]) > 0 {
headersMap[key] = headers[key][0]
}
}
headersJSON, err := json.Marshal(headersMap)
if err != nil {
return models.PostHeaderParams{}, fmt.Errorf("json.Marshal headers: %w", err)
}
var params models.PostHeaderParams
err = json.Unmarshal(headersJSON, ¶ms)
if err != nil {
return models.PostHeaderParams{}, fmt.Errorf("json.Unmarshal models.PostHeaderParams: %w", err)
}
return params, nil
}
Hi, I think oapi-codegen might benefit from having a bit more modularity with generated parameters. Having separate structs for different parameter types (e.g. headers vs cookies etc) might allow more flexibility to use the type generation without requiring users to use the server code generation also. I'm personally more interested in ensuring accuracy of API docs than reducing the writing of boilerplate and prefer a greater level of control and brevity in my http handlers. So I'd like the option to take or leave certain parts of the generation functionality.
If we had separate structs for different parameter types, then I believe we could leverage json tags without the risk of accidentally overwriting attributes. For example: