Skip to content

Commit bba4b7e

Browse files
refactor: replace per-style param functions with monolithic dispatchers
Replace 14 per-style bind/style files with 2 monolithic dispatchers (BindParameter, BindQueryParameter, BindRawQueryParameter, StyleParameter) that take the style as a field in ParameterOptions and dispatch internally. Add Style and AllowReserved fields to ParameterOptions. Add MissingRequiredParameterError typed error for required param detection. Delete ComputeStyleFunc/ComputeBindFunc — templates hardcode function names. Fix Fiber receiver template to use url.ParseQuery instead of c.Queries(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 51d13f4 commit bba4b7e

64 files changed

Lines changed: 9141 additions & 6331 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codegen/internal/gather_operations.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,6 @@ func (g *operationGatherer) gatherParameter(param *v3.Parameter) (*ParameterDesc
231231
required = *param.Required
232232
}
233233

234-
styleFunc := ComputeStyleFunc(style)
235-
bindFunc := ComputeBindFunc(style, param.In)
236-
237-
// When a runtime package is configured, prefix function names so generated
238-
// code references them from the runtime package (e.g., "params.StyleSimpleParam").
239-
if g.ctx != nil && g.ctx.RuntimeParamsPrefix() != "" {
240-
styleFunc = g.ctx.RuntimeParamsPrefix() + styleFunc
241-
bindFunc = g.ctx.RuntimeParamsPrefix() + bindFunc
242-
}
243-
244234
desc := &ParameterDescriptor{
245235
Name: param.Name,
246236
GoName: goName,
@@ -253,9 +243,6 @@ func (g *operationGatherer) gatherParameter(param *v3.Parameter) (*ParameterDesc
253243
Schema: schemaDesc,
254244
TypeDecl: typeDecl,
255245

256-
StyleFunc: styleFunc,
257-
BindFunc: bindFunc,
258-
259246
IsStyled: isStyled,
260247
IsPassThrough: isPassThrough,
261248
IsJSON: isJSON,

codegen/internal/operation.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ type ParameterDescriptor struct {
131131
Schema *SchemaDescriptor
132132
TypeDecl string // Go type declaration (e.g., "string", "[]int", "*MyType")
133133

134-
// Precomputed function names for templates
135-
StyleFunc string // "StyleSimpleParam", "StyleFormExplodeParam", etc.
136-
BindFunc string // "BindSimpleParam", "BindFormExplodeParam", etc.
137-
138134
// Encoding modes
139135
IsStyled bool // Uses style/explode serialization (most common)
140136
IsPassThrough bool // No styling, just pass the string through
@@ -195,6 +191,15 @@ func (p *ParameterDescriptor) SchemaFormat() string {
195191
return ""
196192
}
197193

194+
// AllowReserved returns whether this parameter's value may contain RFC 3986
195+
// reserved characters without percent-encoding.
196+
func (p *ParameterDescriptor) AllowReserved() bool {
197+
if p.Spec != nil {
198+
return p.Spec.AllowReserved
199+
}
200+
return false
201+
}
202+
198203
// RequestBodyDescriptor describes a request body for a specific content type.
199204
type RequestBodyDescriptor struct {
200205
ContentType string // "application/json", "multipart/form-data", etc.
@@ -270,21 +275,6 @@ type SecurityRequirement struct {
270275

271276
// Helper functions for computing descriptor fields
272277

273-
// ComputeStyleFunc returns the style function name for a parameter.
274-
func ComputeStyleFunc(style string) string {
275-
return "Style" + ToCamelCase(style) + "Param"
276-
}
277-
278-
// ComputeBindFunc returns the bind function name for a parameter.
279-
// Query parameters use a separate entry point that takes url.Values.
280-
func ComputeBindFunc(style string, location string) string {
281-
base := "Bind" + ToCamelCase(style)
282-
if location == "query" {
283-
return base + "QueryParam"
284-
}
285-
return base + "Param"
286-
}
287-
288278
// ComputeBodyNameTag returns the name tag for a content type.
289279
func ComputeBodyNameTag(contentType string) string {
290280
switch {

0 commit comments

Comments
 (0)