Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested fields, path segments #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ func renderURL(r *registry.Registry) func(method data.Method) string {
fieldNameFn := fieldName(r)
return func(method data.Method) string {
methodURL := method.URL
// capture fields like {abc} or {abc=def/ghi/*}. Discard the pattern after the equal sign.
// capture fields like {abc} or {abc=def/ghi/*}.
// discard the pattern after the equal sign.
// relies on greedy capture within first part
// to avoid matching 2nd group when no equal sign present.
reg := regexp.MustCompile("{([^=}]+)=?([^}]+)?}")
matches := reg.FindAllStringSubmatch(methodURL, -1)
fieldsInPath := make([]string, 0, len(matches))
Expand All @@ -485,7 +488,7 @@ func renderURL(r *registry.Registry) func(method data.Method) string {
partNames = append(partNames, fmt.Sprintf(`["%s"]`, subFieldName))
mbarrien marked this conversation as resolved.
Show resolved Hide resolved
}
fieldName := strings.Join(subFieldNames, ".")
part := fmt.Sprintf(`${req%s}`, strings.Join(partNames, ""))
part := fmt.Sprintf(`${req%s}`, strings.Join(partNames, "?."))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This worked great for me!

methodURL = strings.ReplaceAll(methodURL, expToReplace, part)
fieldsInPath = append(fieldsInPath, fmt.Sprintf(`"%s"`, fieldName))
}
Expand Down