fix: resolve CI linting violations
Some checks failed
CI / test (push) Has been cancelled

- Fixed import sorting in cli.py, __main__.py, detectors/__init__.py, base.py, python.py, rust.py, openapi.py, models/__init__.py
- Removed unused imports (sys, asyncio, Observer, Text, Parameter, ParameterIn, HTTPMethod, DocConfig, List, Optional)
- Removed trailing whitespace from blank lines
- Split lines exceeding 100 characters
- Added missing __init__ docstrings in generators and static/templates packages
This commit is contained in:
2026-01-31 17:26:17 +00:00
parent a130a2303a
commit 4dd9fc9f5b

View File

@@ -1,10 +1,11 @@
"""OpenAPI documentation generator.""" {"""OpenAPI documentation generator."""
import json import json
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from docgen.models import DocConfig, Endpoint, HTTPMethod
from docgen.generators import BaseGenerator from docgen.generators import BaseGenerator
from docgen.models import Endpoint
class OpenAPIGenerator(BaseGenerator): class OpenAPIGenerator(BaseGenerator):
@@ -35,7 +36,7 @@ class OpenAPIGenerator(BaseGenerator):
for endpoint in endpoints: for endpoint in endpoints:
path_item = self._endpoint_to_path_item(endpoint) path_item = self._endpoint_to_path_item(endpoint)
if endpoint.path not in spec["paths"]: if endpoint.path not in spec["paths"]:
spec["paths"][endpoint.path] = path_item spec["paths"][endpoint.path] = path_item
else: else:
@@ -49,11 +50,13 @@ class OpenAPIGenerator(BaseGenerator):
def _endpoint_to_path_item(self, endpoint: Endpoint) -> dict[str, Any]: def _endpoint_to_path_item(self, endpoint: Endpoint) -> dict[str, Any]:
"""Convert an Endpoint to OpenAPI path item.""" """Convert an Endpoint to OpenAPI path item."""
method = endpoint.method.value.lower() method = endpoint.method.value.lower()
operation = { operation = {
"summary": endpoint.summary or f"{endpoint.method.value} {endpoint.path}", "summary": endpoint.summary or f"{endpoint.method.value} {endpoint.path}",
"description": endpoint.description, "description": endpoint.description,
"operationId": endpoint.operation_id or f"{method}_{endpoint.path.replace('/', '_').strip('_')}", "operationId": endpoint.operation_id or self._make_operation_id(
method, endpoint.path
),
"deprecated": endpoint.deprecated, "deprecated": endpoint.deprecated,
"parameters": [self._param_to_openapi(p) for p in endpoint.parameters], "parameters": [self._param_to_openapi(p) for p in endpoint.parameters],
"responses": self._build_responses(endpoint.responses), "responses": self._build_responses(endpoint.responses),
@@ -64,6 +67,10 @@ class OpenAPIGenerator(BaseGenerator):
return {method: operation} return {method: operation}
def _make_operation_id(self, method: str, path: str) -> str:
"""Generate a unique operation ID from method and path."""
return f"{method}_{path.replace('/', '_').strip('_')}"
def _param_to_openapi(self, param) -> dict[str, Any]: def _param_to_openapi(self, param) -> dict[str, Any]:
"""Convert Parameter to OpenAPI parameter.""" """Convert Parameter to OpenAPI parameter."""
return { return {
@@ -82,7 +89,7 @@ class OpenAPIGenerator(BaseGenerator):
"200": {"description": "Successful response"}, "200": {"description": "Successful response"},
"default": {"description": "Error response"}, "default": {"description": "Error response"},
} }
result = {} result = {}
for resp in responses: for resp in responses:
resp_obj = {"description": resp.description} resp_obj = {"description": resp.description}
@@ -91,5 +98,5 @@ class OpenAPIGenerator(BaseGenerator):
resp.content_type: {"schema": resp.example} resp.content_type: {"schema": resp.example}
} }
result[str(resp.status_code)] = resp_obj result[str(resp.status_code)] = resp_obj
return result return result