Compare commits
2 Commits
37b892f695
...
80f8defcc2
| Author | SHA1 | Date | |
|---|---|---|---|
| 80f8defcc2 | |||
| f03e250763 |
@@ -1,3 +1,4 @@
|
|||||||
# openapi_first
|
# openapi_first
|
||||||
|
|
||||||
::: openapi_first
|
::: openapi_first
|
||||||
|
- [Openapi First](openapi_first/)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"module": "openapi_first.app",
|
"module": "openapi_first.app",
|
||||||
"content": {
|
"content": {
|
||||||
"path": "openapi_first.app",
|
"path": "openapi_first.app",
|
||||||
"docstring": "openapi_first.app\n=========================\n\nOpenAPI-first application bootstrap for FastAPI.\n\nThis module provides `OpenAPIFirstApp`, a thin but strict abstraction\nthat enforces OpenAPI as the single source of truth for a FastAPI service.\n\nCore principles\n---------------\n- The OpenAPI specification (JSON or YAML) defines the entire API surface.\n- Every operationId in the OpenAPI spec must have a corresponding\n Python handler function.\n- Handlers are plain Python callables (no FastAPI decorators).\n- FastAPI route registration is derived exclusively from the spec.\n- FastAPI's autogenerated OpenAPI schema is fully overridden.\n\nWhat this module does\n---------------------\n- Loads and validates an OpenAPI 3.x specification.\n- Dynamically binds HTTP routes to handler functions using operationId.\n- Registers routes with FastAPI at application startup.\n- Ensures runtime behavior matches the OpenAPI contract exactly.\n\nWhat this module does NOT do\n----------------------------\n- It does not generate OpenAPI specs.\n- It does not generate client code.\n- It does not introduce a new framework or lifecycle.\n- It does not alter FastAPI dependency injection semantics.\n\nIntended usage\n--------------\nThis module is intended for teams that want:\n\n- OpenAPI-first API development\n- Strong contract enforcement\n- Minimal FastAPI boilerplate\n- Predictable, CI-friendly failures for spec/implementation drift",
|
"docstring": "OpenAPI-first application bootstrap for FastAPI.\n\n---\n\n## Summary\n\nThis module provides `OpenAPIFirstApp`, a thin but strict abstraction\nthat enforces OpenAPI as the single source of truth for a FastAPI service.\n\nNotes:\n **Core Principles:**\n\n - The OpenAPI specification (JSON or YAML) defines the entire API surface\n - Every operationId in the OpenAPI spec must have a corresponding Python handler function\n - Handlers are plain Python callables (no FastAPI decorators)\n - FastAPI route registration is derived exclusively from the spec\n - FastAPI's autogenerated OpenAPI schema is fully overridden\n\n **Responsibilities:**\n\n - Loads and validates an OpenAPI 3.x specification\n - Dynamically binds HTTP routes to handler functions using operationId\n - Registers routes with FastAPI at application startup\n - Ensures runtime behavior matches the OpenAPI contract exactly\n\n **Constraints:**\n\n - This module intentionally does NOT: Generate OpenAPI specs, generate client code, introduce a new framework or lifecycle, or alter FastAPI dependency injection semantics.",
|
||||||
"objects": {
|
"objects": {
|
||||||
"FastAPI": {
|
"FastAPI": {
|
||||||
"name": "FastAPI",
|
"name": "FastAPI",
|
||||||
@@ -16,21 +16,21 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.app.load_openapi",
|
"path": "openapi_first.app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"bind_routes": {
|
"bind_routes": {
|
||||||
"name": "bind_routes",
|
"name": "bind_routes",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.app.bind_routes",
|
"path": "openapi_first.app.bind_routes",
|
||||||
"signature": "<bound method Alias.signature of Alias('bind_routes', 'openapi_first.binder.bind_routes')>",
|
"signature": "<bound method Alias.signature of Alias('bind_routes', 'openapi_first.binder.bind_routes')>",
|
||||||
"docstring": "Bind OpenAPI operations to FastAPI routes.\n\nIterates through the OpenAPI specification paths and methods,\nresolves each operationId to a handler function, and registers\na corresponding APIRoute on the FastAPI application.\n\nParameters\n----------\napp : fastapi.FastAPI\n The FastAPI application instance to which routes will be added.\n\nspec : dict\n Parsed OpenAPI 3.x specification dictionary.\n\nroutes_module : module\n Python module containing handler functions. Each handler's\n name MUST exactly match an OpenAPI operationId.\n\nRaises\n------\nMissingOperationHandler\n If an operationId is missing from the spec or if no corresponding\n handler function exists in the routes module.\n\nBehavior guarantees\n-------------------\n- Route registration is deterministic and spec-driven.\n- No route decorators are required or supported.\n- Handler resolution errors surface at application startup."
|
"docstring": "Bind OpenAPI operations to FastAPI routes.\n\nArgs:\n app (fastapi.FastAPI):\n The FastAPI application instance to which routes will be added.\n spec (dict):\n Parsed OpenAPI 3.x specification dictionary.\n routes_module (module):\n Python module containing handler functions. Each handler's name MUST exactly match an OpenAPI operationId.\n\nRaises:\n MissingOperationHandler:\n If an operationId is missing from the spec or if no corresponding handler function exists in the routes module.\n\nNotes:\n **Responsibilities:**\n\n - Iterates through the OpenAPI specification paths and methods\n - Resolves each operationId to a handler function, and registers a corresponding APIRoute on the FastAPI application\n\n **Guarantees:**\n\n - Route registration is deterministic and spec-driven. No route decorators are required or supported. Handler resolution errors surface at application startup."
|
||||||
},
|
},
|
||||||
"OpenAPIFirstApp": {
|
"OpenAPIFirstApp": {
|
||||||
"name": "OpenAPIFirstApp",
|
"name": "OpenAPIFirstApp",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.app.OpenAPIFirstApp",
|
"path": "openapi_first.app.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Class.signature of Class('OpenAPIFirstApp', 49, 120)>",
|
"signature": "<bound method Class.signature of Class('OpenAPIFirstApp', 38, 104)>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"module": "openapi_first.binder",
|
"module": "openapi_first.binder",
|
||||||
"content": {
|
"content": {
|
||||||
"path": "openapi_first.binder",
|
"path": "openapi_first.binder",
|
||||||
"docstring": "openapi_first.binder\n============================\n\nOpenAPI-driven route binding for FastAPI.\n\nThis module is responsible for translating an OpenAPI 3.x specification\ninto concrete FastAPI routes. It enforces a strict one-to-one mapping\nbetween OpenAPI operations and Python handler functions using operationId.\n\nCore responsibility\n-------------------\n- Read path + method definitions from an OpenAPI specification\n- Resolve each operationId to a Python callable\n- Register routes with FastAPI using APIRoute\n- Fail fast when contract violations are detected\n\nDesign constraints\n------------------\n- All routes MUST be declared in the OpenAPI specification.\n- All OpenAPI operations MUST define an operationId.\n- Every operationId MUST resolve to a handler function.\n- Handlers are plain Python callables (no decorators required).\n- No implicit route creation or inference is allowed.\n\nThis module intentionally does NOT:\n-------------------------------\n- Perform request or response validation\n- Generate Pydantic models\n- Modify FastAPI dependency injection\n- Interpret OpenAPI semantics beyond routing metadata\n\nThose concerns belong to other layers or tooling.",
|
"docstring": "OpenAPI-driven route binding for FastAPI.\n\n---\n\n## Summary\n\nThis module is responsible for translating an OpenAPI 3.x specification\ninto concrete FastAPI routes. It enforces a strict one-to-one mapping\nbetween OpenAPI operations and Python handler functions using operationId.\n\nNotes:\n **Core Responsibility:**\n\n - Read path + method definitions from an OpenAPI specification\n - Resolve each operationId to a Python callable\n - Register routes with FastAPI using APIRoute\n - Fail fast when contract violations are detected\n\n **Design Constraints:**\n\n - All routes MUST be declared in the OpenAPI specification\n - All OpenAPI operations MUST define an operationId\n - Every operationId MUST resolve to a handler function\n - Handlers are plain Python callables (no decorators required)\n - No implicit route creation or inference is allowed\n\n **Constraints:**\n\n - This module intentionally does NOT: Perform request or response validation, generate Pydantic models, modify FastAPI dependency injection, or interpret OpenAPI semantics beyond routing metadata.",
|
||||||
"objects": {
|
"objects": {
|
||||||
"APIRoute": {
|
"APIRoute": {
|
||||||
"name": "APIRoute",
|
"name": "APIRoute",
|
||||||
@@ -16,14 +16,14 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.binder.MissingOperationHandler",
|
"path": "openapi_first.binder.MissingOperationHandler",
|
||||||
"signature": "<bound method Alias.signature of Alias('MissingOperationHandler', 'openapi_first.errors.MissingOperationHandler')>",
|
"signature": "<bound method Alias.signature of Alias('MissingOperationHandler', 'openapi_first.errors.MissingOperationHandler')>",
|
||||||
"docstring": "Raised when an OpenAPI operation cannot be resolved to a handler.\n\nThis error occurs when:\n- An OpenAPI operation does not define an operationId, or\n- An operationId is defined but no matching function exists in the\n provided routes module.\n\nThis represents a violation of the OpenAPI-first contract and\nindicates that the specification and implementation are out of sync."
|
"docstring": "Raised when an OpenAPI operation cannot be resolved to a handler.\n\nNotes:\n **Scenarios:**\n\n - An OpenAPI operation does not define an operationId\n - An operationId is defined but no matching function exists in the provided routes module\n\n **Guarantees:**\n\n - This represents a violation of the OpenAPI-first contract and indicates that the specification and implementation are out of sync"
|
||||||
},
|
},
|
||||||
"bind_routes": {
|
"bind_routes": {
|
||||||
"name": "bind_routes",
|
"name": "bind_routes",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.binder.bind_routes",
|
"path": "openapi_first.binder.bind_routes",
|
||||||
"signature": "<bound method Function.signature of Function('bind_routes', 41, 102)>",
|
"signature": "<bound method Function.signature of Function('bind_routes', 38, 93)>",
|
||||||
"docstring": "Bind OpenAPI operations to FastAPI routes.\n\nIterates through the OpenAPI specification paths and methods,\nresolves each operationId to a handler function, and registers\na corresponding APIRoute on the FastAPI application.\n\nParameters\n----------\napp : fastapi.FastAPI\n The FastAPI application instance to which routes will be added.\n\nspec : dict\n Parsed OpenAPI 3.x specification dictionary.\n\nroutes_module : module\n Python module containing handler functions. Each handler's\n name MUST exactly match an OpenAPI operationId.\n\nRaises\n------\nMissingOperationHandler\n If an operationId is missing from the spec or if no corresponding\n handler function exists in the routes module.\n\nBehavior guarantees\n-------------------\n- Route registration is deterministic and spec-driven.\n- No route decorators are required or supported.\n- Handler resolution errors surface at application startup."
|
"docstring": "Bind OpenAPI operations to FastAPI routes.\n\nArgs:\n app (fastapi.FastAPI):\n The FastAPI application instance to which routes will be added.\n spec (dict):\n Parsed OpenAPI 3.x specification dictionary.\n routes_module (module):\n Python module containing handler functions. Each handler's name MUST exactly match an OpenAPI operationId.\n\nRaises:\n MissingOperationHandler:\n If an operationId is missing from the spec or if no corresponding handler function exists in the routes module.\n\nNotes:\n **Responsibilities:**\n\n - Iterates through the OpenAPI specification paths and methods\n - Resolves each operationId to a handler function, and registers a corresponding APIRoute on the FastAPI application\n\n **Guarantees:**\n\n - Route registration is deterministic and spec-driven. No route decorators are required or supported. Handler resolution errors surface at application startup."
|
||||||
},
|
},
|
||||||
"Any": {
|
"Any": {
|
||||||
"name": "Any",
|
"name": "Any",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"module": "openapi_first.cli",
|
"module": "openapi_first.cli",
|
||||||
"content": {
|
"content": {
|
||||||
"path": "openapi_first.cli",
|
"path": "openapi_first.cli",
|
||||||
"docstring": "openapi_first.cli\n========================\n\nCommand-line interface for FastAPI OpenAPI-first scaffolding utilities.\n\nThis CLI bootstraps OpenAPI-first FastAPI applications from versioned,\nbundled templates packaged with the library.",
|
"docstring": "Command-line interface for FastAPI OpenAPI-first scaffolding utilities.\n\n---\n\n## Summary\n\nThis CLI bootstraps OpenAPI-first FastAPI applications from versioned,\nbundled templates packaged with the library.",
|
||||||
"objects": {
|
"objects": {
|
||||||
"argparse": {
|
"argparse": {
|
||||||
"name": "argparse",
|
"name": "argparse",
|
||||||
@@ -43,21 +43,21 @@
|
|||||||
"name": "available_templates",
|
"name": "available_templates",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.cli.available_templates",
|
"path": "openapi_first.cli.available_templates",
|
||||||
"signature": "<bound method Function.signature of Function('available_templates', 20, 29)>",
|
"signature": "<bound method Function.signature of Function('available_templates', 21, 34)>",
|
||||||
"docstring": "Return a list of available application templates."
|
"docstring": "Return a list of available application templates.\n\nReturns:\n list[str]:\n Sorted list of template names found in the internal templates directory."
|
||||||
},
|
},
|
||||||
"copy_template": {
|
"copy_template": {
|
||||||
"name": "copy_template",
|
"name": "copy_template",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.cli.copy_template",
|
"path": "openapi_first.cli.copy_template",
|
||||||
"signature": "<bound method Function.signature of Function('copy_template', 32, 49)>",
|
"signature": "<bound method Function.signature of Function('copy_template', 37, 64)>",
|
||||||
"docstring": "Copy a bundled OpenAPI-first application template into a directory."
|
"docstring": "Copy a bundled OpenAPI-first application template into a directory.\n\nArgs:\n template (str):\n Name of the template to copy.\n target_dir (Path):\n Filesystem path where the template should be copied.\n\nRaises:\n FileNotFoundError:\n If the requested template does not exist."
|
||||||
},
|
},
|
||||||
"main": {
|
"main": {
|
||||||
"name": "main",
|
"name": "main",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.cli.main",
|
"path": "openapi_first.cli.main",
|
||||||
"signature": "<bound method Function.signature of Function('main', 52, 88)>",
|
"signature": "<bound method Function.signature of Function('main', 67, 103)>",
|
||||||
"docstring": null
|
"docstring": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"module": "openapi_first.client",
|
"module": "openapi_first.client",
|
||||||
"content": {
|
"content": {
|
||||||
"path": "openapi_first.client",
|
"path": "openapi_first.client",
|
||||||
"docstring": "openapi_first.client\n====================\n\nOpenAPI-first HTTP client for contract-driven services.\n\nThis module provides `OpenAPIClient`, a thin, strict HTTP client that\nderives all callable operations directly from an OpenAPI 3.x specification.\n\nIt is the client counterpart to `OpenAPIFirstApp`.\n\nCore principles\n---------------\n- The OpenAPI specification is the single source of truth.\n- Each operationId becomes a callable Python method.\n- No implicit schema mutation or inference.\n- No code generation step.\n- Minimal abstraction over httpx.\n\nWhat this module does\n---------------------\n- Parses an OpenAPI 3.x specification.\n- Dynamically creates one callable per operationId.\n- Enforces presence of:\n - servers\n - paths\n - operationId\n- Formats path parameters safely.\n- Handles JSON request bodies explicitly.\n- Returns raw `httpx.Response` objects.\n\nWhat this module does NOT do\n----------------------------\n- It does not generate client code.\n- It does not validate request/response schemas.\n- It does not deserialize responses.\n- It does not retry requests.\n- It does not implement authentication helpers.\n- It does not assume non-2xx responses are failures.\n\nIntended usage\n--------------\nThis client is designed for:\n\n- Service-to-service communication\n- Integration testing\n- Contract-driven internal SDK usage\n- Systems that want OpenAPI-first symmetry with `OpenAPIFirstApp`\n\nDesign constraints\n------------------\n- Only the first server in the OpenAPI `servers` list is used if\n `base_url` is not explicitly provided.\n- Only explicitly declared request bodies are allowed.\n- `application/json` is handled natively; other media types are sent as raw content.\n- All responses are returned as-is.",
|
"docstring": "OpenAPI-first HTTP client for contract-driven services.\n\n---\n\n## Summary\n\nThis module provides `OpenAPIClient`, a thin, strict HTTP client that\nderives all callable operations directly from an OpenAPI 3.x specification.\n\nIt is the client counterpart to `OpenAPIFirstApp`.\n\nNotes:\n **Core Principles:**\n\n - The OpenAPI specification is the single source of truth\n - Each operationId becomes a callable Python method\n - No implicit schema mutation or inference\n - No code generation step\n - Minimal abstraction over httpx\n\n **Responsibilities:**\n\n - Parses an OpenAPI 3.x specification\n - Dynamically creates one callable per operationId\n - Enforces presence of servers, paths, and operationId\n - Formats path parameters safely\n - Handles JSON request bodies explicitly\n - Returns raw `httpx.Response` objects\n\n **Constraints:**\n\n - This module intentionally does NOT: Generate client code, validate request/response schemas, deserialize responses, retry requests, implement authentication helpers, or assume non-2xx responses are failures.",
|
||||||
"objects": {
|
"objects": {
|
||||||
"Any": {
|
"Any": {
|
||||||
"name": "Any",
|
"name": "Any",
|
||||||
@@ -51,21 +51,21 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.client.OpenAPIFirstError",
|
"path": "openapi_first.client.OpenAPIFirstError",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstError', 'openapi_first.errors.OpenAPIFirstError')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstError', 'openapi_first.errors.OpenAPIFirstError')>",
|
||||||
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nThis exception exists to allow callers, test suites, and CI pipelines\nto catch and distinguish OpenAPI contract violations from unrelated\nruntime errors.\n\nAll exceptions raised by the OpenAPI-first core should inherit from\nthis type."
|
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nNotes:\n **Responsibilities:**\n\n - This exception exists to allow callers, test suites, and CI pipelines to catch and distinguish OpenAPI contract violations from unrelated runtime errors\n - All exceptions raised by the OpenAPI-first core should inherit from this type"
|
||||||
},
|
},
|
||||||
"OpenAPIClientError": {
|
"OpenAPIClientError": {
|
||||||
"name": "OpenAPIClientError",
|
"name": "OpenAPIClientError",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.client.OpenAPIClientError",
|
"path": "openapi_first.client.OpenAPIClientError",
|
||||||
"signature": "<bound method Class.signature of Class('OpenAPIClientError', 67, 68)>",
|
"signature": "<bound method Class.signature of Class('OpenAPIClientError', 44, 47)>",
|
||||||
"docstring": "Raised when an OpenAPI client operation fails."
|
"docstring": "Raised when an OpenAPI client operation fails."
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.client.OpenAPIClient",
|
"path": "openapi_first.client.OpenAPIClient",
|
||||||
"signature": "<bound method Class.signature of Class('OpenAPIClient', 71, 291)>",
|
"signature": "<bound method Class.signature of Class('OpenAPIClient', 50, 257)>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
"name": "operations",
|
"name": "operations",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.client.OpenAPIClient.operations",
|
"path": "openapi_first.client.OpenAPIClient.operations",
|
||||||
"signature": "<bound method Function.signature of Function('operations', 160, 161)>",
|
"signature": "<bound method Function.signature of Function('operations', 126, 127)>",
|
||||||
"docstring": null
|
"docstring": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,21 @@
|
|||||||
"module": "openapi_first.errors",
|
"module": "openapi_first.errors",
|
||||||
"content": {
|
"content": {
|
||||||
"path": "openapi_first.errors",
|
"path": "openapi_first.errors",
|
||||||
"docstring": "openapi_first.errors\n============================\n\nCustom exceptions for OpenAPI-first FastAPI applications.\n\nThis module defines a small hierarchy of explicit, intention-revealing\nexceptions used to signal contract violations between an OpenAPI\nspecification and its Python implementation.\n\nDesign principles\n-----------------\n- Errors represent *programmer mistakes*, not runtime conditions.\n- All errors are raised during application startup.\n- Messages are actionable and suitable for CI/CD output.\n- Exceptions are explicit rather than reused from generic built-ins.\n\nThese errors should normally cause immediate application failure.",
|
"docstring": "Exceptions for OpenAPI-first FastAPI applications.\n\n---\n\n## Summary\n\nThis module defines a small hierarchy of explicit, intention-revealing\nexceptions used to signal contract violations between an OpenAPI\nspecification and its Python implementation.\n\nNotes:\n **Design Principles:**\n\n - Errors represent programmer mistakes, not runtime conditions\n - All errors are raised during application startup\n - Messages are actionable and suitable for CI/CD output\n - Exceptions are explicit rather than reused from generic built-ins\n\n These errors should normally cause immediate application failure.",
|
||||||
"objects": {
|
"objects": {
|
||||||
"OpenAPIFirstError": {
|
"OpenAPIFirstError": {
|
||||||
"name": "OpenAPIFirstError",
|
"name": "OpenAPIFirstError",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.errors.OpenAPIFirstError",
|
"path": "openapi_first.errors.OpenAPIFirstError",
|
||||||
"signature": "<bound method Class.signature of Class('OpenAPIFirstError', 21, 32)>",
|
"signature": "<bound method Class.signature of Class('OpenAPIFirstError', 23, 33)>",
|
||||||
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nThis exception exists to allow callers, test suites, and CI pipelines\nto catch and distinguish OpenAPI contract violations from unrelated\nruntime errors.\n\nAll exceptions raised by the OpenAPI-first core should inherit from\nthis type."
|
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nNotes:\n **Responsibilities:**\n\n - This exception exists to allow callers, test suites, and CI pipelines to catch and distinguish OpenAPI contract violations from unrelated runtime errors\n - All exceptions raised by the OpenAPI-first core should inherit from this type"
|
||||||
},
|
},
|
||||||
"MissingOperationHandler": {
|
"MissingOperationHandler": {
|
||||||
"name": "MissingOperationHandler",
|
"name": "MissingOperationHandler",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.errors.MissingOperationHandler",
|
"path": "openapi_first.errors.MissingOperationHandler",
|
||||||
"signature": "<bound method Class.signature of Class('MissingOperationHandler', 35, 72)>",
|
"signature": "<bound method Class.signature of Class('MissingOperationHandler', 36, 74)>",
|
||||||
"docstring": "Raised when an OpenAPI operation cannot be resolved to a handler.\n\nThis error occurs when:\n- An OpenAPI operation does not define an operationId, or\n- An operationId is defined but no matching function exists in the\n provided routes module.\n\nThis represents a violation of the OpenAPI-first contract and\nindicates that the specification and implementation are out of sync."
|
"docstring": "Raised when an OpenAPI operation cannot be resolved to a handler.\n\nNotes:\n **Scenarios:**\n\n - An OpenAPI operation does not define an operationId\n - An operationId is defined but no matching function exists in the provided routes module\n\n **Guarantees:**\n\n - This represents a violation of the OpenAPI-first contract and indicates that the specification and implementation are out of sync"
|
||||||
},
|
},
|
||||||
"Optional": {
|
"Optional": {
|
||||||
"name": "Optional",
|
"name": "Optional",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
|||||||
"module": "openapi_first.loader",
|
"module": "openapi_first.loader",
|
||||||
"content": {
|
"content": {
|
||||||
"path": "openapi_first.loader",
|
"path": "openapi_first.loader",
|
||||||
"docstring": "openapi_first.loaders\n=============================\n\nOpenAPI specification loading and validation utilities.\n\nThis module is responsible for loading an OpenAPI 3.x specification\nfrom disk and validating it before it is used by the application.\n\nIt enforces the principle that an invalid or malformed OpenAPI document\nmust never reach the routing or runtime layers.\n\nDesign principles\n-----------------\n- OpenAPI is treated as an authoritative contract.\n- Invalid specifications fail fast at application startup.\n- Supported formats are JSON and YAML.\n- Validation errors are surfaced clearly and early.\n\nThis module intentionally does NOT:\n-----------------------------------\n- Modify the OpenAPI document\n- Infer missing fields\n- Generate models or code\n- Perform request/response validation at runtime",
|
"docstring": "OpenAPI specification loading and validation utilities.\n\n---\n\n## Summary\n\nThis module is responsible for loading an OpenAPI 3.x specification\nfrom disk and validating it before it is used by the application.\n\nIt enforces the principle that an invalid or malformed OpenAPI document\nmust never reach the routing or runtime layers.\n\nNotes:\n **Design Principles:**\n\n - OpenAPI is treated as an authoritative contract\n - Invalid specifications fail fast at application startup\n - Supported formats are JSON and YAML\n - Validation errors are surfaced clearly and early\n\n **Constraints:**\n\n - This module intentionally does NOT: Modify the OpenAPI document, infer missing fields, generate models or code, or perform request/response validation at runtime.",
|
||||||
"objects": {
|
"objects": {
|
||||||
"json": {
|
"json": {
|
||||||
"name": "json",
|
"name": "json",
|
||||||
@@ -44,21 +44,21 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.loader.OpenAPIFirstError",
|
"path": "openapi_first.loader.OpenAPIFirstError",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstError', 'openapi_first.errors.OpenAPIFirstError')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstError', 'openapi_first.errors.OpenAPIFirstError')>",
|
||||||
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nThis exception exists to allow callers, test suites, and CI pipelines\nto catch and distinguish OpenAPI contract violations from unrelated\nruntime errors.\n\nAll exceptions raised by the OpenAPI-first core should inherit from\nthis type."
|
"docstring": "Base exception for all OpenAPI-first enforcement errors.\n\nNotes:\n **Responsibilities:**\n\n - This exception exists to allow callers, test suites, and CI pipelines to catch and distinguish OpenAPI contract violations from unrelated runtime errors\n - All exceptions raised by the OpenAPI-first core should inherit from this type"
|
||||||
},
|
},
|
||||||
"OpenAPISpecLoadError": {
|
"OpenAPISpecLoadError": {
|
||||||
"name": "OpenAPISpecLoadError",
|
"name": "OpenAPISpecLoadError",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.loader.OpenAPISpecLoadError",
|
"path": "openapi_first.loader.OpenAPISpecLoadError",
|
||||||
"signature": "<bound method Class.signature of Class('OpenAPISpecLoadError', 38, 45)>",
|
"signature": "<bound method Class.signature of Class('OpenAPISpecLoadError', 37, 46)>",
|
||||||
"docstring": "Raised when an OpenAPI specification cannot be loaded or validated.\n\nThis error indicates that the OpenAPI document is unreadable,\nmalformed, or violates the OpenAPI 3.x specification."
|
"docstring": "Raised when an OpenAPI specification cannot be loaded or validated.\n\nNotes:\n **Guarantees:**\n\n - This error indicates that the OpenAPI document is unreadable, malformed, or violates the OpenAPI 3.x specification"
|
||||||
},
|
},
|
||||||
"load_openapi": {
|
"load_openapi": {
|
||||||
"name": "load_openapi",
|
"name": "load_openapi",
|
||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.loader.load_openapi",
|
"path": "openapi_first.loader.load_openapi",
|
||||||
"signature": "<bound method Function.signature of Function('load_openapi', 48, 107)>",
|
"signature": "<bound method Function.signature of Function('load_openapi', 49, 102)>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"Dict": {
|
"Dict": {
|
||||||
"name": "Dict",
|
"name": "Dict",
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
@@ -178,14 +178,14 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
|
|||||||
@@ -23,14 +23,14 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
|
|||||||
@@ -74,7 +74,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.crud_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
@@ -185,14 +185,14 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
"path": "openapi_first.templates.crud_app.test_crud_app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
"path": "openapi_first.templates.crud_app.test_crud_app.OpenAPIClient",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
@@ -296,7 +296,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.health_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
@@ -425,7 +425,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
@@ -605,14 +605,14 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
@@ -261,14 +261,14 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
"path": "openapi_first.templates.model_app.main.OpenAPIFirstApp",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIFirstApp', 'openapi_first.app.OpenAPIFirstApp')>",
|
||||||
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\n`OpenAPIFirstApp` subclasses FastAPI and replaces manual route\nregistration with OpenAPI-driven binding. All routes are derived\nfrom the provided OpenAPI specification, and each operationId is\nmapped to a Python function in the supplied routes module.\n\nParameters\n----------\nopenapi_path : str\n Filesystem path to the OpenAPI 3.x specification file.\n This specification is treated as the authoritative API contract.\n\nroutes_module : module\n Python module containing handler functions whose names correspond\n exactly to OpenAPI operationId values.\n\n**fastapi_kwargs\n Additional keyword arguments passed directly to `fastapi.FastAPI`\n (e.g., title, version, middleware, lifespan handlers).\n\nRaises\n------\nOpenAPIFirstError\n If the OpenAPI specification is invalid, or if any declared\n operationId does not have a corresponding handler function.\n\nBehavior guarantees\n-------------------\n- No route can exist without an OpenAPI declaration.\n- No OpenAPI operation can exist without a handler.\n- Swagger UI and `/openapi.json` always reflect the provided spec.\n- Handler functions remain framework-agnostic and testable.\n\nExample\n-------\n```python\nfrom openapi_first import OpenAPIFirstApp\nimport app.routes as routes\n\napp = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n)\n```",
|
"docstring": "FastAPI application enforcing OpenAPI-first design.\n\nNotes:\n **Responsibilities:**\n\n - `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding\n - All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module\n\n **Guarantees:**\n\n - No route can exist without an OpenAPI declaration\n - No OpenAPI operation can exist without a handler\n - Swagger UI and `/openapi.json` always reflect the provided spec\n - Handler functions remain framework-agnostic and testable\n\nExample:\n ```python\n from openapi_first import OpenAPIFirstApp\n import app.routes as routes\n\n app = OpenAPIFirstApp(\n openapi_path=\"app/openapi.json\",\n routes_module=routes,\n title=\"Example Service\",\n )\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"openapi": {
|
"openapi": {
|
||||||
"name": "openapi",
|
"name": "openapi",
|
||||||
|
|||||||
@@ -23,14 +23,14 @@
|
|||||||
"kind": "function",
|
"kind": "function",
|
||||||
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
"path": "openapi_first.templates.model_app.test_model_app.load_openapi",
|
||||||
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
"signature": "<bound method Alias.signature of Alias('load_openapi', 'openapi_first.loader.load_openapi')>",
|
||||||
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nThe specification is parsed based on file extension and validated\nusing a strict OpenAPI schema validator. Any error results in an\nimmediate exception, preventing application startup.\n\nParameters\n----------\npath : str or pathlib.Path\n Filesystem path to an OpenAPI specification file.\n Supported extensions:\n - `.json`\n - `.yaml`\n - `.yml`\n\nReturns\n-------\ndict\n Parsed and validated OpenAPI specification.\n\nRaises\n------\nOpenAPISpecLoadError\n If the file does not exist, cannot be parsed, or fails\n OpenAPI schema validation."
|
"docstring": "Load and validate an OpenAPI 3.x specification from disk.\n\nArgs:\n path (str | Path):\n Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.\n\nReturns:\n dict[str, Any]:\n Parsed and validated OpenAPI specification.\n\nRaises:\n OpenAPISpecLoadError:\n If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.\n\nNotes:\n **Guarantees:**\n\n - The specification is parsed based on file extension and validated using a strict OpenAPI schema validator\n - Any error results in an immediate exception, preventing application startup"
|
||||||
},
|
},
|
||||||
"OpenAPIClient": {
|
"OpenAPIClient": {
|
||||||
"name": "OpenAPIClient",
|
"name": "OpenAPIClient",
|
||||||
"kind": "class",
|
"kind": "class",
|
||||||
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
"path": "openapi_first.templates.model_app.test_model_app.OpenAPIClient",
|
||||||
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
"signature": "<bound method Alias.signature of Alias('OpenAPIClient', 'openapi_first.client.OpenAPIClient')>",
|
||||||
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nThis client derives all callable methods directly from an OpenAPI 3.x\nspecification. Each operationId becomes a method on the client\ninstance.\n\nDesign principles\n-----------------\n- One callable per operationId\n- Explicit parameters (path, query, headers, body)\n- No implicit schema inference or mutation\n- Returns raw httpx.Response objects\n- No response validation or deserialization\n\nParameters\n----------\nspec : dict\n Parsed OpenAPI 3.x specification.\nbase_url : str | None\n Base URL of the target service. If omitted, the first entry\n in the OpenAPI `servers` list is used.\nclient : httpx.Client | None\n Optional preconfigured httpx client instance.\n\nRaises\n------\nOpenAPIClientError\n If:\n - No servers are defined and base_url is not provided\n - OpenAPI spec has no paths\n - An operation is missing operationId\n - Duplicate operationIds are detected\n - Required path parameters are missing\n - Required request body is missing\n\n Example\n-------\n```python\nfrom openapi_first import loader, client\n\nspec = loader.load_openapi(\"openapi.yaml\")\n\napi = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n)\n\n# Call operationId: getUser\nresponse = api.getUser(\n path_params={\"user_id\": 123}\n)\n\nprint(response.status_code)\nprint(response.json())\n\n# Call operationId: createUser\nresponse = api.createUser(\n body={\"name\": \"Bob\"}\n)\n\nprint(response.status_code)\n```",
|
"docstring": "OpenAPI-first HTTP client (httpx-based).\n\nNotes:\n **Responsibilities:**\n\n - This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.\n\n **Guarantees:**\n\n - One callable per operationId\n - Explicit parameters (path, query, headers, body)\n - No implicit schema inference or mutation\n - Returns raw `httpx.Response` objects\n - No response validation or deserialization\n\nExample:\n ```python\n from openapi_first import loader, client\n\n spec = loader.load_openapi(\"openapi.yaml\")\n\n api = client.OpenAPIClient(\n spec=spec,\n base_url=\"http://localhost:8000\",\n )\n\n # Call operationId: getUser\n response = api.getUser(\n path_params={\"user_id\": 123}\n )\n\n print(response.status_code)\n print(response.json())\n ```",
|
||||||
"members": {
|
"members": {
|
||||||
"spec": {
|
"spec": {
|
||||||
"name": "spec",
|
"name": "spec",
|
||||||
|
|||||||
33
mkdocs.yml
33
mkdocs.yml
@@ -8,12 +8,19 @@ theme:
|
|||||||
text: Inter
|
text: Inter
|
||||||
code: JetBrains Mono
|
code: JetBrains Mono
|
||||||
features:
|
features:
|
||||||
- navigation.tabs
|
- navigation.sections
|
||||||
- navigation.expand
|
- navigation.expand
|
||||||
- navigation.top
|
- navigation.top
|
||||||
- navigation.instant
|
- navigation.instant
|
||||||
|
- navigation.tracking
|
||||||
|
- navigation.indexes
|
||||||
- content.code.copy
|
- content.code.copy
|
||||||
- content.code.annotate
|
- content.code.annotate
|
||||||
|
- content.tabs.link
|
||||||
|
- content.action.edit
|
||||||
|
- search.highlight
|
||||||
|
- search.share
|
||||||
|
- search.suggest
|
||||||
plugins:
|
plugins:
|
||||||
- search
|
- search
|
||||||
- mkdocstrings:
|
- mkdocstrings:
|
||||||
@@ -31,6 +38,30 @@ plugins:
|
|||||||
annotations_path: brief
|
annotations_path: brief
|
||||||
show_root_heading: true
|
show_root_heading: true
|
||||||
group_by_category: true
|
group_by_category: true
|
||||||
|
show_category_heading: true
|
||||||
|
show_object_full_path: false
|
||||||
|
show_symbol_type_heading: true
|
||||||
|
markdown_extensions:
|
||||||
|
- pymdownx.superfences
|
||||||
|
- pymdownx.inlinehilite
|
||||||
|
- pymdownx.snippets
|
||||||
|
- admonition
|
||||||
|
- pymdownx.details
|
||||||
|
- pymdownx.superfences
|
||||||
|
- pymdownx.highlight:
|
||||||
|
linenums: true
|
||||||
|
anchor_linenums: true
|
||||||
|
line_spans: __span
|
||||||
|
pygments_lang_class: true
|
||||||
|
- pymdownx.tabbed:
|
||||||
|
alternate_style: true
|
||||||
|
- pymdownx.tasklist:
|
||||||
|
custom_checkbox: true
|
||||||
|
- tables
|
||||||
|
- footnotes
|
||||||
|
- pymdownx.caret
|
||||||
|
- pymdownx.tilde
|
||||||
|
- pymdownx.mark
|
||||||
site_name: openapi_first
|
site_name: openapi_first
|
||||||
nav:
|
nav:
|
||||||
- Home: index.md
|
- Home: index.md
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
FastAPI OpenAPI First — strict OpenAPI-first application bootstrap for FastAPI.
|
FastAPI OpenAPI First — strict OpenAPI-first application bootstrap for FastAPI.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
FastAPI OpenAPI First is a **contract-first infrastructure library** that
|
FastAPI OpenAPI First is a **contract-first infrastructure library** that
|
||||||
enforces OpenAPI as the single source of truth for FastAPI services.
|
enforces OpenAPI as the single source of truth for FastAPI services.
|
||||||
|
|
||||||
@@ -9,28 +13,9 @@ deterministic, spec-driven application assembly. Every HTTP route,
|
|||||||
method, and operation is defined in OpenAPI first and bound to Python
|
method, and operation is defined in OpenAPI first and bound to Python
|
||||||
handlers explicitly via operationId.
|
handlers explicitly via operationId.
|
||||||
|
|
||||||
The package is intentionally minimal and layered. Each module has a
|
---
|
||||||
single responsibility and exposes explicit contracts rather than
|
|
||||||
convenience facades.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
## Installation
|
||||||
Architecture Overview
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
The library is structured around four core responsibilities:
|
|
||||||
|
|
||||||
- loader: load and validate OpenAPI 3.x specifications (JSON/YAML)
|
|
||||||
- binder: bind OpenAPI operations to FastAPI routes via operationId
|
|
||||||
- app: OpenAPI-first FastAPI application bootstrap
|
|
||||||
- client: OpenAPI-first HTTP client driven by the same specification
|
|
||||||
- errors: explicit error hierarchy for contract violations
|
|
||||||
|
|
||||||
The package root acts as a **namespace**, not a facade. Consumers are
|
|
||||||
expected to import functionality explicitly from the appropriate module.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Installation
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
Install using pip:
|
Install using pip:
|
||||||
|
|
||||||
@@ -40,44 +25,9 @@ Or with Poetry:
|
|||||||
|
|
||||||
poetry add openapi-first
|
poetry add openapi-first
|
||||||
|
|
||||||
Runtime dependencies are intentionally minimal:
|
---
|
||||||
- fastapi (server-side)
|
|
||||||
- httpx (client-side)
|
|
||||||
- openapi-spec-validator
|
|
||||||
- pyyaml (optional, for YAML specs)
|
|
||||||
|
|
||||||
The ASGI server (e.g., uvicorn) is an application-level dependency and is
|
## Quick start
|
||||||
not bundled with this library.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Command-Line Interface (Scaffolding, Templates)
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
FastAPI OpenAPI First ships with a small CLI for bootstrapping
|
|
||||||
OpenAPI-first FastAPI applications from bundled templates.
|
|
||||||
|
|
||||||
List available application templates:
|
|
||||||
|
|
||||||
openapi-first --list
|
|
||||||
|
|
||||||
Create a new application using the default template:
|
|
||||||
|
|
||||||
openapi-first
|
|
||||||
|
|
||||||
Create a new application using a specific template:
|
|
||||||
|
|
||||||
openapi-first health_app
|
|
||||||
|
|
||||||
Create a new application in a custom directory:
|
|
||||||
|
|
||||||
openapi-first health_app my-service
|
|
||||||
|
|
||||||
The CLI copies template files verbatim into the target directory.
|
|
||||||
No code is generated or modified beyond the copied scaffold.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Server-Side Usage (OpenAPI → FastAPI)
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
Minimal OpenAPI-first FastAPI application:
|
Minimal OpenAPI-first FastAPI application:
|
||||||
|
|
||||||
@@ -91,109 +41,43 @@ Minimal OpenAPI-first FastAPI application:
|
|||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Run with:
|
OperationId-driven HTTP client:
|
||||||
# uvicorn my_service.main:api
|
|
||||||
|
|
||||||
Handler definitions (no decorators):
|
|
||||||
|
|
||||||
def get_health():
|
|
||||||
return {"status": "ok"}
|
|
||||||
|
|
||||||
OpenAPI snippet:
|
|
||||||
|
|
||||||
paths:
|
|
||||||
/health:
|
|
||||||
get:
|
|
||||||
operationId: get_health
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
|
|
||||||
The binder guarantees:
|
|
||||||
- Every OpenAPI operationId has exactly one handler
|
|
||||||
- No undocumented routes exist
|
|
||||||
- All mismatches fail at application startup
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Client-Side Usage (OpenAPI → HTTP Client)
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
The same OpenAPI specification can be used to construct a strict,
|
|
||||||
operationId-driven HTTP client.
|
|
||||||
|
|
||||||
Client construction:
|
|
||||||
|
|
||||||
from openapi_first.loader import load_openapi
|
from openapi_first.loader import load_openapi
|
||||||
from openapi_first.client import OpenAPIClient
|
from openapi_first.client import OpenAPIClient
|
||||||
|
|
||||||
spec = load_openapi("openapi.yaml")
|
spec = load_openapi("openapi.yaml")
|
||||||
|
|
||||||
client = OpenAPIClient(spec)
|
client = OpenAPIClient(spec)
|
||||||
|
|
||||||
Calling operations (operationId is the API):
|
|
||||||
|
|
||||||
response = client.get_health()
|
response = client.get_health()
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {"status": "ok"}
|
|
||||||
|
|
||||||
Path parameters must match the OpenAPI specification exactly:
|
---
|
||||||
|
|
||||||
response = client.get_item(
|
## Architecture
|
||||||
path_params={"item_id": 1}
|
|
||||||
)
|
|
||||||
|
|
||||||
Request bodies are passed explicitly:
|
The library is structured around four core responsibilities:
|
||||||
|
|
||||||
response = client.create_item(
|
- **loader**: Load and validate OpenAPI 3.x specifications (JSON/YAML)
|
||||||
body={"name": "Orange", "price": 0.8}
|
- **binder**: Bind OpenAPI operations to FastAPI routes via operationId
|
||||||
)
|
- **app**: OpenAPI-first FastAPI application bootstrap
|
||||||
|
- **client**: OpenAPI-first HTTP client driven by the same specification
|
||||||
|
- **errors**: Explicit error hierarchy for contract violations
|
||||||
|
|
||||||
Client guarantees:
|
---
|
||||||
- One callable per OpenAPI operationId
|
|
||||||
- No hardcoded URLs or HTTP methods in user code
|
|
||||||
- Path and body parameters must match the spec exactly
|
|
||||||
- Invalid or incomplete OpenAPI specs fail at client construction time
|
|
||||||
- No schema inference or mutation is performed
|
|
||||||
|
|
||||||
The client is transport-level only and returns `httpx.Response`
|
## Public API
|
||||||
objects directly. Response interpretation and validation are left to
|
|
||||||
the consumer or higher-level layers.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Extensibility Model
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
FastAPI OpenAPI First is designed to be extended via **explicit contracts**:
|
|
||||||
|
|
||||||
- Users MAY extend OpenAPI loading behavior (e.g. multi-file specs)
|
|
||||||
by wrapping or replacing `loader.load_openapi`
|
|
||||||
- Users MAY extend route binding behavior by building on top of
|
|
||||||
`binder.bind_routes`
|
|
||||||
- Users MAY layer additional validation (e.g. signature checks)
|
|
||||||
without modifying core modules
|
|
||||||
|
|
||||||
Users SHOULD NOT rely on FastAPI decorators for routing when using this
|
|
||||||
library. Mixing decorator-driven routes with OpenAPI-first routing
|
|
||||||
defeats the contract guarantees and is explicitly unsupported.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
Public API Surface
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
The supported public API consists of the following top-level modules:
|
The supported public API consists of the following top-level modules:
|
||||||
|
|
||||||
- openapi_first.app
|
- `openapi_first.app`
|
||||||
- openapi_first.binder
|
- `openapi_first.binder`
|
||||||
- openapi_first.loader
|
- `openapi_first.loader`
|
||||||
- openapi_first.client
|
- `openapi_first.client`
|
||||||
- openapi_first.errors
|
- `openapi_first.errors`
|
||||||
|
|
||||||
Classes and functions should be imported explicitly from these modules.
|
---
|
||||||
No individual symbols are re-exported at the package root.
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
## Design Guarantees
|
||||||
Design Guarantees
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
- OpenAPI is the single source of truth
|
- OpenAPI is the single source of truth
|
||||||
- No undocumented routes can exist
|
- No undocumented routes can exist
|
||||||
@@ -201,31 +85,8 @@ Design Guarantees
|
|||||||
- All contract violations fail at application startup or client creation
|
- All contract violations fail at application startup or client creation
|
||||||
- No hidden FastAPI magic or implicit behavior
|
- No hidden FastAPI magic or implicit behavior
|
||||||
- Deterministic, testable application assembly
|
- Deterministic, testable application assembly
|
||||||
- CI-friendly failure modes
|
|
||||||
|
|
||||||
FastAPI OpenAPI First favors correctness, explicitness, and contract
|
---
|
||||||
enforcement over convenience shortcuts.
|
|
||||||
|
|
||||||
## Core Philosophy
|
|
||||||
|
|
||||||
`FastAPI OpenAPI First` operates on the **Contract-as-Code** principle:
|
|
||||||
|
|
||||||
1. **Spec-Driven Routing**: The OpenAPI document *is* the router. Code only exists to fulfill established contracts.
|
|
||||||
2. **Startup Fail-Fast**: Binding mismatches (missing handlers or extra operations) are detected during app initialization, not at runtime.
|
|
||||||
3. **Decoupled Symmetry**: The same specification drives both the FastAPI server and the `httpx`-based client, ensuring type-safe communication.
|
|
||||||
|
|
||||||
## Documentation Design
|
|
||||||
|
|
||||||
Follow these "AI-Native" docstring principles to maximize developer and agent productivity:
|
|
||||||
|
|
||||||
### For Humans
|
|
||||||
- **Logical Grouping**: Document the Loader, Binder, and Client as distinct infrastructure layers.
|
|
||||||
- **Spec Snippets**: Always include the corresponding OpenAPI YAML/JSON snippet alongside Python examples.
|
|
||||||
|
|
||||||
### For LLMs
|
|
||||||
- **Full Path Linking**: Refer to cross-module dependencies using their full dotted paths (e.g., `openapi_first.loader.load_openapi`).
|
|
||||||
- **Complete Stubs**: Maintain high-fidelity `.pyi` stubs for all public interfaces to provide an optimized machine-context.
|
|
||||||
- **Traceable Errors**: Use specific `: description` pairs in `Raises` blocks to allow agents to accurately map errors to spec violations.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from . import app
|
from . import app
|
||||||
|
|||||||
@@ -1,43 +1,32 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.app
|
|
||||||
=========================
|
|
||||||
|
|
||||||
OpenAPI-first application bootstrap for FastAPI.
|
OpenAPI-first application bootstrap for FastAPI.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
This module provides `OpenAPIFirstApp`, a thin but strict abstraction
|
This module provides `OpenAPIFirstApp`, a thin but strict abstraction
|
||||||
that enforces OpenAPI as the single source of truth for a FastAPI service.
|
that enforces OpenAPI as the single source of truth for a FastAPI service.
|
||||||
|
|
||||||
Core principles
|
Notes:
|
||||||
---------------
|
**Core Principles:**
|
||||||
- The OpenAPI specification (JSON or YAML) defines the entire API surface.
|
|
||||||
- Every operationId in the OpenAPI spec must have a corresponding
|
|
||||||
Python handler function.
|
|
||||||
- Handlers are plain Python callables (no FastAPI decorators).
|
|
||||||
- FastAPI route registration is derived exclusively from the spec.
|
|
||||||
- FastAPI's autogenerated OpenAPI schema is fully overridden.
|
|
||||||
|
|
||||||
What this module does
|
- The OpenAPI specification (JSON or YAML) defines the entire API surface
|
||||||
---------------------
|
- Every operationId in the OpenAPI spec must have a corresponding Python handler function
|
||||||
- Loads and validates an OpenAPI 3.x specification.
|
- Handlers are plain Python callables (no FastAPI decorators)
|
||||||
- Dynamically binds HTTP routes to handler functions using operationId.
|
- FastAPI route registration is derived exclusively from the spec
|
||||||
- Registers routes with FastAPI at application startup.
|
- FastAPI's autogenerated OpenAPI schema is fully overridden
|
||||||
- Ensures runtime behavior matches the OpenAPI contract exactly.
|
|
||||||
|
|
||||||
What this module does NOT do
|
**Responsibilities:**
|
||||||
----------------------------
|
|
||||||
- It does not generate OpenAPI specs.
|
|
||||||
- It does not generate client code.
|
|
||||||
- It does not introduce a new framework or lifecycle.
|
|
||||||
- It does not alter FastAPI dependency injection semantics.
|
|
||||||
|
|
||||||
Intended usage
|
- Loads and validates an OpenAPI 3.x specification
|
||||||
--------------
|
- Dynamically binds HTTP routes to handler functions using operationId
|
||||||
This module is intended for teams that want:
|
- Registers routes with FastAPI at application startup
|
||||||
|
- Ensures runtime behavior matches the OpenAPI contract exactly
|
||||||
|
|
||||||
- OpenAPI-first API development
|
**Constraints:**
|
||||||
- Strong contract enforcement
|
|
||||||
- Minimal FastAPI boilerplate
|
- This module intentionally does NOT: Generate OpenAPI specs, generate client code, introduce a new framework or lifecycle, or alter FastAPI dependency injection semantics.
|
||||||
- Predictable, CI-friendly failures for spec/implementation drift
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
@@ -50,50 +39,30 @@ class OpenAPIFirstApp(FastAPI):
|
|||||||
"""
|
"""
|
||||||
FastAPI application enforcing OpenAPI-first design.
|
FastAPI application enforcing OpenAPI-first design.
|
||||||
|
|
||||||
`OpenAPIFirstApp` subclasses FastAPI and replaces manual route
|
Notes:
|
||||||
registration with OpenAPI-driven binding. All routes are derived
|
**Responsibilities:**
|
||||||
from the provided OpenAPI specification, and each operationId is
|
|
||||||
mapped to a Python function in the supplied routes module.
|
|
||||||
|
|
||||||
Parameters
|
- `OpenAPIFirstApp` subclasses FastAPI and replaces manual route registration with OpenAPI-driven binding
|
||||||
----------
|
- All routes are derived from the provided OpenAPI specification, and each operationId is mapped to a Python function in the supplied routes module
|
||||||
openapi_path : str
|
|
||||||
Filesystem path to the OpenAPI 3.x specification file.
|
|
||||||
This specification is treated as the authoritative API contract.
|
|
||||||
|
|
||||||
routes_module : module
|
**Guarantees:**
|
||||||
Python module containing handler functions whose names correspond
|
|
||||||
exactly to OpenAPI operationId values.
|
|
||||||
|
|
||||||
**fastapi_kwargs
|
- No route can exist without an OpenAPI declaration
|
||||||
Additional keyword arguments passed directly to `fastapi.FastAPI`
|
- No OpenAPI operation can exist without a handler
|
||||||
(e.g., title, version, middleware, lifespan handlers).
|
- Swagger UI and `/openapi.json` always reflect the provided spec
|
||||||
|
- Handler functions remain framework-agnostic and testable
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```python
|
||||||
|
from openapi_first import OpenAPIFirstApp
|
||||||
|
import app.routes as routes
|
||||||
|
|
||||||
Raises
|
app = OpenAPIFirstApp(
|
||||||
------
|
openapi_path="app/openapi.json",
|
||||||
OpenAPIFirstError
|
routes_module=routes,
|
||||||
If the OpenAPI specification is invalid, or if any declared
|
title="Example Service",
|
||||||
operationId does not have a corresponding handler function.
|
)
|
||||||
|
```
|
||||||
Behavior guarantees
|
|
||||||
-------------------
|
|
||||||
- No route can exist without an OpenAPI declaration.
|
|
||||||
- No OpenAPI operation can exist without a handler.
|
|
||||||
- Swagger UI and `/openapi.json` always reflect the provided spec.
|
|
||||||
- Handler functions remain framework-agnostic and testable.
|
|
||||||
|
|
||||||
Example
|
|
||||||
-------
|
|
||||||
```python
|
|
||||||
from openapi_first import OpenAPIFirstApp
|
|
||||||
import app.routes as routes
|
|
||||||
|
|
||||||
app = OpenAPIFirstApp(
|
|
||||||
openapi_path="app/openapi.json",
|
|
||||||
routes_module=routes,
|
|
||||||
title="Example Service",
|
|
||||||
)
|
|
||||||
```
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -103,6 +72,21 @@ class OpenAPIFirstApp(FastAPI):
|
|||||||
routes_module,
|
routes_module,
|
||||||
**fastapi_kwargs,
|
**fastapi_kwargs,
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Initialize the application.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
openapi_path (str):
|
||||||
|
Filesystem path to the OpenAPI 3.x specification file. This specification is treated as the authoritative API contract.
|
||||||
|
routes_module (module):
|
||||||
|
Python module containing handler functions whose names correspond exactly to OpenAPI operationId values.
|
||||||
|
**fastapi_kwargs (Any):
|
||||||
|
Additional keyword arguments passed directly to `fastapi.FastAPI` (e.g., title, version, middleware, lifespan handlers).
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
OpenAPIFirstError:
|
||||||
|
If the OpenAPI specification is invalid, or if any declared operationId does not have a corresponding handler function.
|
||||||
|
"""
|
||||||
# Initialize FastAPI normally
|
# Initialize FastAPI normally
|
||||||
super().__init__(**fastapi_kwargs)
|
super().__init__(**fastapi_kwargs)
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,33 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.binder
|
|
||||||
============================
|
|
||||||
|
|
||||||
OpenAPI-driven route binding for FastAPI.
|
OpenAPI-driven route binding for FastAPI.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
This module is responsible for translating an OpenAPI 3.x specification
|
This module is responsible for translating an OpenAPI 3.x specification
|
||||||
into concrete FastAPI routes. It enforces a strict one-to-one mapping
|
into concrete FastAPI routes. It enforces a strict one-to-one mapping
|
||||||
between OpenAPI operations and Python handler functions using operationId.
|
between OpenAPI operations and Python handler functions using operationId.
|
||||||
|
|
||||||
Core responsibility
|
Notes:
|
||||||
-------------------
|
**Core Responsibility:**
|
||||||
- Read path + method definitions from an OpenAPI specification
|
|
||||||
- Resolve each operationId to a Python callable
|
|
||||||
- Register routes with FastAPI using APIRoute
|
|
||||||
- Fail fast when contract violations are detected
|
|
||||||
|
|
||||||
Design constraints
|
- Read path + method definitions from an OpenAPI specification
|
||||||
------------------
|
- Resolve each operationId to a Python callable
|
||||||
- All routes MUST be declared in the OpenAPI specification.
|
- Register routes with FastAPI using APIRoute
|
||||||
- All OpenAPI operations MUST define an operationId.
|
- Fail fast when contract violations are detected
|
||||||
- Every operationId MUST resolve to a handler function.
|
|
||||||
- Handlers are plain Python callables (no decorators required).
|
|
||||||
- No implicit route creation or inference is allowed.
|
|
||||||
|
|
||||||
This module intentionally does NOT:
|
**Design Constraints:**
|
||||||
-------------------------------
|
|
||||||
- Perform request or response validation
|
|
||||||
- Generate Pydantic models
|
|
||||||
- Modify FastAPI dependency injection
|
|
||||||
- Interpret OpenAPI semantics beyond routing metadata
|
|
||||||
|
|
||||||
Those concerns belong to other layers or tooling.
|
- All routes MUST be declared in the OpenAPI specification
|
||||||
|
- All OpenAPI operations MUST define an operationId
|
||||||
|
- Every operationId MUST resolve to a handler function
|
||||||
|
- Handlers are plain Python callables (no decorators required)
|
||||||
|
- No implicit route creation or inference is allowed
|
||||||
|
|
||||||
|
**Constraints:**
|
||||||
|
|
||||||
|
- This module intentionally does NOT: Perform request or response validation, generate Pydantic models, modify FastAPI dependency injection, or interpret OpenAPI semantics beyond routing metadata.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi.routing import APIRoute
|
from fastapi.routing import APIRoute
|
||||||
@@ -42,33 +39,27 @@ def bind_routes(app, spec: dict, routes_module) -> None:
|
|||||||
"""
|
"""
|
||||||
Bind OpenAPI operations to FastAPI routes.
|
Bind OpenAPI operations to FastAPI routes.
|
||||||
|
|
||||||
Iterates through the OpenAPI specification paths and methods,
|
Args:
|
||||||
resolves each operationId to a handler function, and registers
|
app (fastapi.FastAPI):
|
||||||
a corresponding APIRoute on the FastAPI application.
|
The FastAPI application instance to which routes will be added.
|
||||||
|
spec (dict):
|
||||||
|
Parsed OpenAPI 3.x specification dictionary.
|
||||||
|
routes_module (module):
|
||||||
|
Python module containing handler functions. Each handler's name MUST exactly match an OpenAPI operationId.
|
||||||
|
|
||||||
Parameters
|
Raises:
|
||||||
----------
|
MissingOperationHandler:
|
||||||
app : fastapi.FastAPI
|
If an operationId is missing from the spec or if no corresponding handler function exists in the routes module.
|
||||||
The FastAPI application instance to which routes will be added.
|
|
||||||
|
|
||||||
spec : dict
|
Notes:
|
||||||
Parsed OpenAPI 3.x specification dictionary.
|
**Responsibilities:**
|
||||||
|
|
||||||
routes_module : module
|
- Iterates through the OpenAPI specification paths and methods
|
||||||
Python module containing handler functions. Each handler's
|
- Resolves each operationId to a handler function, and registers a corresponding APIRoute on the FastAPI application
|
||||||
name MUST exactly match an OpenAPI operationId.
|
|
||||||
|
|
||||||
Raises
|
**Guarantees:**
|
||||||
------
|
|
||||||
MissingOperationHandler
|
|
||||||
If an operationId is missing from the spec or if no corresponding
|
|
||||||
handler function exists in the routes module.
|
|
||||||
|
|
||||||
Behavior guarantees
|
- Route registration is deterministic and spec-driven. No route decorators are required or supported. Handler resolution errors surface at application startup.
|
||||||
-------------------
|
|
||||||
- Route registration is deterministic and spec-driven.
|
|
||||||
- No route decorators are required or supported.
|
|
||||||
- Handler resolution errors surface at application startup.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
paths = spec.get("paths", {})
|
paths = spec.get("paths", {})
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.cli
|
|
||||||
========================
|
|
||||||
|
|
||||||
Command-line interface for FastAPI OpenAPI-first scaffolding utilities.
|
Command-line interface for FastAPI OpenAPI-first scaffolding utilities.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
This CLI bootstraps OpenAPI-first FastAPI applications from versioned,
|
This CLI bootstraps OpenAPI-first FastAPI applications from versioned,
|
||||||
bundled templates packaged with the library.
|
bundled templates packaged with the library.
|
||||||
"""
|
"""
|
||||||
@@ -20,6 +21,10 @@ DEFAULT_TEMPLATE = "health_app"
|
|||||||
def available_templates() -> list[str]:
|
def available_templates() -> list[str]:
|
||||||
"""
|
"""
|
||||||
Return a list of available application templates.
|
Return a list of available application templates.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]:
|
||||||
|
Sorted list of template names found in the internal templates directory.
|
||||||
"""
|
"""
|
||||||
root = resources.files("openapi_first.templates")
|
root = resources.files("openapi_first.templates")
|
||||||
return sorted(
|
return sorted(
|
||||||
@@ -32,6 +37,16 @@ def available_templates() -> list[str]:
|
|||||||
def copy_template(template: str, target_dir: Path) -> None:
|
def copy_template(template: str, target_dir: Path) -> None:
|
||||||
"""
|
"""
|
||||||
Copy a bundled OpenAPI-first application template into a directory.
|
Copy a bundled OpenAPI-first application template into a directory.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
template (str):
|
||||||
|
Name of the template to copy.
|
||||||
|
target_dir (Path):
|
||||||
|
Filesystem path where the template should be copied.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FileNotFoundError:
|
||||||
|
If the requested template does not exist.
|
||||||
"""
|
"""
|
||||||
target_dir = target_dir.resolve()
|
target_dir = target_dir.resolve()
|
||||||
target_dir.mkdir(parents=True, exist_ok=True)
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
@@ -1,59 +1,36 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.client
|
|
||||||
====================
|
|
||||||
|
|
||||||
OpenAPI-first HTTP client for contract-driven services.
|
OpenAPI-first HTTP client for contract-driven services.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
This module provides `OpenAPIClient`, a thin, strict HTTP client that
|
This module provides `OpenAPIClient`, a thin, strict HTTP client that
|
||||||
derives all callable operations directly from an OpenAPI 3.x specification.
|
derives all callable operations directly from an OpenAPI 3.x specification.
|
||||||
|
|
||||||
It is the client counterpart to `OpenAPIFirstApp`.
|
It is the client counterpart to `OpenAPIFirstApp`.
|
||||||
|
|
||||||
Core principles
|
Notes:
|
||||||
---------------
|
**Core Principles:**
|
||||||
- The OpenAPI specification is the single source of truth.
|
|
||||||
- Each operationId becomes a callable Python method.
|
|
||||||
- No implicit schema mutation or inference.
|
|
||||||
- No code generation step.
|
|
||||||
- Minimal abstraction over httpx.
|
|
||||||
|
|
||||||
What this module does
|
- The OpenAPI specification is the single source of truth
|
||||||
---------------------
|
- Each operationId becomes a callable Python method
|
||||||
- Parses an OpenAPI 3.x specification.
|
- No implicit schema mutation or inference
|
||||||
- Dynamically creates one callable per operationId.
|
- No code generation step
|
||||||
- Enforces presence of:
|
- Minimal abstraction over httpx
|
||||||
- servers
|
|
||||||
- paths
|
|
||||||
- operationId
|
|
||||||
- Formats path parameters safely.
|
|
||||||
- Handles JSON request bodies explicitly.
|
|
||||||
- Returns raw `httpx.Response` objects.
|
|
||||||
|
|
||||||
What this module does NOT do
|
**Responsibilities:**
|
||||||
----------------------------
|
|
||||||
- It does not generate client code.
|
|
||||||
- It does not validate request/response schemas.
|
|
||||||
- It does not deserialize responses.
|
|
||||||
- It does not retry requests.
|
|
||||||
- It does not implement authentication helpers.
|
|
||||||
- It does not assume non-2xx responses are failures.
|
|
||||||
|
|
||||||
Intended usage
|
- Parses an OpenAPI 3.x specification
|
||||||
--------------
|
- Dynamically creates one callable per operationId
|
||||||
This client is designed for:
|
- Enforces presence of servers, paths, and operationId
|
||||||
|
- Formats path parameters safely
|
||||||
|
- Handles JSON request bodies explicitly
|
||||||
|
- Returns raw `httpx.Response` objects
|
||||||
|
|
||||||
- Service-to-service communication
|
**Constraints:**
|
||||||
- Integration testing
|
|
||||||
- Contract-driven internal SDK usage
|
|
||||||
- Systems that want OpenAPI-first symmetry with `OpenAPIFirstApp`
|
|
||||||
|
|
||||||
Design constraints
|
- This module intentionally does NOT: Generate client code, validate request/response schemas, deserialize responses, retry requests, implement authentication helpers, or assume non-2xx responses are failures.
|
||||||
------------------
|
|
||||||
- Only the first server in the OpenAPI `servers` list is used if
|
|
||||||
`base_url` is not explicitly provided.
|
|
||||||
- Only explicitly declared request bodies are allowed.
|
|
||||||
- `application/json` is handled natively; other media types are sent as raw content.
|
|
||||||
- All responses are returned as-is.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Any, Callable, Dict, Optional
|
from typing import Any, Callable, Dict, Optional
|
||||||
@@ -65,73 +42,47 @@ from .errors import OpenAPIFirstError
|
|||||||
|
|
||||||
|
|
||||||
class OpenAPIClientError(OpenAPIFirstError):
|
class OpenAPIClientError(OpenAPIFirstError):
|
||||||
"""Raised when an OpenAPI client operation fails."""
|
"""
|
||||||
|
Raised when an OpenAPI client operation fails.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class OpenAPIClient:
|
class OpenAPIClient:
|
||||||
"""
|
"""
|
||||||
OpenAPI-first HTTP client (httpx-based).
|
OpenAPI-first HTTP client (httpx-based).
|
||||||
|
|
||||||
This client derives all callable methods directly from an OpenAPI 3.x
|
Notes:
|
||||||
specification. Each operationId becomes a method on the client
|
**Responsibilities:**
|
||||||
instance.
|
|
||||||
|
|
||||||
Design principles
|
- This client derives all callable methods directly from an OpenAPI 3.x specification. Each operationId becomes a method on the client instance.
|
||||||
-----------------
|
|
||||||
- One callable per operationId
|
|
||||||
- Explicit parameters (path, query, headers, body)
|
|
||||||
- No implicit schema inference or mutation
|
|
||||||
- Returns raw httpx.Response objects
|
|
||||||
- No response validation or deserialization
|
|
||||||
|
|
||||||
Parameters
|
**Guarantees:**
|
||||||
----------
|
|
||||||
spec : dict
|
|
||||||
Parsed OpenAPI 3.x specification.
|
|
||||||
base_url : str | None
|
|
||||||
Base URL of the target service. If omitted, the first entry
|
|
||||||
in the OpenAPI `servers` list is used.
|
|
||||||
client : httpx.Client | None
|
|
||||||
Optional preconfigured httpx client instance.
|
|
||||||
|
|
||||||
Raises
|
- One callable per operationId
|
||||||
------
|
- Explicit parameters (path, query, headers, body)
|
||||||
OpenAPIClientError
|
- No implicit schema inference or mutation
|
||||||
If:
|
- Returns raw `httpx.Response` objects
|
||||||
- No servers are defined and base_url is not provided
|
- No response validation or deserialization
|
||||||
- OpenAPI spec has no paths
|
|
||||||
- An operation is missing operationId
|
|
||||||
- Duplicate operationIds are detected
|
|
||||||
- Required path parameters are missing
|
|
||||||
- Required request body is missing
|
|
||||||
|
|
||||||
Example
|
Example:
|
||||||
-------
|
```python
|
||||||
```python
|
from openapi_first import loader, client
|
||||||
from openapi_first import loader, client
|
|
||||||
|
|
||||||
spec = loader.load_openapi("openapi.yaml")
|
spec = loader.load_openapi("openapi.yaml")
|
||||||
|
|
||||||
api = client.OpenAPIClient(
|
api = client.OpenAPIClient(
|
||||||
spec=spec,
|
spec=spec,
|
||||||
base_url="http://localhost:8000",
|
base_url="http://localhost:8000",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Call operationId: getUser
|
# Call operationId: getUser
|
||||||
response = api.getUser(
|
response = api.getUser(
|
||||||
path_params={"user_id": 123}
|
path_params={"user_id": 123}
|
||||||
)
|
)
|
||||||
|
|
||||||
print(response.status_code)
|
print(response.status_code)
|
||||||
print(response.json())
|
print(response.json())
|
||||||
|
```
|
||||||
# Call operationId: createUser
|
|
||||||
response = api.createUser(
|
|
||||||
body={"name": "Bob"}
|
|
||||||
)
|
|
||||||
|
|
||||||
print(response.status_code)
|
|
||||||
```
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -140,6 +91,21 @@ class OpenAPIClient:
|
|||||||
base_url: Optional[str] = None,
|
base_url: Optional[str] = None,
|
||||||
client: Optional[httpx.Client] = None,
|
client: Optional[httpx.Client] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""
|
||||||
|
Initialize the OpenAPI client.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
spec (dict[str, Any]):
|
||||||
|
Parsed OpenAPI 3.x specification.
|
||||||
|
base_url (str, optional):
|
||||||
|
Base URL of the target service. If omitted, the first entry in the OpenAPI `servers` list is used.
|
||||||
|
client (httpx.Client, optional):
|
||||||
|
Optional preconfigured httpx client instance.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
OpenAPIClientError:
|
||||||
|
If no servers are defined, spec has no paths, operationIds are missing/duplicate, or required parameters are missing.
|
||||||
|
"""
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
self.base_url = base_url or self._resolve_base_url(spec)
|
self.base_url = base_url or self._resolve_base_url(spec)
|
||||||
self.client = client or httpx.Client(base_url=self.base_url)
|
self.client = client or httpx.Client(base_url=self.base_url)
|
||||||
|
|||||||
@@ -1,33 +1,34 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.errors
|
Exceptions for OpenAPI-first FastAPI applications.
|
||||||
============================
|
|
||||||
|
|
||||||
Custom exceptions for OpenAPI-first FastAPI applications.
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
This module defines a small hierarchy of explicit, intention-revealing
|
This module defines a small hierarchy of explicit, intention-revealing
|
||||||
exceptions used to signal contract violations between an OpenAPI
|
exceptions used to signal contract violations between an OpenAPI
|
||||||
specification and its Python implementation.
|
specification and its Python implementation.
|
||||||
|
|
||||||
Design principles
|
Notes:
|
||||||
-----------------
|
**Design Principles:**
|
||||||
- Errors represent *programmer mistakes*, not runtime conditions.
|
|
||||||
- All errors are raised during application startup.
|
|
||||||
- Messages are actionable and suitable for CI/CD output.
|
|
||||||
- Exceptions are explicit rather than reused from generic built-ins.
|
|
||||||
|
|
||||||
These errors should normally cause immediate application failure.
|
- Errors represent programmer mistakes, not runtime conditions
|
||||||
|
- All errors are raised during application startup
|
||||||
|
- Messages are actionable and suitable for CI/CD output
|
||||||
|
- Exceptions are explicit rather than reused from generic built-ins
|
||||||
|
|
||||||
|
These errors should normally cause immediate application failure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class OpenAPIFirstError(Exception):
|
class OpenAPIFirstError(Exception):
|
||||||
"""
|
"""
|
||||||
Base exception for all OpenAPI-first enforcement errors.
|
Base exception for all OpenAPI-first enforcement errors.
|
||||||
|
|
||||||
This exception exists to allow callers, test suites, and CI pipelines
|
Notes:
|
||||||
to catch and distinguish OpenAPI contract violations from unrelated
|
**Responsibilities:**
|
||||||
runtime errors.
|
|
||||||
|
|
||||||
All exceptions raised by the OpenAPI-first core should inherit from
|
- This exception exists to allow callers, test suites, and CI pipelines to catch and distinguish OpenAPI contract violations from unrelated runtime errors
|
||||||
this type.
|
- All exceptions raised by the OpenAPI-first core should inherit from this type
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -36,27 +37,28 @@ class MissingOperationHandler(OpenAPIFirstError):
|
|||||||
"""
|
"""
|
||||||
Raised when an OpenAPI operation cannot be resolved to a handler.
|
Raised when an OpenAPI operation cannot be resolved to a handler.
|
||||||
|
|
||||||
This error occurs when:
|
Notes:
|
||||||
- An OpenAPI operation does not define an operationId, or
|
**Scenarios:**
|
||||||
- An operationId is defined but no matching function exists in the
|
|
||||||
provided routes module.
|
|
||||||
|
|
||||||
This represents a violation of the OpenAPI-first contract and
|
- An OpenAPI operation does not define an operationId
|
||||||
indicates that the specification and implementation are out of sync.
|
- An operationId is defined but no matching function exists in the provided routes module
|
||||||
|
|
||||||
|
**Guarantees:**
|
||||||
|
|
||||||
|
- This represents a violation of the OpenAPI-first contract and indicates that the specification and implementation are out of sync
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *, path: str, method: str, operation_id: str | None = None):
|
def __init__(self, *, path: str, method: str, operation_id: str | None = None):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Initialize the error.
|
||||||
----------
|
|
||||||
path : str
|
|
||||||
The HTTP path declared in the OpenAPI specification.
|
|
||||||
|
|
||||||
method : str
|
Args:
|
||||||
The HTTP method (as declared in the OpenAPI spec).
|
path (str):
|
||||||
|
The HTTP path declared in the OpenAPI specification.
|
||||||
operation_id : str, optional
|
method (str):
|
||||||
The operationId declared in the OpenAPI spec, if present.
|
The HTTP method (as declared in the OpenAPI spec).
|
||||||
|
operation_id (str, optional):
|
||||||
|
The operationId declared in the OpenAPI spec, if present.
|
||||||
"""
|
"""
|
||||||
if operation_id:
|
if operation_id:
|
||||||
message = (
|
message = (
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
"""
|
"""
|
||||||
openapi_first.loaders
|
|
||||||
=============================
|
|
||||||
|
|
||||||
OpenAPI specification loading and validation utilities.
|
OpenAPI specification loading and validation utilities.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
This module is responsible for loading an OpenAPI 3.x specification
|
This module is responsible for loading an OpenAPI 3.x specification
|
||||||
from disk and validating it before it is used by the application.
|
from disk and validating it before it is used by the application.
|
||||||
|
|
||||||
It enforces the principle that an invalid or malformed OpenAPI document
|
It enforces the principle that an invalid or malformed OpenAPI document
|
||||||
must never reach the routing or runtime layers.
|
must never reach the routing or runtime layers.
|
||||||
|
|
||||||
Design principles
|
Notes:
|
||||||
-----------------
|
**Design Principles:**
|
||||||
- OpenAPI is treated as an authoritative contract.
|
|
||||||
- Invalid specifications fail fast at application startup.
|
|
||||||
- Supported formats are JSON and YAML.
|
|
||||||
- Validation errors are surfaced clearly and early.
|
|
||||||
|
|
||||||
This module intentionally does NOT:
|
- OpenAPI is treated as an authoritative contract
|
||||||
-----------------------------------
|
- Invalid specifications fail fast at application startup
|
||||||
- Modify the OpenAPI document
|
- Supported formats are JSON and YAML
|
||||||
- Infer missing fields
|
- Validation errors are surfaced clearly and early
|
||||||
- Generate models or code
|
|
||||||
- Perform request/response validation at runtime
|
**Constraints:**
|
||||||
|
|
||||||
|
- This module intentionally does NOT: Modify the OpenAPI document, infer missing fields, generate models or code, or perform request/response validation at runtime.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@@ -39,8 +38,10 @@ class OpenAPISpecLoadError(OpenAPIFirstError):
|
|||||||
"""
|
"""
|
||||||
Raised when an OpenAPI specification cannot be loaded or validated.
|
Raised when an OpenAPI specification cannot be loaded or validated.
|
||||||
|
|
||||||
This error indicates that the OpenAPI document is unreadable,
|
Notes:
|
||||||
malformed, or violates the OpenAPI 3.x specification.
|
**Guarantees:**
|
||||||
|
|
||||||
|
- This error indicates that the OpenAPI document is unreadable, malformed, or violates the OpenAPI 3.x specification
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -49,29 +50,23 @@ def load_openapi(path: str | Path) -> dict[str, Any]:
|
|||||||
"""
|
"""
|
||||||
Load and validate an OpenAPI 3.x specification from disk.
|
Load and validate an OpenAPI 3.x specification from disk.
|
||||||
|
|
||||||
The specification is parsed based on file extension and validated
|
Args:
|
||||||
using a strict OpenAPI schema validator. Any error results in an
|
path (str | Path):
|
||||||
immediate exception, preventing application startup.
|
Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.
|
||||||
|
|
||||||
Parameters
|
Returns:
|
||||||
----------
|
dict[str, Any]:
|
||||||
path : str or pathlib.Path
|
Parsed and validated OpenAPI specification.
|
||||||
Filesystem path to an OpenAPI specification file.
|
|
||||||
Supported extensions:
|
|
||||||
- `.json`
|
|
||||||
- `.yaml`
|
|
||||||
- `.yml`
|
|
||||||
|
|
||||||
Returns
|
Raises:
|
||||||
-------
|
OpenAPISpecLoadError:
|
||||||
dict
|
If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.
|
||||||
Parsed and validated OpenAPI specification.
|
|
||||||
|
|
||||||
Raises
|
Notes:
|
||||||
------
|
**Guarantees:**
|
||||||
OpenAPISpecLoadError
|
|
||||||
If the file does not exist, cannot be parsed, or fails
|
- The specification is parsed based on file extension and validated using a strict OpenAPI schema validator
|
||||||
OpenAPI schema validation.
|
- Any error results in an immediate exception, preventing application startup
|
||||||
"""
|
"""
|
||||||
spec_path = Path(path)
|
spec_path = Path(path)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user