google styled doc

This commit is contained in:
2026-03-08 00:29:23 +05:30
parent 37b892f695
commit f03e250763
7 changed files with 261 additions and 447 deletions

View File

@@ -1,28 +1,27 @@
"""
openapi_first.loaders
=============================
OpenAPI specification loading and validation utilities.
---
## Summary
This module is responsible for loading an OpenAPI 3.x specification
from disk and validating it before it is used by the application.
It enforces the principle that an invalid or malformed OpenAPI document
must never reach the routing or runtime layers.
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.
Notes:
**Design Principles:**
This module intentionally does NOT:
-----------------------------------
- Modify the OpenAPI document
- Infer missing fields
- Generate models or code
- Perform request/response validation at runtime
- 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
**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
@@ -39,8 +38,10 @@ class OpenAPISpecLoadError(OpenAPIFirstError):
"""
Raised when an OpenAPI specification cannot be loaded or validated.
This error indicates that the OpenAPI document is unreadable,
malformed, or violates the OpenAPI 3.x specification.
Notes:
**Guarantees:**
- This error indicates that the OpenAPI document is unreadable, malformed, or violates the OpenAPI 3.x specification
"""
pass
@@ -49,29 +50,23 @@ def load_openapi(path: str | Path) -> dict[str, Any]:
"""
Load and validate an OpenAPI 3.x specification from disk.
The specification is parsed based on file extension and validated
using a strict OpenAPI schema validator. Any error results in an
immediate exception, preventing application startup.
Args:
path (str | Path):
Filesystem path to an OpenAPI specification file. Supported extensions: .json, .yaml, .yml.
Parameters
----------
path : str or pathlib.Path
Filesystem path to an OpenAPI specification file.
Supported extensions:
- `.json`
- `.yaml`
- `.yml`
Returns:
dict[str, Any]:
Parsed and validated OpenAPI specification.
Returns
-------
dict
Parsed and validated OpenAPI specification.
Raises:
OpenAPISpecLoadError:
If the file does not exist, cannot be parsed, or fails OpenAPI schema validation.
Raises
------
OpenAPISpecLoadError
If the file does not exist, cannot be parsed, or fails
OpenAPI schema validation.
Notes:
**Guarantees:**
- The specification is parsed based on file extension and validated using a strict OpenAPI schema validator
- Any error results in an immediate exception, preventing application startup
"""
spec_path = Path(path)