MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / SwaggerUriToStdHttpUri

Function SwaggerUriToStdHttpUri

pkg/codegen/utils.go:643–654  ·  view source on GitHub ↗

SwaggerUriToStdHttpUri converts a swagger style path URI with parameters to a net/http ServeMux compatible path URI. Parameter names are sanitized to be valid Go identifiers, as required by ServeMux wildcard segments. Valid input parameters are: {param} {param*} {.param} {.param*} {;param} {;

(uri string)

Source from the content-addressed store, hash-verified

641// {?param}
642// {?param*}
643func SwaggerUriToStdHttpUri(uri string) string {
644 // https://pkg.go.dev/net/http#hdr-Patterns-ServeMux
645 // The special wildcard {$} matches only the end of the URL. For example, the pattern "/{$}" matches only the path "/", whereas the pattern "/" matches every path.
646 if uri == "/" {
647 return "/{$}"
648 }
649
650 return pathParamRE.ReplaceAllStringFunc(uri, func(match string) string {
651 sub := pathParamRE.FindStringSubmatch(match)
652 return "{" + SanitizeGoIdentifier(sub[1]) + "}"
653 })
654}
655
656// OrderedParamsFromUri returns the argument names, in order, in a given URI string, so for
657// /path/{param1}/{.param2*}/{?param3}, it would return param1, param2, param3

Callers 1

Calls 1

SanitizeGoIdentifierFunction · 0.85

Tested by 1