feat(standards): codify codegen, ship generic Tier-B infra, add get_app_template + prompts; fix docs:// regressions
P0: fix doc:// -> docs:// across standards src/server/registry and regenerate stale mongo-ops bundle. P1: build recipe + spec-first routing now document the openapi-first codegen fast path (models/routes with --inject-request/--package). P4: CRUD template documents the model-vs-document id rule (BaseDocument owns id). P5: authless guidance (omit security keys). P6: template gains generic infra (http_cache, keyed SSE bus, KV port+in-memory+Redis), interfaces/openapi.py + .dockerignore + generic build test registered as components, and a get_app_template tool; genericity matrix marks LLM pool + human-in-loop as reference-app patterns. P7: intake/build/start_app/trial prompts. P8: template ships tests/integration/test_openapi_app_builds.py. Rebuilt standards + openapi-first bundles and re-collected.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import importlib
|
||||
|
||||
import yaml
|
||||
|
||||
import interfaces.openapi as routes_module
|
||||
|
||||
from openapi_first.app import OpenAPIFirstApp
|
||||
|
||||
_HTTP_METHODS = {"get", "post", "put", "patch", "delete", "head", "options"}
|
||||
|
||||
|
||||
def _operation_ids(spec: dict) -> list[str]:
|
||||
"""Collect every declared operationId from an OpenAPI spec.
|
||||
|
||||
Args:
|
||||
spec (dict): Parsed OpenAPI document.
|
||||
|
||||
Returns:
|
||||
list[str]: Operation ids in declaration order.
|
||||
"""
|
||||
ids: list[str] = []
|
||||
for path_item in (spec.get("paths") or {}).values():
|
||||
for method, operation in path_item.items():
|
||||
if method.lower() in _HTTP_METHODS and isinstance(operation, dict):
|
||||
if operation.get("operationId"):
|
||||
ids.append(operation["operationId"])
|
||||
return ids
|
||||
|
||||
|
||||
def test_openapi_app_builds():
|
||||
"""Every operationId in the spec must resolve to a handler, and the app must build."""
|
||||
spec = yaml.safe_load(open("openapi.yaml", encoding="utf-8"))
|
||||
module = importlib.import_module(routes_module.__name__)
|
||||
|
||||
missing = [oid for oid in _operation_ids(spec) if not hasattr(module, oid)]
|
||||
assert not missing, f"handlers missing for operationIds: {missing}"
|
||||
|
||||
app = OpenAPIFirstApp(
|
||||
openapi_path="openapi.yaml",
|
||||
routes_module=module,
|
||||
title="App API",
|
||||
version="0.1.0",
|
||||
)
|
||||
assert app is not None
|
||||
Reference in New Issue
Block a user