Skip to content

Commit

Permalink
fix: inferred path-params not camel-cased
Browse files Browse the repository at this point in the history
  • Loading branch information
czabaj committed Oct 18, 2024
1 parent 745b0f2 commit 9a7d834
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ func renderServiceTags(services []*descriptor.Service, reg *descriptor.Registry)
// Returns:
//
// The modified pathParts and pathParams slice.
func expandPathPatterns(pathParts []string, pathParams []descriptor.Parameter) ([]string, []descriptor.Parameter) {
func expandPathPatterns(pathParts []string, pathParams []descriptor.Parameter, reg *descriptor.Registry) ([]string, []descriptor.Parameter) {
expandedPathParts := []string{}
modifiedPathParams := pathParams
for _, pathPart := range pathParts {
Expand Down Expand Up @@ -1192,6 +1192,9 @@ func expandPathPatterns(pathParts []string, pathParams []descriptor.Parameter) (
}
lastPart := expandedPathParts[len(expandedPathParts)-1]
paramName := strings.TrimSuffix(lastPart, "s")
if reg.GetUseJSONNamesForFields() {
paramName = casing.JSONCamelCase(paramName)
}
expandedPathParts = append(expandedPathParts, "{"+paramName+"}")
newParam := descriptor.Parameter{
Target: &descriptor.Field{
Expand Down Expand Up @@ -1248,7 +1251,7 @@ func renderServices(services []*descriptor.Service, paths *openapiPathsObject, r
parts := templateToParts(b.PathTmpl.Template, reg, meth.RequestType.Fields, msgs)
pathParams := b.PathParams
if reg.GetExpandSlashedPathPatterns() {
parts, pathParams = expandPathPatterns(parts, pathParams)
parts, pathParams = expandPathPatterns(parts, pathParams, reg)
}
// extract any constraints specified in the path placeholders into ECMA regular expressions
pathParamRegexpMap := partsToRegexpMap(parts)
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-openapiv2/internal/genopenapi/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4288,7 +4288,7 @@ func templateToRegexpMap(path string, reg *descriptor.Registry, fields []*descri
}

func templateToExpandedPath(path string, reg *descriptor.Registry, fields []*descriptor.Field, msgs []*descriptor.Message, pathParams []descriptor.Parameter) (string, []descriptor.Parameter) {
pathParts, pathParams := expandPathPatterns(templateToParts(path, reg, fields, msgs), pathParams)
pathParts, pathParams := expandPathPatterns(templateToParts(path, reg, fields, msgs), pathParams, reg)
return partsToOpenAPIPath(pathParts, make(map[string]string)), pathParams
}

Expand Down

0 comments on commit 9a7d834

Please sign in to comment.