danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.71k stars 134 forks source link

Defining Servers Causes 404 from OpenAPI Endpoint #443

Open derekssmith opened 2 months ago

derekssmith commented 2 months ago

When I add servers to the OpenAPI configuration the docs page will not load because the openapi.json call returns a 404.

apiConfig := huma.DefaultConfig("My API V1", "1.0.0")
apiConfig.Info.Description = apiDescription

apiConfig.Servers = append(apiConfig.Servers, &huma.Server{
    URL:         "https://myapi.beta.mydomain.com/v1",
    Description: "Beta Server",
})
danielgtaylor commented 2 months ago

@derekssmith this is intended to be used with the route groups and base URL settings as described here:

https://huma.rocks/features/bring-your-own-router/#route-groups-base-urls

Typically you'd set up a route group with the /v1 path and then the docs & OpenAPI will be served from there as well. Huma itself doesn't apply any prefix from the server list because it could happen either at the gateway or within the router itself, and this provides the most flexibility for setting up those various scenarios. Hopefully that helps!