xtr-http-kernel 7.4.0__tar.gz → 7.5.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.
- xtr_http_kernel-7.4.0/README.md → xtr_http_kernel-7.5.0/PKG-INFO +47 -3
- xtr_http_kernel-7.4.0/PKG-INFO → xtr_http_kernel-7.5.0/README.md +17 -31
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/pyproject.toml +19 -14
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/pyproject.toml.orig +21 -14
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/SKILL.md +3 -1
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/__init__.py +2 -1
- xtr_http_kernel-7.5.0/src/xtr_http_kernel/command/_open_api_document.py +171 -0
- xtr_http_kernel-7.5.0/src/xtr_http_kernel/command/open_api_export_command.py +129 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/LICENSE +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/configure.md +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/listeners.md +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/rate-limits.md +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/.agents/skills/xtr-http-kernel/references/routing.md +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/_detached.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/_kernel_middleware.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/_route_contexts.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/_staging.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/_state.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/_headers.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/_media_types.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/_scope_uri.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/_server_params.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/http_message_factory.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/http_message_factory_interface.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/response.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/response_factory.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/served_connection.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/starlette_http_factory.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/starlette_http_factory_interface.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/_messages.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/_profiler.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/_profiler_logging.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/http_kernel_bundle.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/http_kernel_config.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/profiler_config.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/profiler_pass.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/profiling_active.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/request_lifecycle_middleware_factory.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/route_recording_middleware_factory.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/route_registry_pass.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/debug_router_command.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/route_description.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/router_command.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/router_match_command.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/_masking.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/ajax_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/clone_var.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/config_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/data_collector_interface.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/data_collector_tag.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/data_collector_templates.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/event_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/exception_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/late_data_collector_interface.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/logger_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/memory_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/profiled_request.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/request_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/request_trace.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/router_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/time_data_collector.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/tracing_data_collector_interface.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/exception_event.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/finish_request_event.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/request_event.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/response_event.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/terminate_event.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/disallow_robots_indexing_listener.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/error_logging_listener.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/profiler_listener.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/rate_limit_headers_listener.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/request_id_listener.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/http_kernel_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_argument_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_collector_priority_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_collector_tag_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_cookie_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_middleware_priority_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_rate_limit_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_token_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/ranged_response_body_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/response_already_a_message_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/streamed_response_body_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/too_many_requests_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/unknown_collector_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/unknown_rate_limiter_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/unsupported_connection_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/kernel_events.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/middleware_stack.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/middleware_tag.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/_state_keys.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/file_profiler_storage.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/profile.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/profile_summary.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/profiler.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/profiler_storage_interface.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/route_recording_middleware.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/py.typed +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/rate_limiter/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/rate_limiter/_applied_rate_limit.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/rate_limiter/rate_limited.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/recipe/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/recipe/files/config/http_kernel.py.tmpl +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/recipe/manifest.toml +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/request_lifecycle_middleware.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/decorator/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/decorator/as_route_resource.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/decorator/as_routes.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/exception/__init__.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/exception/invalid_argument_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/exception/route_conflict_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/exception/routing_error.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/route_registry.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/setup.py +0 -0
- {xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/testing.py +0 -0
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xtr-http-kernel
|
|
3
|
+
Version: 7.5.0
|
|
4
|
+
Summary: Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel.
|
|
5
|
+
Keywords: http,kernel,request,lifecycle,events,middleware,fastapi
|
|
6
|
+
Author: Xterr
|
|
7
|
+
Author-email: Xterr <me@xterr.dev>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Dist: fastapi>=0.143.1
|
|
15
|
+
Requires-Dist: starlette>=1.6
|
|
16
|
+
Requires-Dist: xtr-clock>=7.5,<8
|
|
17
|
+
Requires-Dist: xtr-dependency-injection>=7.5,<8
|
|
18
|
+
Requires-Dist: xtr-event-dispatcher>=7.5,<8
|
|
19
|
+
Requires-Dist: xtr-event-dispatcher-contracts>=7.5,<8
|
|
20
|
+
Requires-Dist: xtr-http-message>=7.5,<8
|
|
21
|
+
Requires-Dist: xtr-http-message-contracts>=7.5,<8
|
|
22
|
+
Requires-Dist: xtr-logging-contracts>=7.5,<8
|
|
23
|
+
Requires-Dist: xtr-service-contracts>=7.5,<8
|
|
24
|
+
Requires-Dist: xtr-stopwatch>=7.5,<8
|
|
25
|
+
Requires-Dist: python-multipart>=0.0.21
|
|
26
|
+
Requires-Dist: pyyaml>=6.0.3 ; extra == 'yaml'
|
|
27
|
+
Requires-Python: >=3.14.4
|
|
28
|
+
Provides-Extra: yaml
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
1
31
|
<div align="center">
|
|
2
32
|
|
|
3
33
|
# xtr-http-kernel
|
|
@@ -41,6 +71,7 @@ Listeners are services, so they come from the container with everything else the
|
|
|
41
71
|
uv add xtr-http-kernel # the lifecycle, its bundle and setup
|
|
42
72
|
uv add xtr-logging # beside it: the listeners that log
|
|
43
73
|
uv add xtr-console # beside it: the commands that report on the router
|
|
74
|
+
uv add "xtr-http-kernel[yaml]" # api:openapi:export --yaml: the description as YAML
|
|
44
75
|
uv add xtr-rate-limiter # beside it: rate limits on routes, routers and the app
|
|
45
76
|
```
|
|
46
77
|
|
|
@@ -629,6 +660,7 @@ removing it undoes.
|
|
|
629
660
|
- **Install** — `uv add xtr-http-kernel`; install [xtr-logging](../xtr-logging) beside it for
|
|
630
661
|
the listeners that write to a log, [xtr-console](../xtr-console) for the commands that report
|
|
631
662
|
on the router, [xtr-rate-limiter](../xtr-rate-limiter) for the [rate limits](#rate-limits).
|
|
663
|
+
`uv add "xtr-http-kernel[yaml]"` lets `api:openapi:export --yaml` write YAML.
|
|
632
664
|
None is needed to serve requests. The
|
|
633
665
|
[HTTP message contract](../xtr-http-message-contracts) and
|
|
634
666
|
[its implementation](../xtr-http-message) come with the package: the
|
|
@@ -880,7 +912,7 @@ request could ever reach.
|
|
|
880
912
|
|
|
881
913
|
## Router commands
|
|
882
914
|
|
|
883
|
-
With a console bundle active,
|
|
915
|
+
With a console bundle active, three commands read the application without serving it — every
|
|
884
916
|
route included, since `setup` added the contributed ones when the application was imported:
|
|
885
917
|
|
|
886
918
|
- **`debug:router`** lists every route in the order routing tries them, prefixes and mounts
|
|
@@ -888,8 +920,20 @@ route included, since `setup` added the contributed ones when the application wa
|
|
|
888
920
|
- **`router:match PATH [--method GET]`** names the route a path reaches, reports a route that
|
|
889
921
|
matches the path but refuses the method as the near miss it is, and fails on a path no route
|
|
890
922
|
answers.
|
|
923
|
+
- **`api:openapi:export`** writes the application's OpenAPI description — the one it serves —
|
|
924
|
+
as JSON on standard output, so it pipes and redirects cleanly:
|
|
925
|
+
|
|
926
|
+
| Option | |
|
|
927
|
+
|---|---|
|
|
928
|
+
| `-y`, `--yaml` | YAML instead of JSON; needs PyYAML, which the `yaml` extra installs — without it the command says so and fails |
|
|
929
|
+
| `-o`, `--output PATH` | write to the file rather than to standard output |
|
|
930
|
+
| `--spec-version 3` | the OpenAPI version; the application describes itself in 3, and `2` is refused |
|
|
931
|
+
| `--api-gateway` | what an Amazon API Gateway import accepts: every schema renamed to its letters and digits, references following; parameters named with anything but letters, digits and `._$-` dropped; `readOnly` taken off properties |
|
|
932
|
+
| `--filter-tags TAG` | only the operations carrying the tag, repeatable; a path left with none goes, and so does the description of every other tag |
|
|
933
|
+
|
|
934
|
+
Applications mounted under the application are not in it: FastAPI leaves them out.
|
|
891
935
|
|
|
892
|
-
|
|
936
|
+
Each takes the application from `--app "package.module:app"`, or from `HttpKernelConfig.app`
|
|
893
937
|
when the option is left out, and read it either side of FastAPI's move to lazily included
|
|
894
938
|
routers.
|
|
895
939
|
|
|
@@ -985,7 +1029,7 @@ xtr_http_kernel/
|
|
|
985
1029
|
├── profiler/ Profiler, Profile, FileProfilerStorage
|
|
986
1030
|
├── data_collector/ the collector contracts, clone_var and the core collectors
|
|
987
1031
|
├── routing/ as_route_resource, as_routes, the registry setup stages from
|
|
988
|
-
├── command/ debug:router and
|
|
1032
|
+
├── command/ debug:router, router:match and api:openapi:export
|
|
989
1033
|
├── exception/ HttpKernelError, the root of everything this library raises
|
|
990
1034
|
└── bundle/ HttpKernelBundle and HttpKernelConfig
|
|
991
1035
|
```
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: xtr-http-kernel
|
|
3
|
-
Version: 7.4.0
|
|
4
|
-
Summary: Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel.
|
|
5
|
-
Keywords: http,kernel,request,lifecycle,events,middleware,fastapi
|
|
6
|
-
Author: Xterr
|
|
7
|
-
Author-email: Xterr <me@xterr.dev>
|
|
8
|
-
License-Expression: MIT
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Classifier: Development Status :: 3 - Alpha
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
-
Classifier: Typing :: Typed
|
|
14
|
-
Requires-Dist: fastapi>=0.143.1
|
|
15
|
-
Requires-Dist: starlette>=1.6
|
|
16
|
-
Requires-Dist: xtr-clock>=7.4,<8
|
|
17
|
-
Requires-Dist: xtr-dependency-injection>=7.4,<8
|
|
18
|
-
Requires-Dist: xtr-event-dispatcher>=7.4,<8
|
|
19
|
-
Requires-Dist: xtr-event-dispatcher-contracts>=7.4,<8
|
|
20
|
-
Requires-Dist: xtr-http-message>=7.4,<8
|
|
21
|
-
Requires-Dist: xtr-http-message-contracts>=7.4,<8
|
|
22
|
-
Requires-Dist: xtr-logging-contracts>=7.4,<8
|
|
23
|
-
Requires-Dist: xtr-service-contracts>=7.4,<8
|
|
24
|
-
Requires-Dist: xtr-stopwatch>=7.4,<8
|
|
25
|
-
Requires-Dist: python-multipart>=0.0.21
|
|
26
|
-
Requires-Python: >=3.14.4
|
|
27
|
-
Description-Content-Type: text/markdown
|
|
28
|
-
|
|
29
1
|
<div align="center">
|
|
30
2
|
|
|
31
3
|
# xtr-http-kernel
|
|
@@ -69,6 +41,7 @@ Listeners are services, so they come from the container with everything else the
|
|
|
69
41
|
uv add xtr-http-kernel # the lifecycle, its bundle and setup
|
|
70
42
|
uv add xtr-logging # beside it: the listeners that log
|
|
71
43
|
uv add xtr-console # beside it: the commands that report on the router
|
|
44
|
+
uv add "xtr-http-kernel[yaml]" # api:openapi:export --yaml: the description as YAML
|
|
72
45
|
uv add xtr-rate-limiter # beside it: rate limits on routes, routers and the app
|
|
73
46
|
```
|
|
74
47
|
|
|
@@ -657,6 +630,7 @@ removing it undoes.
|
|
|
657
630
|
- **Install** — `uv add xtr-http-kernel`; install [xtr-logging](../xtr-logging) beside it for
|
|
658
631
|
the listeners that write to a log, [xtr-console](../xtr-console) for the commands that report
|
|
659
632
|
on the router, [xtr-rate-limiter](../xtr-rate-limiter) for the [rate limits](#rate-limits).
|
|
633
|
+
`uv add "xtr-http-kernel[yaml]"` lets `api:openapi:export --yaml` write YAML.
|
|
660
634
|
None is needed to serve requests. The
|
|
661
635
|
[HTTP message contract](../xtr-http-message-contracts) and
|
|
662
636
|
[its implementation](../xtr-http-message) come with the package: the
|
|
@@ -908,7 +882,7 @@ request could ever reach.
|
|
|
908
882
|
|
|
909
883
|
## Router commands
|
|
910
884
|
|
|
911
|
-
With a console bundle active,
|
|
885
|
+
With a console bundle active, three commands read the application without serving it — every
|
|
912
886
|
route included, since `setup` added the contributed ones when the application was imported:
|
|
913
887
|
|
|
914
888
|
- **`debug:router`** lists every route in the order routing tries them, prefixes and mounts
|
|
@@ -916,8 +890,20 @@ route included, since `setup` added the contributed ones when the application wa
|
|
|
916
890
|
- **`router:match PATH [--method GET]`** names the route a path reaches, reports a route that
|
|
917
891
|
matches the path but refuses the method as the near miss it is, and fails on a path no route
|
|
918
892
|
answers.
|
|
893
|
+
- **`api:openapi:export`** writes the application's OpenAPI description — the one it serves —
|
|
894
|
+
as JSON on standard output, so it pipes and redirects cleanly:
|
|
895
|
+
|
|
896
|
+
| Option | |
|
|
897
|
+
|---|---|
|
|
898
|
+
| `-y`, `--yaml` | YAML instead of JSON; needs PyYAML, which the `yaml` extra installs — without it the command says so and fails |
|
|
899
|
+
| `-o`, `--output PATH` | write to the file rather than to standard output |
|
|
900
|
+
| `--spec-version 3` | the OpenAPI version; the application describes itself in 3, and `2` is refused |
|
|
901
|
+
| `--api-gateway` | what an Amazon API Gateway import accepts: every schema renamed to its letters and digits, references following; parameters named with anything but letters, digits and `._$-` dropped; `readOnly` taken off properties |
|
|
902
|
+
| `--filter-tags TAG` | only the operations carrying the tag, repeatable; a path left with none goes, and so does the description of every other tag |
|
|
903
|
+
|
|
904
|
+
Applications mounted under the application are not in it: FastAPI leaves them out.
|
|
919
905
|
|
|
920
|
-
|
|
906
|
+
Each takes the application from `--app "package.module:app"`, or from `HttpKernelConfig.app`
|
|
921
907
|
when the option is left out, and read it either side of FastAPI's move to lazily included
|
|
922
908
|
routers.
|
|
923
909
|
|
|
@@ -1013,7 +999,7 @@ xtr_http_kernel/
|
|
|
1013
999
|
├── profiler/ Profiler, Profile, FileProfilerStorage
|
|
1014
1000
|
├── data_collector/ the collector contracts, clone_var and the core collectors
|
|
1015
1001
|
├── routing/ as_route_resource, as_routes, the registry setup stages from
|
|
1016
|
-
├── command/ debug:router and
|
|
1002
|
+
├── command/ debug:router, router:match and api:openapi:export
|
|
1017
1003
|
├── exception/ HttpKernelError, the root of everything this library raises
|
|
1018
1004
|
└── bundle/ HttpKernelBundle and HttpKernelConfig
|
|
1019
1005
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "xtr-http-kernel"
|
|
3
|
-
version = "7.
|
|
3
|
+
version = "7.5.0"
|
|
4
4
|
description = "Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.14.4"
|
|
@@ -24,15 +24,15 @@ classifiers = [
|
|
|
24
24
|
dependencies = [
|
|
25
25
|
"fastapi>=0.143.1",
|
|
26
26
|
"starlette>=1.6",
|
|
27
|
-
"xtr-clock>=7.
|
|
28
|
-
"xtr-dependency-injection>=7.
|
|
29
|
-
"xtr-event-dispatcher>=7.
|
|
30
|
-
"xtr-event-dispatcher-contracts>=7.
|
|
31
|
-
"xtr-http-message>=7.
|
|
32
|
-
"xtr-http-message-contracts>=7.
|
|
33
|
-
"xtr-logging-contracts>=7.
|
|
34
|
-
"xtr-service-contracts>=7.
|
|
35
|
-
"xtr-stopwatch>=7.
|
|
27
|
+
"xtr-clock>=7.5,<8",
|
|
28
|
+
"xtr-dependency-injection>=7.5,<8",
|
|
29
|
+
"xtr-event-dispatcher>=7.5,<8",
|
|
30
|
+
"xtr-event-dispatcher-contracts>=7.5,<8",
|
|
31
|
+
"xtr-http-message>=7.5,<8",
|
|
32
|
+
"xtr-http-message-contracts>=7.5,<8",
|
|
33
|
+
"xtr-logging-contracts>=7.5,<8",
|
|
34
|
+
"xtr-service-contracts>=7.5,<8",
|
|
35
|
+
"xtr-stopwatch>=7.5,<8",
|
|
36
36
|
"python-multipart>=0.0.21",
|
|
37
37
|
]
|
|
38
38
|
|
|
@@ -40,6 +40,9 @@ dependencies = [
|
|
|
40
40
|
name = "Xterr"
|
|
41
41
|
email = "me@xterr.dev"
|
|
42
42
|
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
yaml = ["pyyaml>=6.0.3"]
|
|
45
|
+
|
|
43
46
|
[project.entry-points."xtr_dependency_injection.bundles"]
|
|
44
47
|
http_kernel = "xtr_http_kernel.bundle:HttpKernelBundle"
|
|
45
48
|
|
|
@@ -54,11 +57,13 @@ dev = [
|
|
|
54
57
|
"pytest-cov>=7.1",
|
|
55
58
|
"anyio>=4.10",
|
|
56
59
|
"ty>=0.0.83",
|
|
57
|
-
"xtr-logging>=7.
|
|
58
|
-
"xtr-console>=7.
|
|
59
|
-
"xtr-clock>=7.
|
|
60
|
-
"xtr-rate-limiter>=7.
|
|
60
|
+
"xtr-logging>=7.5,<8",
|
|
61
|
+
"xtr-console>=7.5,<8",
|
|
62
|
+
"xtr-clock>=7.5,<8",
|
|
63
|
+
"xtr-rate-limiter>=7.5,<8",
|
|
61
64
|
"httpx>=0.27",
|
|
65
|
+
"pyyaml>=6.0.3",
|
|
66
|
+
"types-pyyaml>=6.0.12",
|
|
62
67
|
]
|
|
63
68
|
|
|
64
69
|
[build-system]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "xtr-http-kernel"
|
|
3
|
-
version = "7.
|
|
3
|
+
version = "7.5.0"
|
|
4
4
|
description = "Requests turned into responses through events: a request lifecycle for FastAPI applications on the xtr kernel."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.14.4"
|
|
@@ -30,19 +30,19 @@ dependencies = [
|
|
|
30
30
|
# the limits of a urlencoded form, which every request read as a message
|
|
31
31
|
# goes through (GHSA-82w8-qh3p-5jfq).
|
|
32
32
|
"starlette>=1.6",
|
|
33
|
-
"xtr-clock>=7.
|
|
34
|
-
"xtr-dependency-injection>=7.
|
|
35
|
-
"xtr-event-dispatcher>=7.
|
|
36
|
-
"xtr-event-dispatcher-contracts>=7.
|
|
33
|
+
"xtr-clock>=7.5,<8",
|
|
34
|
+
"xtr-dependency-injection>=7.5,<8",
|
|
35
|
+
"xtr-event-dispatcher>=7.5,<8",
|
|
36
|
+
"xtr-event-dispatcher-contracts>=7.5,<8",
|
|
37
37
|
# The bridge builds messages and is the one place a message meets a route,
|
|
38
38
|
# so both the contract and the implementation of it are required: the
|
|
39
39
|
# bundle registers the implementation's factories under the contract.
|
|
40
|
-
"xtr-http-message>=7.
|
|
41
|
-
"xtr-http-message-contracts>=7.
|
|
42
|
-
"xtr-logging-contracts>=7.
|
|
43
|
-
"xtr-service-contracts>=7.
|
|
40
|
+
"xtr-http-message>=7.5,<8",
|
|
41
|
+
"xtr-http-message-contracts>=7.5,<8",
|
|
42
|
+
"xtr-logging-contracts>=7.5,<8",
|
|
43
|
+
"xtr-service-contracts>=7.5,<8",
|
|
44
44
|
# The profiler times each request on it, and the time panel reads it.
|
|
45
|
-
"xtr-stopwatch>=7.
|
|
45
|
+
"xtr-stopwatch>=7.5,<8",
|
|
46
46
|
# A submitted form with files in it: the bridge asks the web framework for
|
|
47
47
|
# the form behind every multipart body, and the framework refuses outright
|
|
48
48
|
# when the parser it reads one with is missing. So a route that takes the
|
|
@@ -50,6 +50,10 @@ dependencies = [
|
|
|
50
50
|
"python-multipart>=0.0.21",
|
|
51
51
|
]
|
|
52
52
|
|
|
53
|
+
[project.optional-dependencies]
|
|
54
|
+
# api:openapi:export --yaml writes the description with it; JSON needs nothing.
|
|
55
|
+
yaml = ["pyyaml>=6.0.3"]
|
|
56
|
+
|
|
53
57
|
# Advertises the bundle so debug:bundles can name it when installed but not listed.
|
|
54
58
|
# Advertising activates nothing: an application lists the bundles it wants.
|
|
55
59
|
[project.entry-points."xtr_dependency_injection.bundles"]
|
|
@@ -67,13 +71,16 @@ dev = [
|
|
|
67
71
|
"pytest-cov>=7.1",
|
|
68
72
|
"anyio>=4.10",
|
|
69
73
|
"ty>=0.0.83",
|
|
70
|
-
"xtr-logging>=7.
|
|
71
|
-
"xtr-console>=7.
|
|
72
|
-
"xtr-clock>=7.
|
|
73
|
-
"xtr-rate-limiter>=7.
|
|
74
|
+
"xtr-logging>=7.5,<8",
|
|
75
|
+
"xtr-console>=7.5,<8",
|
|
76
|
+
"xtr-clock>=7.5,<8",
|
|
77
|
+
"xtr-rate-limiter>=7.5,<8",
|
|
74
78
|
# Requests are driven straight at the application through an ASGI
|
|
75
79
|
# transport, so the suite never binds a socket.
|
|
76
80
|
"httpx>=0.27",
|
|
81
|
+
# api:openapi:export --yaml, and the types its use is checked against.
|
|
82
|
+
"pyyaml>=6.0.3",
|
|
83
|
+
"types-pyyaml>=6.0.12",
|
|
77
84
|
]
|
|
78
85
|
|
|
79
86
|
[build-system]
|
|
@@ -421,7 +421,9 @@ to make.
|
|
|
421
421
|
6. **Run** any ASGI server against the module `setup` was called in: `uvicorn app.web:app`.
|
|
422
422
|
7. **Check** `debug:bundles` shows `http_kernel` as `listed` and `active`, `event_dispatcher` as
|
|
423
423
|
`required`. With a console bundle, `debug:router` lists the routes in the order routing tries
|
|
424
|
-
them,
|
|
424
|
+
them, `router:match PATH [--method GET]` names the route a path reaches, and
|
|
425
|
+
`api:openapi:export [-y] [-o PATH] [--api-gateway] [--filter-tags TAG]` writes the OpenAPI
|
|
426
|
+
description (`-y` needs the `yaml` extra).
|
|
425
427
|
8. **Remove** drop the `setup(app, kernel)` call, drop the `BUNDLES` entry;
|
|
426
428
|
`uv run xtr-recipes recipes:remove xtr-http-kernel` deletes
|
|
427
429
|
`<app>/config/packages/http_kernel.py`, unless you edited it, in which case it is moved aside
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from .debug_router_command import DebugRouterCommand
|
|
6
|
+
from .open_api_export_command import OpenApiExportCommand
|
|
6
7
|
from .route_description import RouteDescription
|
|
7
8
|
from .router_match_command import RouterMatchCommand
|
|
8
9
|
|
|
9
|
-
__all__ = ["DebugRouterCommand", "RouteDescription", "RouterMatchCommand"]
|
|
10
|
+
__all__ = ["DebugRouterCommand", "OpenApiExportCommand", "RouteDescription", "RouterMatchCommand"]
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Reshaping an OpenAPI description before it is exported: by tag, or for an API gateway.
|
|
2
|
+
|
|
3
|
+
Each function returns a new description and leaves the one it is given as it
|
|
4
|
+
was: the application keeps the description it built, and hands that same
|
|
5
|
+
object to every later caller.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
from typing import TYPE_CHECKING, Final
|
|
12
|
+
|
|
13
|
+
from xtr_http_kernel.exception import InvalidArgumentError
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from collections.abc import Collection, Mapping
|
|
17
|
+
|
|
18
|
+
__all__ = ["JsonValue", "filter_tags", "for_api_gateway"]
|
|
19
|
+
|
|
20
|
+
type JsonValue = dict[str, JsonValue] | list[JsonValue] | str | int | float | bool | None
|
|
21
|
+
"""A value of a JSON document."""
|
|
22
|
+
|
|
23
|
+
_OPERATIONS: Final = frozenset(
|
|
24
|
+
{"get", "put", "post", "delete", "options", "head", "patch", "trace"}
|
|
25
|
+
)
|
|
26
|
+
"""The keys of a path item that hold an operation; the others describe the path."""
|
|
27
|
+
|
|
28
|
+
_GATEWAY_PARAMETER_NAME: Final = re.compile(r"[a-zA-Z0-9._$-]+")
|
|
29
|
+
_NOT_ALPHANUMERIC: Final = re.compile(r"[^0-9A-Za-z]")
|
|
30
|
+
_SCHEMA_REFERENCE: Final = "#/components/schemas/"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def filter_tags(document: dict[str, JsonValue], tags: Collection[str]) -> dict[str, JsonValue]:
|
|
34
|
+
"""Return ``document`` with only the operations carrying one of ``tags``.
|
|
35
|
+
|
|
36
|
+
A path left without an operation goes too, and so does the description
|
|
37
|
+
of every tag not asked for. Schemas only the dropped operations used stay:
|
|
38
|
+
they are harmless, and finding them means following every reference.
|
|
39
|
+
"""
|
|
40
|
+
wanted = frozenset(tags)
|
|
41
|
+
paths: dict[str, JsonValue] = {}
|
|
42
|
+
for path, item in _object(document.get("paths")).items():
|
|
43
|
+
kept = {
|
|
44
|
+
key: value
|
|
45
|
+
for key, value in _object(item).items()
|
|
46
|
+
if key not in _OPERATIONS or not wanted.isdisjoint(_strings(_object(value).get("tags")))
|
|
47
|
+
}
|
|
48
|
+
if not _OPERATIONS.isdisjoint(kept):
|
|
49
|
+
paths[path] = kept
|
|
50
|
+
filtered: dict[str, JsonValue] = {**document, "paths": paths}
|
|
51
|
+
if "tags" in document:
|
|
52
|
+
filtered["tags"] = [
|
|
53
|
+
tag for tag in _array(document["tags"]) if _object(tag).get("name") in wanted
|
|
54
|
+
]
|
|
55
|
+
return filtered
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def for_api_gateway(document: dict[str, JsonValue]) -> dict[str, JsonValue]:
|
|
59
|
+
"""Return ``document`` without what an Amazon API Gateway import refuses.
|
|
60
|
+
|
|
61
|
+
A gateway names a schema with letters and digits alone, so every schema
|
|
62
|
+
is renamed that way, and every reference to it follows. It takes a
|
|
63
|
+
parameter name made of letters, digits and ``._$-`` only, so an operation
|
|
64
|
+
loses any other parameter. It refuses ``readOnly`` on a property, so the
|
|
65
|
+
properties of every schema lose it.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
InvalidArgumentError: If two schemas would take the same name.
|
|
69
|
+
"""
|
|
70
|
+
names = _gateway_names(_object(_object(document.get("components")).get("schemas")))
|
|
71
|
+
gateway = _object_with_references(document, names)
|
|
72
|
+
components = _object(gateway.get("components"))
|
|
73
|
+
if "schemas" in components:
|
|
74
|
+
components["schemas"] = {
|
|
75
|
+
names[name]: _without_read_only(schema)
|
|
76
|
+
for name, schema in _object(components["schemas"]).items()
|
|
77
|
+
}
|
|
78
|
+
for item in _object(gateway.get("paths")).values():
|
|
79
|
+
path_item = _object(item)
|
|
80
|
+
_keep_gateway_parameters(path_item)
|
|
81
|
+
for key, operation in path_item.items():
|
|
82
|
+
if key in _OPERATIONS:
|
|
83
|
+
_keep_gateway_parameters(_object(operation))
|
|
84
|
+
return gateway
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _gateway_names(schemas: Mapping[str, JsonValue]) -> dict[str, str]:
|
|
88
|
+
"""Map each schema name to its letters and digits.
|
|
89
|
+
|
|
90
|
+
Raises:
|
|
91
|
+
InvalidArgumentError: If two names keep the same letters and digits.
|
|
92
|
+
"""
|
|
93
|
+
names: dict[str, str] = {}
|
|
94
|
+
owners: dict[str, str] = {}
|
|
95
|
+
for name in schemas:
|
|
96
|
+
renamed = _NOT_ALPHANUMERIC.sub("", name)
|
|
97
|
+
if renamed in owners:
|
|
98
|
+
reason = (
|
|
99
|
+
f'the schemas "{owners[renamed]}" and "{name}" would both be named "{renamed}" '
|
|
100
|
+
"for an API gateway, which names a schema with letters and digits alone"
|
|
101
|
+
)
|
|
102
|
+
raise InvalidArgumentError(reason)
|
|
103
|
+
owners[renamed] = name
|
|
104
|
+
names[name] = renamed
|
|
105
|
+
return names
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _with_references(value: JsonValue, names: Mapping[str, str]) -> JsonValue:
|
|
109
|
+
"""Return a copy of ``value`` whose schema references use the names in ``names``."""
|
|
110
|
+
if isinstance(value, dict):
|
|
111
|
+
return _object_with_references(value, names)
|
|
112
|
+
if isinstance(value, list):
|
|
113
|
+
return [_with_references(item, names) for item in value]
|
|
114
|
+
return value
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _object_with_references(
|
|
118
|
+
value: dict[str, JsonValue], names: Mapping[str, str]
|
|
119
|
+
) -> dict[str, JsonValue]:
|
|
120
|
+
copied = {key: _with_references(item, names) for key, item in value.items()}
|
|
121
|
+
reference = copied.get("$ref")
|
|
122
|
+
if isinstance(reference, str) and reference.startswith(_SCHEMA_REFERENCE):
|
|
123
|
+
name = reference.removeprefix(_SCHEMA_REFERENCE)
|
|
124
|
+
copied["$ref"] = _SCHEMA_REFERENCE + names.get(name, name)
|
|
125
|
+
return copied
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _without_read_only(schema: JsonValue) -> JsonValue:
|
|
129
|
+
"""Return ``schema`` with ``readOnly`` taken off each of its properties."""
|
|
130
|
+
if not isinstance(schema, dict) or not isinstance(schema.get("properties"), dict):
|
|
131
|
+
return schema
|
|
132
|
+
properties = {
|
|
133
|
+
name: (
|
|
134
|
+
{key: value for key, value in prop.items() if key != "readOnly"}
|
|
135
|
+
if isinstance(prop, dict)
|
|
136
|
+
else prop
|
|
137
|
+
)
|
|
138
|
+
for name, prop in _object(schema["properties"]).items()
|
|
139
|
+
}
|
|
140
|
+
return {**schema, "properties": properties}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _keep_gateway_parameters(holder: dict[str, JsonValue]) -> None:
|
|
144
|
+
"""Drop from ``holder`` the parameters a gateway cannot name; a reference is kept."""
|
|
145
|
+
parameters = holder.get("parameters")
|
|
146
|
+
if not isinstance(parameters, list):
|
|
147
|
+
return
|
|
148
|
+
holder["parameters"] = [
|
|
149
|
+
parameter
|
|
150
|
+
for parameter in parameters
|
|
151
|
+
if isinstance(parameter, dict)
|
|
152
|
+
and (
|
|
153
|
+
"$ref" in parameter
|
|
154
|
+
or _GATEWAY_PARAMETER_NAME.fullmatch(str(parameter.get("name", ""))) is not None
|
|
155
|
+
)
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _object(value: JsonValue) -> dict[str, JsonValue]:
|
|
160
|
+
"""Return ``value`` when it is a JSON object, else an empty one."""
|
|
161
|
+
return value if isinstance(value, dict) else {}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _array(value: JsonValue) -> list[JsonValue]:
|
|
165
|
+
"""Return ``value`` when it is a JSON array, else an empty one."""
|
|
166
|
+
return value if isinstance(value, list) else []
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _strings(value: JsonValue) -> list[str]:
|
|
170
|
+
"""Return the strings of ``value`` when it is a JSON array."""
|
|
171
|
+
return [item for item in _array(value) if isinstance(item, str)]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""``api:openapi:export``: an application's OpenAPI description, as JSON or YAML."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path # noqa: TC003 — read at runtime: the console converts --output from it
|
|
8
|
+
from typing import TYPE_CHECKING, Annotated, Final, Literal, cast, final, override
|
|
9
|
+
|
|
10
|
+
from xtr_console import ConsoleStyle, ExitCode, Option, as_command, escape
|
|
11
|
+
|
|
12
|
+
from xtr_http_kernel.exception import InvalidArgumentError
|
|
13
|
+
|
|
14
|
+
# Imported under another name: the command's own --filter-tags parameter takes this one.
|
|
15
|
+
from ._open_api_document import JsonValue, for_api_gateway
|
|
16
|
+
from ._open_api_document import filter_tags as tagged_only
|
|
17
|
+
from .router_command import RouterCommand
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from collections.abc import Callable
|
|
21
|
+
|
|
22
|
+
__all__ = ["OpenApiExportCommand"]
|
|
23
|
+
|
|
24
|
+
_NO_YAML: Final = (
|
|
25
|
+
"YAML needs the PyYAML package: install it with `uv add pyyaml`, or install this "
|
|
26
|
+
'package with its yaml extra, `uv add "xtr-http-kernel[yaml]"`.'
|
|
27
|
+
)
|
|
28
|
+
_NO_OPENAPI_2: Final = (
|
|
29
|
+
"OpenAPI 2 is not supported: the application describes itself in OpenAPI 3; "
|
|
30
|
+
"leave --spec-version out, or pass 3."
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@as_command("api:openapi:export")
|
|
35
|
+
@final
|
|
36
|
+
class OpenApiExportCommand(RouterCommand):
|
|
37
|
+
"""Exports the OpenAPI description of an application."""
|
|
38
|
+
|
|
39
|
+
__slots__ = ()
|
|
40
|
+
|
|
41
|
+
async def __call__( # noqa: PLR0913, PLR0911 — the command line of the command; one exit per refusal
|
|
42
|
+
self,
|
|
43
|
+
io: ConsoleStyle,
|
|
44
|
+
*,
|
|
45
|
+
app: str | None = None,
|
|
46
|
+
yaml: Annotated[bool, Option(alias="-y")] = False,
|
|
47
|
+
output: Annotated[Path | None, Option(alias="-o")] = None,
|
|
48
|
+
spec_version: Literal["2", "3"] = "3",
|
|
49
|
+
api_gateway: bool = False,
|
|
50
|
+
filter_tags: list[str] | None = None,
|
|
51
|
+
) -> int:
|
|
52
|
+
"""Dump the OpenAPI documentation.
|
|
53
|
+
|
|
54
|
+
The description is the one the application serves, every route its
|
|
55
|
+
routes files include among it; nothing is served to build it.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
io: Where the command writes.
|
|
59
|
+
app: The application to describe, as ``package.module:app``; the
|
|
60
|
+
configured one when left out.
|
|
61
|
+
yaml: Dump the documentation in YAML.
|
|
62
|
+
output: Write output to file.
|
|
63
|
+
spec_version: OpenAPI version to use; only 3 is produced.
|
|
64
|
+
api_gateway: Enable the Amazon API Gateway compatibility mode.
|
|
65
|
+
filter_tags: Keep only the operations tagged with this tag; repeat
|
|
66
|
+
for several.
|
|
67
|
+
"""
|
|
68
|
+
if spec_version == "2":
|
|
69
|
+
io.error(_NO_OPENAPI_2)
|
|
70
|
+
return ExitCode.INVALID
|
|
71
|
+
dump = _yaml_dumper() if yaml else _json
|
|
72
|
+
if dump is None:
|
|
73
|
+
io.warning(escape(_NO_YAML))
|
|
74
|
+
return ExitCode.FAILURE
|
|
75
|
+
application = self._app_or_report(io, app)
|
|
76
|
+
if application is None:
|
|
77
|
+
return ExitCode.INVALID
|
|
78
|
+
# The framework types its description loosely; it is a JSON document.
|
|
79
|
+
document: dict[str, JsonValue] = application.openapi()
|
|
80
|
+
if filter_tags:
|
|
81
|
+
document = tagged_only(document, filter_tags)
|
|
82
|
+
if api_gateway:
|
|
83
|
+
try:
|
|
84
|
+
document = for_api_gateway(document)
|
|
85
|
+
except InvalidArgumentError as error:
|
|
86
|
+
io.error(escape(str(error)))
|
|
87
|
+
return ExitCode.FAILURE
|
|
88
|
+
text = dump(document)
|
|
89
|
+
if output is None:
|
|
90
|
+
# As it is: neither wrapped to the terminal nor read as markup.
|
|
91
|
+
io.console.print(
|
|
92
|
+
text, end="", markup=False, highlight=False, emoji=False, soft_wrap=True
|
|
93
|
+
)
|
|
94
|
+
return ExitCode.SUCCESS
|
|
95
|
+
try:
|
|
96
|
+
_ = await asyncio.to_thread(output.write_text, text, encoding="utf-8")
|
|
97
|
+
except OSError as error:
|
|
98
|
+
io.error(escape(f'Cannot write "{output}": {error.strerror or error}.'))
|
|
99
|
+
return ExitCode.FAILURE
|
|
100
|
+
io.success(escape(f'Data written to "{output}".'))
|
|
101
|
+
return ExitCode.SUCCESS
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _json(document: dict[str, JsonValue]) -> str:
|
|
105
|
+
return json.dumps(document, indent=2, ensure_ascii=False) + "\n"
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _yaml_dumper() -> Callable[[dict[str, JsonValue]], str] | None:
|
|
109
|
+
"""Return what writes a description as YAML, or ``None`` when PyYAML is not installed."""
|
|
110
|
+
try:
|
|
111
|
+
# Optional: installed with the yaml extra.
|
|
112
|
+
import yaml # noqa: PLC0415
|
|
113
|
+
except ImportError:
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
class _Dumper(yaml.SafeDumper):
|
|
117
|
+
"""Writes a value met twice in full, never as an anchor and an alias."""
|
|
118
|
+
|
|
119
|
+
@override
|
|
120
|
+
def ignore_aliases(self, data: object) -> bool:
|
|
121
|
+
return True
|
|
122
|
+
|
|
123
|
+
# The stubs leave the keyword arguments of ``dump`` untyped; these are its own.
|
|
124
|
+
dump_yaml = cast("Callable[..., str]", yaml.dump)
|
|
125
|
+
|
|
126
|
+
def dump(document: dict[str, JsonValue]) -> str:
|
|
127
|
+
return dump_yaml(document, Dumper=_Dumper, sort_keys=False, allow_unicode=True)
|
|
128
|
+
|
|
129
|
+
return dump
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/_server_params.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/http_message_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/response_factory.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/served_connection.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bridge/starlette_http_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/_profiler_logging.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/http_kernel_bundle.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/http_kernel_config.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/profiler_config.py
RENAMED
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/profiling_active.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/bundle/route_registry_pass.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/debug_router_command.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/route_description.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/router_command.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/command/router_match_command.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/__init__.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/_masking.py
RENAMED
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/clone_var.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/data_collector/request_trace.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/exception_event.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/finish_request_event.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event/terminate_event.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/event_listener/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/http_kernel_error.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/exception/invalid_token_error.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/profiler/profile_summary.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/rate_limiter/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/rate_limiter/rate_limited.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/request_lifecycle_middleware.py
RENAMED
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/decorator/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/decorator/as_routes.py
RENAMED
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/exception/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xtr_http_kernel-7.4.0 → xtr_http_kernel-7.5.0}/src/xtr_http_kernel/routing/route_registry.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|