Repository navigation
feat(routes): add opt-in route prefix resolution from host.json - #869
Merged
Merged
Conversation
Add an opt-in helper that returns the effective route prefix without duplicating it in code. The AzureFunctionsJobHost__extensions__http__routePrefix app setting wins, then extensions.http.routePrefix from the given host.json (default ./host.json), then /api. The result is normalized for every existing route_prefix parameter, an empty prefix is honored at each level, and an unreadable or malformed file warns with RuntimeWarning and falls back. No existing default or signature changes. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
…mismatch Let --route-prefix auto resolve the prefix from the host.json beside the imported --app module (current directory otherwise), honoring the app-setting override. Without auto, a host.json prefix that differs from the effective one now produces a structured route-prefix-mismatch warning that gates --fail-on-warnings. The check reads the file only, and missing, malformed or unreadable files never produce it. The default stays /api. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
Add the resolution section to the route prefix guide with the precedence, the function_app.py usage and the app-setting override, point the getting-started guide at it, and add the helper to the API reference. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
Describe the auto value, the literal /auto prefix, the route-prefix-mismatch warning and its exit code 2 behavior under --fail-on-warnings. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
…notes Mention the opt-in helper and the CLI auto value in the README, and record in the design notes that detection is opt-in and that Python APIs do not warn about mismatches. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
List the new public helper and the CLI behavior in llms.txt and llms-full.txt. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
A host.json saved with a UTF-8 byte order mark, as some Windows editors do, made resolve_route_prefix warn and fall back to /api. Decode with utf-8-sig so the file is read, add a regression test, and document that the file is parsed as strict JSON, so comments and trailing commas are still reported as unreadable. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the opt-in route-prefix resolution change.
No open issues 🎉
What changed in this PR
Adds opt-in route-prefix resolution to align generated OpenAPI paths and Swagger UI URLs with Azure Functions configuration, while preserving the /api default.
Changes:
- Exports
resolve_route_prefix()with app-setting precedence,host.jsonfallback, normalization, and invalid-file diagnostics. - Adds CLI
--route-prefix autoand structured mismatch warnings that gate--fail-on-warnings. - Adds regression coverage and documents configuration, discovery rules, and compatibility.
| File | Description |
|---|---|
tests/test_spec_warnings.py |
Checks the new warning code’s serialized value. |
tests/test_public_api.py |
Verifies the helper is publicly exported. |
tests/test_host_config.py |
Covers precedence, normalization, fallback, and diagnostics. |
tests/test_docs_routes_host_config.py |
Checks Swagger URLs use resolved prefixes. |
tests/test_cli_host_config.py |
Covers automatic resolution, discovery, and warning gating. |
src/azure_functions_openapi/host_config.py |
Implements configuration reading and prefix resolution. |
src/azure_functions_openapi/cli.py |
Integrates resolved prefixes and mismatch warnings. |
src/azure_functions_openapi/_warnings.py |
Adds ROUTE_PREFIX_MISMATCH. |
src/azure_functions_openapi/_cli_route_prefix.py |
Implements CLI discovery and mismatch detection. |
src/azure_functions_openapi/__init__.py |
Exports resolve_route_prefix. |
README.md |
Introduces opt-in prefix detection. |
llms.txt |
Summarizes the new public helper. |
llms-full.txt |
Documents resolution and CLI warning behavior. |
docs/route-prefix.md |
Explains precedence, usage, and compatibility. |
docs/getting-started.md |
Adds helper-based route configuration guidance. |
docs/cli.md |
Documents automatic resolution and warning exit behavior. |
docs/api.md |
Adds the helper reference and mismatch-warning scope. |
DESIGN.md |
Records the opt-in compatibility policy. |
Review effort: Balanced
…ilter-independent Pin that --route-prefix auto falls back to /api with a RuntimeWarning and does not gate --fail-on-warnings when host.json is unreadable, so any change to that policy is deliberate. Record warnings with the always filter in the absent-configuration test so its empty-list assertion cannot pass because a filter hid the warning. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
Say that the helper treats a present but empty app setting as no prefix without claiming how a hosting environment delivers it, and document that --route-prefix auto falls back to /api with a RuntimeWarning that does not gate --fail-on-warnings when host.json cannot be read. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
Align the route prefix guide with the CLI guide so a missing host.json is not read as one of the cases that prints the RuntimeWarning in --route-prefix auto mode. Refs #859 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@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
The URL prefix the Functions host serves HTTP triggers under (
host.json,extensions.http.routePrefix) had to be repeated asroute_prefix=and--route-prefix, and nothing detected a mismatch. This adds opt-in resolution and a CLI warning without changing any default.Changes
resolve_route_prefix(host_json=None). It returns the effective prefix: theAzureFunctionsJobHost__extensions__http__routePrefixapp setting if present, thenextensions.http.routePrefixfrom the givenhost.json(default./host.json), then/api. The result is normalized for every existingroute_prefixparameter, an empty prefix is honored at each level, a missing file or key falls back silently, and an unreadable or malformed file warns withRuntimeWarningand falls back. The file is parsed as strict JSON with an optional UTF-8 byte order mark. It never imports or executes application code.--route-prefix autouses the helper with thehost.jsonbeside the imported--appmodule (the current directory otherwise). The default is still/api; a literal prefix namedautois written/auto.auto, ahost.jsonprefix that differs from the effective prefix produces a structuredroute-prefix-mismatchwarning (newWarningCode) on stderr, and it gates--fail-on-warnings. The check reads the file only, and missing, malformed or unreadable files never produce it.DESIGN.mdand the LLM references. The repository's formatter hook also re-indented one closing parenthesis indocs/getting-started.mdand one comment indocs/route-prefix.md(whitespace only).Validation
Run locally on
1c5b4fa:make check-all: exit 0 (1700 passed, 30 skipped). The skipped tests need the optionalazure-functions-validationpackage, which the Hatch environment does not install. Coverage is 95.39% (gate: 95%).mkdocs build --strict: exit 0. The new test files also pass on Python 3.14.host.jsonsetsroutePrefixtov1: the mismatch warning with exit 0; exit 2 with--fail-on-warningsand no output file;--route-prefix autogiving/v1/...paths, also whenhost.jsonstarts with a byte order mark; an explicit/v1without a warning; the app-setting override, including an empty value; ahost.jsonwithoutroutePrefix; and the Swagger UI URL/v1/openapi.jsonwhenresolve_route_prefixfeedsregister_openapi_routes.1c5b4fa: all check runs completed with no failures, including the requiredAnalyze,bandit,ci-required,PR titleandsemgrepcontexts.c5683c0and found no blocking issues; its notes are applied, and the last commit (1c5b4fa) only rewords one sentence indocs/route-prefix.md.DESIGN.mdanddocs/cli.mdare policy-bearing files, so a maintainer review of the final head is still needed.Compatibility
resolve_route_prefixandWarningCode.ROUTE_PREFIX_MISMATCHare additions.generate --fail-on-warningsin a project whosehost.jsonprefix differs from the effective prefix now exit 2. That is the drift this detects; fix it with--route-prefix <value>or--route-prefix auto.--route-prefixthat differs fromhost.jsonis still honored for the generated paths, but it also produces the warning. A job that intentionally documents a gateway-facing prefix should therefore not use--fail-on-warnings.autois now a reserved--route-prefixvalue.host.jsonis looked up beside the imported--appmodule, so a module inside a package reads the file in that package directory, not the project root.auto, an unreadable or malformedhost.jsonfalls back to/apiwith aRuntimeWarningthat does not gate--fail-on-warnings. A file with comments or trailing commas counts as malformed, although the Functions host may accept it. This follows the decision recorded on feat(routes): read the host.json route prefix instead of duplicating it in code and CLI flags #859; a hard error or a gating warning inautomode would be a small follow-up if you prefer it./api, so an explicit value cannot be told apart from the default.Related Issues
Closes #859