normalizeDocURL cleans docURL's path and enforces metadataDocsAPIVersion for https://docs.github.com/rest and https://docs.github.com/enterprise-cloud@latest/rest URLs.
(docURL string)
| 486 | // https://docs.github.com/rest and |
| 487 | // https://docs.github.com/enterprise-cloud@latest/rest URLs. |
| 488 | func normalizeDocURL(docURL string) string { |
| 489 | u, err := url.Parse(docURL) |
| 490 | if err != nil { |
| 491 | return docURL |
| 492 | } |
| 493 | cleanPath := path.Clean(u.Path) |
| 494 | isRESTDocsURL := u.Host == "docs.github.com" && |
| 495 | (cleanPath == "/rest" || |
| 496 | strings.HasPrefix(cleanPath, "/rest/") || |
| 497 | cleanPath == "/enterprise-cloud@latest/rest" || |
| 498 | strings.HasPrefix(cleanPath, "/enterprise-cloud@latest/rest/")) |
| 499 | if !isRESTDocsURL { |
| 500 | return docURL |
| 501 | } |
| 502 | |
| 503 | u.Path = cleanPath |
| 504 | q := u.Query() |
| 505 | if q.Get("apiVersion") == "" { |
| 506 | q.Set("apiVersion", metadataDocsAPIVersion) |
| 507 | } |
| 508 | u.RawQuery = q.Encode() |
| 509 | return u.String() |
| 510 | } |
| 511 | |
| 512 | // nodeServiceMethod returns the name of the service method represented by fn, or "" if fn is not a service method. |
| 513 | // Name is in the form of "Receiver.Function", for example "IssuesService.Create". |
searching dependent graphs…