Repository navigation
Advertise route prefix via servers instead of on every path - #11
Merged
Merged
Conversation
Path keys are now relative to the API base (e.g. `/items`, not `/api/items`). The Functions route prefix is a global base path, so it is advertised once via the document's top-level `servers` array — the idiomatic OpenAPI representation of a shared base URL (effective URL = servers[].url + path key). By default the server URL is inferred from the incoming request (scheme, host, path base, honouring X-Forwarded-Proto / X-Forwarded-Host), with a relative fallback when the host is unresolved. The new OpenApiOptions.Servers lets callers advertise fixed URLs (e.g. an API gateway) verbatim, skipping request inference. The per-request servers are applied to a shallow copy of the cached document so the shared singleton is never mutated across differing hosts. BREAKING (pre-1.0): consumers relying on `/api` in the generated path keys must update. Recommend releasing as 0.2.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves the Functions route prefix (
apiby default) out of every generated path key and into the document's top-levelserversarray — the idiomatic OpenAPI representation of a shared base path./items, not/api/items.servers[].url+ path key.Server URL resolution
X-Forwarded-Proto/X-Forwarded-Host. The advertised base therefore matches wherever the doc is served from (local, deployed, behind a proxy)./api) when the host can't be resolved.OpenApiOptions.Servers— entries are used verbatim and request inference is skipped (for fixed gateway/APIM URLs).The per-request
serversare applied to a shallow copy of the cached document (new OpenApiDocument(cached) { Servers = ... }), so the shared singleton is never mutated when different hosts hit the endpoint concurrently.Changes
FunctionEndpointDiscovery— emits route-relative paths (routePrefixremoved fromDiscover/TryDiscover/CombinePath).OpenApiOptions— addedServers(IList<OpenApiServer>); refinedRoutePrefixdocs.OpenApiHttpFunctions— per-requestserversinjection (BuildServers,WithServers,ResolveRequestBaseUrl).ServerBasePathTests.cs(6 tests: inference, forwarded headers, relative fallback, empty prefix, explicit override, per-host isolation without cache mutation).Testing
dotnet test— 156/156 pass.Note
This is a document-shape change: consumers relying on
/apiin the generated path keys must update. Pre-1.0, so acceptable — recommend releasing as 0.2.0.