MCPcopy
hub / github.com/danielgtaylor/huma / getAPIPrefix

Function getAPIPrefix

api.go:406–427  ·  view source on GitHub ↗

getAPIPrefix returns the API prefix from the first server URL in the OpenAPI spec. If no server URL is set, then an empty string is returned.

(oapi *OpenAPI)

Source from the content-addressed store, hash-verified

404// getAPIPrefix returns the API prefix from the first server URL in the OpenAPI
405// spec. If no server URL is set, then an empty string is returned.
406func getAPIPrefix(oapi *OpenAPI) string {
407 for _, server := range oapi.Servers {
408 if server.URL == "" {
409 continue
410 }
411
412 serverURL, err := url.Parse(server.URL)
413 if err != nil {
414 panic("invalid server URL: " + server.URL + ": " + err.Error())
415 }
416
417 if serverURL.Path == "" {
418 continue
419 }
420
421 if strings.HasPrefix(server.URL, "/") || serverURL.Host != "" {
422 return serverURL.Path
423 }
424 }
425
426 return ""
427}
428
429func parseContentType(contentType string) (int, int, error) {
430 // Handle e.g. `application/json; charset=utf-8` or `my/format+json`

Callers 2

registerDocsRouteMethod · 0.85
OnAddOperationMethod · 0.85

Calls 1

ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…