huma icon indicating copy to clipboard operation
huma copied to clipboard

openapi.yaml location with humaecho.NewWithGroup

Open mrgleeco opened this issue 3 months ago • 1 comments

As preface, I'm n00b here and kudos are in order. Huma is really quite awesome. So, I am a fan of echo and things work great until i use an echo group like so:

		e := echo.New()
		hc := huma.DefaultConfig(appName, appVersion)
		g := e.Group("/api/v0")
		app := humaecho.NewWithGroup(e, g, hc)

When I go to get the openAPI docs, curl localhost:8888/api/v0/docs it looks OK, but returns this content:

    <elements-api
      apiDescriptionUrl="/openapi.yaml"
      router="hash"
      layout="sidebar"
      tryItCredentialsPolicy="same-origin"
    />

Here is where the fail is: the YAML doc appears to be at /api/v0/openapi.yaml. Is there a magic setting to get things to realign? Id prefer to have the spec within my group prefix URI, but if not possible, is there a way to place at the root?

mrgleeco avatar Sep 04 '25 04:09 mrgleeco

Don't know if it's correct, I'm quite new to echo and huma, but after looking at https://huma.rocks/features/bring-your-own-router/#route-groups-base-urls I made this that seem to be workning...

	grp := e.Group("/api/v0")
	hc:= huma.DefaultConfig(appName, appVersion)
	hc.Servers = []*huma.Server{
		{
			URL:         "/api/v0",
			Description: "Local development server",
		},
	}

	api := humaecho.NewWithGroup(e, grp, hc)

kmpm avatar Nov 12 '25 06:11 kmpm