fastapi-apcore 0.5.1__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/PKG-INFO +12 -10
  2. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/README.md +6 -4
  3. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/pyproject.toml +6 -6
  4. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/client.py +29 -0
  5. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/extensions.py +8 -0
  6. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/scanners/openapi.py +48 -0
  7. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore.egg-info/PKG-INFO +12 -10
  8. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore.egg-info/SOURCES.txt +1 -0
  9. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore.egg-info/requires.txt +5 -5
  10. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_extensions.py +46 -0
  11. fastapi_apcore-0.6.0/tests/test_proxy_preflight.py +118 -0
  12. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/setup.cfg +0 -0
  13. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/__init__.py +0 -0
  14. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/cli.py +0 -0
  15. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/__init__.py +0 -0
  16. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/config.py +0 -0
  17. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/context.py +0 -0
  18. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/observability.py +0 -0
  19. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/registry.py +0 -0
  20. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/serializers.py +0 -0
  21. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/shortcuts.py +0 -0
  22. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/engine/tasks.py +0 -0
  23. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/governance.py +0 -0
  24. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/output/__init__.py +0 -0
  25. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/output/registry_writer.py +0 -0
  26. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/output/yaml_writer.py +0 -0
  27. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/py.typed +0 -0
  28. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/scanners/__init__.py +0 -0
  29. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/scanners/base.py +0 -0
  30. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore/scanners/native.py +0 -0
  31. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore.egg-info/dependency_links.txt +0 -0
  32. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore.egg-info/entry_points.txt +0 -0
  33. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/src/fastapi_apcore.egg-info/top_level.txt +0 -0
  34. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_acl_demo.py +0 -0
  35. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_client.py +0 -0
  36. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_config.py +0 -0
  37. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_context.py +0 -0
  38. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_governance.py +0 -0
  39. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_integration.py +0 -0
  40. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_observability.py +0 -0
  41. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_public_api.py +0 -0
  42. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_registry.py +0 -0
  43. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_scanner.py +0 -0
  44. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_serializers.py +0 -0
  45. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_shortcuts.py +0 -0
  46. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_tasks.py +0 -0
  47. {fastapi_apcore-0.5.1 → fastapi_apcore-0.6.0}/tests/test_writers.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-apcore
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: FastAPI integration for apcore AI-Perceivable Core — exposes FastAPI routes as apcore modules with auto-discovery, schema extraction from Pydantic models, and OpenAPI-based scanning.
5
5
  Author-email: aiperceivable <team@aiperceivable.com>
6
6
  License-Expression: Apache-2.0
@@ -10,17 +10,17 @@ Keywords: fastapi,apcore,mcp,llm,ai,tools,pydantic,schema,module,cli,auto-discov
10
10
  Requires-Python: >=3.11
11
11
  Description-Content-Type: text/markdown
12
12
  Requires-Dist: fastapi>=0.100
13
- Requires-Dist: apcore>=0.32.2
14
- Requires-Dist: apcore-toolkit>=0.14.1
13
+ Requires-Dist: apcore>=0.33.0
14
+ Requires-Dist: apcore-toolkit>=0.15.0
15
15
  Provides-Extra: mcp
16
- Requires-Dist: apcore-mcp>=0.23.3; extra == "mcp"
16
+ Requires-Dist: apcore-mcp>=0.23.4; extra == "mcp"
17
17
  Provides-Extra: cli
18
- Requires-Dist: apcore-cli>=0.12.6; extra == "cli"
18
+ Requires-Dist: apcore-cli>=0.14.1; extra == "cli"
19
19
  Requires-Dist: click>=8.0; extra == "cli"
20
20
  Provides-Extra: all
21
21
  Requires-Dist: fastapi-apcore[cli,mcp]; extra == "all"
22
22
  Provides-Extra: dev
23
- Requires-Dist: apdev[dev]>=0.2.3; extra == "dev"
23
+ Requires-Dist: apdev[dev]>=0.2.7; extra == "dev"
24
24
  Requires-Dist: pytest>=7.0; extra == "dev"
25
25
  Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
26
26
  Requires-Dist: httpx>=0.24; extra == "dev"
@@ -59,10 +59,10 @@ FastAPI integration for [apcore](https://github.com/aiperceivable/apcore-python)
59
59
 
60
60
  - Python >= 3.11
61
61
  - FastAPI >= 0.100
62
- - apcore >= 0.32.2
63
- - apcore-toolkit >= 0.14.1
64
- - apcore-mcp >= 0.23.3 (optional, `[mcp]` extra)
65
- - apcore-cli >= 0.12.6 (optional, `[cli]` extra)
62
+ - apcore >= 0.33.0
63
+ - apcore-toolkit >= 0.15.0
64
+ - apcore-mcp >= 0.23.4 (optional, `[mcp]` extra)
65
+ - apcore-cli >= 0.14.1 (optional, `[cli]` extra)
66
66
 
67
67
  ## Installation
68
68
 
@@ -333,6 +333,8 @@ if __name__ == "__main__":
333
333
 
334
334
  Each scanned route becomes a CLI command named after `display.cli.alias` from the binding overlay (or the module_id if no overlay is set). The commands forward HTTP requests to the running API using `HTTPProxyRegistryWriter`. Built-in subcommands include `list`, `describe`, `completion`, and `man`.
335
335
 
336
+ `create_cli()` runs a proxy preflight by default (`validate_proxy=True`). It resolves inherited and referenced OpenAPI parameters through apcore-toolkit's effective-parameter scanner, then refuses to register any operation the HTTP proxy cannot forward losslessly — for example a query parameter on a JSON-body `POST`, a body on a query-method route, or conflicting path/query/body names. The error names every offending module. Pass `validate_proxy=False` to keep the legacy best-effort behaviour. Native scanning (`scan_source="native"`) skips this check because it has no OpenAPI document to resolve against.
337
+
336
338
  `commands_dir` points to a directory of plain Python function files. When set, `ConventionScanner` from `apcore-toolkit` scans for public functions and registers them as additional modules alongside the scanned API routes (§5.14).
337
339
 
338
340
  ### Display Overlay (`binding_path`)
@@ -29,10 +29,10 @@ FastAPI integration for [apcore](https://github.com/aiperceivable/apcore-python)
29
29
 
30
30
  - Python >= 3.11
31
31
  - FastAPI >= 0.100
32
- - apcore >= 0.32.2
33
- - apcore-toolkit >= 0.14.1
34
- - apcore-mcp >= 0.23.3 (optional, `[mcp]` extra)
35
- - apcore-cli >= 0.12.6 (optional, `[cli]` extra)
32
+ - apcore >= 0.33.0
33
+ - apcore-toolkit >= 0.15.0
34
+ - apcore-mcp >= 0.23.4 (optional, `[mcp]` extra)
35
+ - apcore-cli >= 0.14.1 (optional, `[cli]` extra)
36
36
 
37
37
  ## Installation
38
38
 
@@ -303,6 +303,8 @@ if __name__ == "__main__":
303
303
 
304
304
  Each scanned route becomes a CLI command named after `display.cli.alias` from the binding overlay (or the module_id if no overlay is set). The commands forward HTTP requests to the running API using `HTTPProxyRegistryWriter`. Built-in subcommands include `list`, `describe`, `completion`, and `man`.
305
305
 
306
+ `create_cli()` runs a proxy preflight by default (`validate_proxy=True`). It resolves inherited and referenced OpenAPI parameters through apcore-toolkit's effective-parameter scanner, then refuses to register any operation the HTTP proxy cannot forward losslessly — for example a query parameter on a JSON-body `POST`, a body on a query-method route, or conflicting path/query/body names. The error names every offending module. Pass `validate_proxy=False` to keep the legacy best-effort behaviour. Native scanning (`scan_source="native"`) skips this check because it has no OpenAPI document to resolve against.
307
+
306
308
  `commands_dir` points to a directory of plain Python function files. When set, `ConventionScanner` from `apcore-toolkit` scans for public functions and registers them as additional modules alongside the scanned API routes (§5.14).
307
309
 
308
310
  ### Display Overlay (`binding_path`)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fastapi-apcore"
7
- version = "0.5.1"
7
+ version = "0.6.0"
8
8
  description = "FastAPI integration for apcore AI-Perceivable Core — exposes FastAPI routes as apcore modules with auto-discovery, schema extraction from Pydantic models, and OpenAPI-based scanning."
9
9
  requires-python = ">=3.11"
10
10
  readme = "README.md"
@@ -28,16 +28,16 @@ keywords = [
28
28
  ]
29
29
  dependencies = [
30
30
  "fastapi>=0.100",
31
- "apcore>=0.32.2",
32
- "apcore-toolkit>=0.14.1",
31
+ "apcore>=0.33.0",
32
+ "apcore-toolkit>=0.15.0",
33
33
  ]
34
34
 
35
35
  [project.optional-dependencies]
36
- mcp = ["apcore-mcp>=0.23.3"]
37
- cli = ["apcore-cli>=0.12.6", "click>=8.0"]
36
+ mcp = ["apcore-mcp>=0.23.4"]
37
+ cli = ["apcore-cli>=0.14.1", "click>=8.0"]
38
38
  all = ["fastapi-apcore[mcp,cli]"]
39
39
  dev = [
40
- "apdev[dev]>=0.2.3",
40
+ "apdev[dev]>=0.2.7",
41
41
  "pytest>=7.0",
42
42
  "pytest-asyncio>=0.21",
43
43
  "httpx>=0.24",
@@ -603,6 +603,7 @@ class FastAPIApcore:
603
603
  max_content_width: int | None = None,
604
604
  docs_url: str | None = None,
605
605
  verbose_help: bool = False,
606
+ validate_proxy: bool = True,
606
607
  ) -> Any:
607
608
  """Create an apcore-cli Click group with all API routes as commands.
608
609
 
@@ -643,6 +644,13 @@ class FastAPIApcore:
643
644
  (``--input``, ``--yes``, ``--large-input``, ``--format``) in
644
645
  ``--help`` output. Defaults to ``False`` (hidden). Users can
645
646
  also toggle this at runtime with the ``--verbose`` flag.
647
+ validate_proxy: When ``True`` (default) and ``scan_source="openapi"``,
648
+ resolve inherited OpenAPI parameters through apcore-toolkit's
649
+ effective-parameter scanner and refuse to register operations
650
+ that cannot be forwarded losslessly (for example a query
651
+ parameter on a JSON-body method). Set ``False`` to keep the
652
+ legacy best-effort proxy. Native scanning skips this check
653
+ because it has no OpenAPI document to resolve against.
646
654
 
647
655
  Returns:
648
656
  A Click Group that can be invoked with ``cli(standalone_mode=True)``.
@@ -705,6 +713,27 @@ class FastAPIApcore:
705
713
 
706
714
  modules = DisplayResolver().resolve(modules, binding_path=binding_path)
707
715
 
716
+ # 1c. Resolve effective OpenAPI inputs and reject operations the HTTP
717
+ # proxy cannot forward losslessly. The writer switches to effective
718
+ # forwarding only when ``proxy_inputs`` metadata is present.
719
+ if validate_proxy and scan_source == "openapi" and modules:
720
+ from apcore_toolkit import validate_effective_proxy_modules
721
+
722
+ from fastapi_apcore.scanners.openapi import apply_effective_proxy_inputs
723
+
724
+ spec = app.openapi()
725
+ if not isinstance(spec, dict):
726
+ logger.warning(
727
+ "create_cli: app.openapi() did not return an OpenAPI document; "
728
+ "skipping proxy preflight"
729
+ )
730
+ else:
731
+ modules = apply_effective_proxy_inputs(modules, spec)
732
+ try:
733
+ validate_effective_proxy_modules(modules)
734
+ except ValueError as exc:
735
+ raise ValueError(f"create_cli() proxy preflight failed: {exc}") from exc
736
+
708
737
  # 2. Register as HTTP proxy modules
709
738
  registry = Registry()
710
739
  writer = HTTPProxyRegistryWriter(
@@ -80,10 +80,18 @@ class FastAPIDiscoverer:
80
80
  func=flattened,
81
81
  module_id=fm.module_id,
82
82
  description=fm.description,
83
+ documentation=getattr(fm, "documentation", None),
83
84
  tags=fm.tags,
84
85
  version=fm.version,
86
+ annotations=getattr(fm, "annotations", None),
87
+ metadata=getattr(fm, "metadata", None),
88
+ display=getattr(fm, "display", None),
89
+ examples=getattr(fm, "examples", None),
85
90
  input_schema=fm.input_schema,
86
91
  output_schema=fm.output_schema,
92
+ # apcore 0.33.0 added resources (e.g. a per-module
93
+ # timeout); rebuilding the module must not drop it.
94
+ resources=getattr(fm, "resources", None),
87
95
  )
88
96
  except (ImportError, AttributeError):
89
97
  pass
@@ -14,6 +14,7 @@ from __future__ import annotations
14
14
  import logging
15
15
  import re
16
16
  import warnings
17
+ from dataclasses import replace
17
18
  from typing import TYPE_CHECKING, Any
18
19
 
19
20
  from apcore_toolkit.openapi import extract_input_schema, extract_output_schema
@@ -26,6 +27,53 @@ if TYPE_CHECKING:
26
27
  logger = logging.getLogger("fastapi_apcore")
27
28
 
28
29
 
30
+ def apply_effective_proxy_inputs(modules: list[ScannedModule], spec: dict[str, Any]) -> list[ScannedModule]:
31
+ """Attach toolkit 0.15.0 effective-parameter metadata for HTTP proxying.
32
+
33
+ Scans the same OpenAPI document through
34
+ :meth:`apcore_toolkit.OpenAPIScanner.scan_with_effective_parameters` and
35
+ copies each matching operation's ``input_schema`` and
36
+ ``metadata["openapi"]`` (including ``proxy_inputs``) onto the adapter's
37
+ scanned module. Matching uses the module's HTTP method and URL path, so
38
+ adapter-specific module IDs, targets and display metadata are preserved.
39
+
40
+ Only the proxy path uses this: it makes path-item inherited parameters
41
+ visible to the CLI and lets
42
+ :func:`apcore_toolkit.validate_effective_proxy_modules` detect operations
43
+ that cannot be forwarded losslessly.
44
+ """
45
+ from apcore_toolkit import OpenAPIScanner
46
+
47
+ effective: dict[tuple[str, str], Any] = {}
48
+ for candidate in OpenAPIScanner().scan_with_effective_parameters(spec):
49
+ metadata = candidate.metadata or {}
50
+ method = str(metadata.get("http_method", "")).upper()
51
+ path = str(metadata.get("url_path", ""))
52
+ effective[(method, path)] = candidate
53
+
54
+ enriched: list[ScannedModule] = []
55
+ for module in modules:
56
+ metadata = dict(module.metadata or {})
57
+ method = str(getattr(module, "http_method", "") or metadata.get("http_method", "")).upper()
58
+ path = str(getattr(module, "url_path", "") or metadata.get("url_path", ""))
59
+ candidate = effective.get((method, path))
60
+ if candidate is None:
61
+ enriched.append(module)
62
+ continue
63
+
64
+ openapi_meta = dict(metadata.get("openapi") or {})
65
+ openapi_meta.update(candidate.metadata.get("openapi") or {})
66
+ metadata["openapi"] = openapi_meta
67
+ enriched.append(
68
+ replace(
69
+ module,
70
+ input_schema=candidate.input_schema,
71
+ metadata=metadata,
72
+ )
73
+ )
74
+ return enriched
75
+
76
+
29
77
  class OpenAPIScanner(BaseScanner):
30
78
  """Scans FastAPI routes via the auto-generated OpenAPI schema.
31
79
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-apcore
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: FastAPI integration for apcore AI-Perceivable Core — exposes FastAPI routes as apcore modules with auto-discovery, schema extraction from Pydantic models, and OpenAPI-based scanning.
5
5
  Author-email: aiperceivable <team@aiperceivable.com>
6
6
  License-Expression: Apache-2.0
@@ -10,17 +10,17 @@ Keywords: fastapi,apcore,mcp,llm,ai,tools,pydantic,schema,module,cli,auto-discov
10
10
  Requires-Python: >=3.11
11
11
  Description-Content-Type: text/markdown
12
12
  Requires-Dist: fastapi>=0.100
13
- Requires-Dist: apcore>=0.32.2
14
- Requires-Dist: apcore-toolkit>=0.14.1
13
+ Requires-Dist: apcore>=0.33.0
14
+ Requires-Dist: apcore-toolkit>=0.15.0
15
15
  Provides-Extra: mcp
16
- Requires-Dist: apcore-mcp>=0.23.3; extra == "mcp"
16
+ Requires-Dist: apcore-mcp>=0.23.4; extra == "mcp"
17
17
  Provides-Extra: cli
18
- Requires-Dist: apcore-cli>=0.12.6; extra == "cli"
18
+ Requires-Dist: apcore-cli>=0.14.1; extra == "cli"
19
19
  Requires-Dist: click>=8.0; extra == "cli"
20
20
  Provides-Extra: all
21
21
  Requires-Dist: fastapi-apcore[cli,mcp]; extra == "all"
22
22
  Provides-Extra: dev
23
- Requires-Dist: apdev[dev]>=0.2.3; extra == "dev"
23
+ Requires-Dist: apdev[dev]>=0.2.7; extra == "dev"
24
24
  Requires-Dist: pytest>=7.0; extra == "dev"
25
25
  Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
26
26
  Requires-Dist: httpx>=0.24; extra == "dev"
@@ -59,10 +59,10 @@ FastAPI integration for [apcore](https://github.com/aiperceivable/apcore-python)
59
59
 
60
60
  - Python >= 3.11
61
61
  - FastAPI >= 0.100
62
- - apcore >= 0.32.2
63
- - apcore-toolkit >= 0.14.1
64
- - apcore-mcp >= 0.23.3 (optional, `[mcp]` extra)
65
- - apcore-cli >= 0.12.6 (optional, `[cli]` extra)
62
+ - apcore >= 0.33.0
63
+ - apcore-toolkit >= 0.15.0
64
+ - apcore-mcp >= 0.23.4 (optional, `[mcp]` extra)
65
+ - apcore-cli >= 0.14.1 (optional, `[cli]` extra)
66
66
 
67
67
  ## Installation
68
68
 
@@ -333,6 +333,8 @@ if __name__ == "__main__":
333
333
 
334
334
  Each scanned route becomes a CLI command named after `display.cli.alias` from the binding overlay (or the module_id if no overlay is set). The commands forward HTTP requests to the running API using `HTTPProxyRegistryWriter`. Built-in subcommands include `list`, `describe`, `completion`, and `man`.
335
335
 
336
+ `create_cli()` runs a proxy preflight by default (`validate_proxy=True`). It resolves inherited and referenced OpenAPI parameters through apcore-toolkit's effective-parameter scanner, then refuses to register any operation the HTTP proxy cannot forward losslessly — for example a query parameter on a JSON-body `POST`, a body on a query-method route, or conflicting path/query/body names. The error names every offending module. Pass `validate_proxy=False` to keep the legacy best-effort behaviour. Native scanning (`scan_source="native"`) skips this check because it has no OpenAPI document to resolve against.
337
+
336
338
  `commands_dir` points to a directory of plain Python function files. When set, `ConventionScanner` from `apcore-toolkit` scans for public functions and registers them as additional modules alongside the scanned API routes (§5.14).
337
339
 
338
340
  ### Display Overlay (`binding_path`)
@@ -35,6 +35,7 @@ tests/test_extensions.py
35
35
  tests/test_governance.py
36
36
  tests/test_integration.py
37
37
  tests/test_observability.py
38
+ tests/test_proxy_preflight.py
38
39
  tests/test_public_api.py
39
40
  tests/test_registry.py
40
41
  tests/test_scanner.py
@@ -1,16 +1,16 @@
1
1
  fastapi>=0.100
2
- apcore>=0.32.2
3
- apcore-toolkit>=0.14.1
2
+ apcore>=0.33.0
3
+ apcore-toolkit>=0.15.0
4
4
 
5
5
  [all]
6
6
  fastapi-apcore[cli,mcp]
7
7
 
8
8
  [cli]
9
- apcore-cli>=0.12.6
9
+ apcore-cli>=0.14.1
10
10
  click>=8.0
11
11
 
12
12
  [dev]
13
- apdev[dev]>=0.2.3
13
+ apdev[dev]>=0.2.7
14
14
  pytest>=7.0
15
15
  pytest-asyncio>=0.21
16
16
  httpx>=0.24
@@ -19,4 +19,4 @@ mypy>=1.0
19
19
  coverage>=7.0
20
20
 
21
21
  [mcp]
22
- apcore-mcp>=0.23.3
22
+ apcore-mcp>=0.23.4
@@ -176,3 +176,49 @@ class TestImportAndInstantiate:
176
176
  def test_import_and_instantiate_bad_class(self):
177
177
  result = _import_and_instantiate("collections.NoSuchClass")
178
178
  assert result is None
179
+
180
+
181
+ # ---------------------------------------------------------------------------
182
+ # FastAPIDiscoverer._adapt_module — rebuild fidelity
183
+ # ---------------------------------------------------------------------------
184
+
185
+
186
+ class TestAdaptModuleResources:
187
+ """Rebuilding a flattened module must keep its metadata and resources."""
188
+
189
+ def test_resources_survive_pydantic_flattening(self):
190
+ from apcore import FunctionModule, ModuleExample
191
+ from pydantic import BaseModel
192
+
193
+ class Filters(BaseModel):
194
+ q: str = ""
195
+
196
+ def search(filters) -> str:
197
+ return filters.q
198
+
199
+ # Set the annotation to the class object so ``typing.get_type_hints``
200
+ # can resolve it despite the nested definition.
201
+ search.__annotations__["filters"] = Filters
202
+
203
+ fm = FunctionModule(
204
+ func=search,
205
+ module_id="test.search",
206
+ description="Search",
207
+ documentation="Search docs",
208
+ tags=["search"],
209
+ annotations={"requires_approval": True},
210
+ metadata={"source": "binding"},
211
+ display={"alias": "search"},
212
+ examples=[ModuleExample(title="demo", inputs={"q": "x"})],
213
+ resources={"timeout": 1500},
214
+ )
215
+ adapted = FastAPIDiscoverer._adapt_module(fm, FunctionModule)
216
+
217
+ assert adapted is not fm
218
+ assert adapted.resources == {"timeout": 1500}
219
+ assert adapted.documentation == "Search docs"
220
+ assert adapted.annotations is not None
221
+ assert adapted.annotations.requires_approval is True
222
+ assert adapted.metadata == {"source": "binding"}
223
+ assert adapted.display == {"alias": "search"}
224
+ assert adapted.examples == [ModuleExample(title="demo", inputs={"q": "x"})]
@@ -0,0 +1,118 @@
1
+ """Tests for create_cli() HTTP proxy preflight (apcore-toolkit 0.15.0)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+ from apcore_toolkit import validate_effective_proxy_modules
7
+ from pydantic import BaseModel
8
+
9
+ from fastapi_apcore import FastAPIApcore
10
+ from fastapi_apcore.scanners.base import ScannedModule
11
+ from fastapi_apcore.scanners.openapi import apply_effective_proxy_inputs
12
+
13
+
14
+ class _Item(BaseModel):
15
+ name: str
16
+
17
+
18
+ def _spec_with_path_item_parameters() -> dict:
19
+ return {
20
+ "openapi": "3.0.0",
21
+ "info": {"title": "Test", "version": "1.0.0"},
22
+ "paths": {
23
+ "/items/{item_id}": {
24
+ "parameters": [
25
+ {
26
+ "name": "item_id",
27
+ "in": "path",
28
+ "required": True,
29
+ "schema": {"type": "string"},
30
+ }
31
+ ],
32
+ "get": {
33
+ "operationId": "get_item",
34
+ "parameters": [
35
+ {
36
+ "name": "expand",
37
+ "in": "query",
38
+ "schema": {"type": "boolean"},
39
+ }
40
+ ],
41
+ "responses": {"200": {"description": "ok"}},
42
+ },
43
+ }
44
+ },
45
+ }
46
+
47
+
48
+ def _module(method: str = "GET", path: str = "/items/{item_id}") -> ScannedModule:
49
+ return ScannedModule(
50
+ module_id="items.get_item.get",
51
+ description="Get an item",
52
+ input_schema={"type": "object", "properties": {}, "required": []},
53
+ output_schema={"type": "object", "properties": {}},
54
+ tags=["items"],
55
+ target="tests:get_item",
56
+ http_method=method,
57
+ url_path=path,
58
+ metadata={"source": "openapi"},
59
+ )
60
+
61
+
62
+ class TestApplyEffectiveProxyInputs:
63
+ """The sidecar effective scan enriches only the proxy-facing fields."""
64
+
65
+ def test_inherits_path_item_parameters(self):
66
+ [module] = apply_effective_proxy_inputs([_module()], _spec_with_path_item_parameters())
67
+
68
+ assert set(module.input_schema["properties"]) == {"item_id", "expand"}
69
+ openapi_meta = module.metadata["openapi"]
70
+ assert openapi_meta["proxy_inputs"]["path"] == ["item_id"]
71
+ assert openapi_meta["proxy_inputs"]["query"] == ["expand"]
72
+ # Adapter-owned fields are preserved.
73
+ assert module.module_id == "items.get_item.get"
74
+ assert module.target == "tests:get_item"
75
+ assert module.metadata["source"] == "openapi"
76
+
77
+ def test_enriched_module_passes_preflight(self):
78
+ [module] = apply_effective_proxy_inputs([_module()], _spec_with_path_item_parameters())
79
+
80
+ validate_effective_proxy_modules([module])
81
+
82
+
83
+ class TestCreateCliProxyPreflight:
84
+ """create_cli() refuses operations the HTTP proxy cannot forward."""
85
+
86
+ def test_rejects_query_parameter_on_json_body_method(self):
87
+ from fastapi import FastAPI
88
+
89
+ app = FastAPI()
90
+
91
+ @app.post("/items")
92
+ def create_item(item: _Item, dry_run: bool = False) -> dict:
93
+ return {"name": item.name, "dry_run": dry_run}
94
+
95
+ client = FastAPIApcore()
96
+ with pytest.raises(ValueError, match="proxy preflight failed"):
97
+ client.create_cli(app, prog_name="test-cli", base_url="http://localhost:8000")
98
+
99
+ def test_validate_proxy_false_keeps_legacy_behaviour(self):
100
+ from fastapi import FastAPI
101
+
102
+ app = FastAPI()
103
+
104
+ @app.post("/items")
105
+ def create_item(item: _Item, dry_run: bool = False) -> dict:
106
+ return {"name": item.name, "dry_run": dry_run}
107
+
108
+ client = FastAPIApcore()
109
+ cli = client.create_cli(
110
+ app,
111
+ prog_name="test-cli",
112
+ base_url="http://localhost:8000",
113
+ validate_proxy=False,
114
+ )
115
+
116
+ import click
117
+
118
+ assert isinstance(cli, click.Group)
File without changes