Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server URL ignored in $schema field for default configuration #674

Open
baderj opened this issue Dec 9, 2024 · 1 comment
Open

Server URL ignored in $schema field for default configuration #674

baderj opened this issue Dec 9, 2024 · 1 comment
Labels
question Further information is requested

Comments

@baderj
Copy link

baderj commented Dec 9, 2024

I'm using the default configuration

        config := huma.DefaultConfig("Example API", "1.0.0")

and changed the server url as follows

	config.Servers = []*huma.Server{
		{URL: "https://api.example.com", Description: "Root URL of the API"},
	}

This URL is correctly reflected in the generated documentation, both for the example requests and also in the $schema of the response:

image

However, when requesting the API, the $schema-url is build from ctx.Host() and the listening port, which in my case is localhost:8888

 curl -s "https://api.example.com/test | jq | head
{
  "$schema": "http://localhost:8888/api/v1/schemas/Test.json",
  "data": [
    ...
  ]
}

Shouldn't the $schema in the responses also use the configured server?

@danielgtaylor danielgtaylor added the question Further information is requested label Dec 9, 2024
@danielgtaylor
Copy link
Owner

@baderj that is one approach you could use. What I ran into is that sometimes you configure multiple servers and sometimes even multiple DNS entries for the same server (without documenting it as such). The safest thing for me so far has been to use the incoming Host header in the response so that clients can use the same host they are already using to access the schemas / openapi / docs / etc.

I'm open to ideas for when it might be better to use the configured server. Also, you can of course copy and modify the transformer code and set up your own config if this doesn't work for your specific use-case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants