fix(api): propagate flat-schema hoisting option across spec output APIs - #382
Conversation
There was a problem hiding this comment.
Pull request overview
This PR exposes the opt-in hoist_flat_schemas flag (added in #377) through all public spec-output wrapper APIs (get_openapi_json, get_openapi_yaml, generate_openapi_report) by adding the parameter, forwarding it into generate_openapi_spec, and extending tests to cover both default and opted-in behavior.
Changes:
- Add
hoist_flat_schemas: bool = Falseto JSON/YAML/report wrapper APIs and forward it togenerate_openapi_spec. - Update wrapper docstrings to mention the new option.
- Extend tests to assert wrapper behavior for both
hoist_flat_schemas=False(default) andTrue, and update existing mock call assertions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/azure_functions_openapi/spec.py | Adds and forwards hoist_flat_schemas through the wrapper APIs and updates wrapper docs. |
| tests/test_openapi_enhanced.py | Updates wrapper call-assertion mocks to include the newly forwarded kwarg. |
| tests/test_hoist_flat.py | Adds wrapper-level tests to ensure the hoist flag propagates through JSON/YAML/report outputs. |
Suppressed comments (2)
src/azure_functions_openapi/spec.py:739
- Same positional-argument compatibility issue as
get_openapi_json: insertinghoist_flat_schemasbeforeregistryshifts the last positional argument away from the registry parameter and can break existing positional callers.
security_schemes: dict[str, dict[str, Any]] | None = None,
route_prefix: str = DEFAULT_ROUTE_PREFIX,
strict: bool = False,
hoist_flat_schemas: bool = False,
registry: OpenAPIRegistry | None = None,
) -> str:
src/azure_functions_openapi/spec.py:755
- This docstring also omits the
registryparameter even though it is part of the public signature, which makes it unclear how to generate YAML from an injected registry.
description: Description for the OpenAPI info object
security_schemes: Security scheme definitions for components.securitySchemes.
route_prefix: HTTP route prefix from ``host.json``
(``extensions.http.routePrefix``). Defaults to ``"/api"``. Pass
``""`` for hosts that disable the prefix or a custom value such
as ``"/v1"``.
strict: When ``True``, raise on any registry entry processing failure.
hoist_flat_schemas: When ``True`` (opt-in, #375), structured flat
schemas are promoted into ``components.schemas``. Defaults to
``False`` to preserve the existing generated spec shape.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| security_schemes: dict[str, dict[str, Any]] | None = None, | ||
| route_prefix: str = DEFAULT_ROUTE_PREFIX, | ||
| strict: bool = False, | ||
| hoist_flat_schemas: bool = False, | ||
| registry: OpenAPIRegistry | None = None, | ||
| ) -> str: |
| security_schemes: Security scheme definitions for components.securitySchemes. | ||
| route_prefix: HTTP route prefix from ``host.json`` | ||
| (``extensions.http.routePrefix``). Defaults to ``"/api"``. Pass | ||
| ``""`` for hosts that disable the prefix or a custom value such | ||
| as ``"/v1"``. | ||
| strict: When ``True``, raise on any registry entry processing failure. | ||
| hoist_flat_schemas: When ``True`` (opt-in, #375), structured flat | ||
| schemas are promoted into ``components.schemas``. Defaults to | ||
| ``False`` to preserve the existing generated spec shape. |
| security_schemes: dict[str, dict[str, Any]] | None = None, | ||
| route_prefix: str = DEFAULT_ROUTE_PREFIX, | ||
| strict: bool = False, | ||
| hoist_flat_schemas: bool = False, | ||
| registry: OpenAPIRegistry | None = None, | ||
| ) -> SpecReport: |
Keep hoist_flat_schemas as the trailing parameter (after registry) in get_openapi_json/get_openapi_yaml/generate_openapi_report so positional callers passing a registry are unaffected and the signatures match generate_openapi_spec. Document the registry parameter.
|
Addressed Copilot review: reordered |
Summary
hoist_flat_schemas: bool = Falsetoget_openapi_json,get_openapi_yaml, andgenerate_openapi_report, forwarding it togenerate_openapi_specso the opt-in flat-schema hoisting from feat(spec): opt-in hoisting of flat schemas into components (#375) #377 is reachable through every public output API (previously onlygenerate_openapi_specaccepted it).generate_openapi_report's "Parameters mirrorgenerate_openapi_spec" docstring is accurate again.components.schemaswhenTrueand preserves the current inline shape whenFalse; updates existing call-assertion mocks to include the new forwarded kwarg.Acceptance
make check-allgreen (coverage 96.26%)Closes #378