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

Revert #704 #1000

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 0 additions & 14 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,26 +672,12 @@ func templateToSwaggerPath(path string, reg *descriptor.Registry) string {
// memory.
re := regexp.MustCompile("{([a-zA-Z][a-zA-Z0-9_.]*).*}")
for index, part := range parts {
// If part is a resource name such as "parent", "name", "user.name", the format info must be retained.
prefix := re.ReplaceAllString(part, "$1")
if isResourceName(prefix) {
continue
}
parts[index] = re.ReplaceAllString(part, "{$1}")
}

return strings.Join(parts, "/")
}

func isResourceName(prefix string) bool {
words := strings.Split(prefix, ".")
l := len(words)
field := words[l-1]
words = strings.Split(field, ":")
field = words[0]
return field == "parent" || field == "name"
}

func renderServices(services []*descriptor.Service, paths swaggerPathsObject, reg *descriptor.Registry, requestResponseRefs, customRefs refMap) error {
// Correctness of svcIdx and methIdx depends on 'services' containing the services in the same order as the 'file.Service' array.
for svcIdx, svc := range services {
Expand Down
20 changes: 10 additions & 10 deletions protoc-gen-swagger/genswagger/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,16 +902,16 @@ func TestTemplateToSwaggerPath(t *testing.T) {
{"/{test=prefix/that/has/multiple/parts/to/it/*}", "/{test}"},
{"/{test1}/{test2}", "/{test1}/{test2}"},
{"/{test1}/{test2}/", "/{test1}/{test2}/"},
{"/{name=prefix/*}", "/{name=prefix/*}"},
{"/{name=prefix1/*/prefix2/*}", "/{name=prefix1/*/prefix2/*}"},
{"/{user.name=prefix/*}", "/{user.name=prefix/*}"},
{"/{user.name=prefix1/*/prefix2/*}", "/{user.name=prefix1/*/prefix2/*}"},
{"/{parent=prefix/*}/children", "/{parent=prefix/*}/children"},
{"/{name=prefix/*}:customMethod", "/{name=prefix/*}:customMethod"},
{"/{name=prefix1/*/prefix2/*}:customMethod", "/{name=prefix1/*/prefix2/*}:customMethod"},
{"/{user.name=prefix/*}:customMethod", "/{user.name=prefix/*}:customMethod"},
{"/{user.name=prefix1/*/prefix2/*}:customMethod", "/{user.name=prefix1/*/prefix2/*}:customMethod"},
{"/{parent=prefix/*}/children:customMethod", "/{parent=prefix/*}/children:customMethod"},
{"/{name=prefix/*}", "/{name}"},
{"/{name=prefix1/*/prefix2/*}", "/{name}"},
{"/{user.name=prefix/*}", "/{user.name}"},
{"/{user.name=prefix1/*/prefix2/*}", "/{user.name}"},
{"/{parent=prefix/*}/children", "/{parent}/children"},
{"/{name=prefix/*}:customMethod", "/{name}:customMethod"},
{"/{name=prefix1/*/prefix2/*}:customMethod", "/{name}:customMethod"},
{"/{user.name=prefix/*}:customMethod", "/{user.name}:customMethod"},
{"/{user.name=prefix1/*/prefix2/*}:customMethod", "/{user.name}:customMethod"},
{"/{parent=prefix/*}/children:customMethod", "/{parent}/children:customMethod"},
}
reg := descriptor.NewRegistry()
reg.SetUseJSONNamesForFields(false)
Expand Down