mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 18:00:36 +00:00
add 204s
This commit is contained in:
parent
e3e8272bbe
commit
277bec9c9a
7 changed files with 112 additions and 210 deletions
|
|
@ -62,6 +62,7 @@ def generate_openapi_spec(output_dir: str) -> dict[str, Any]:
|
|||
|
||||
# Clean descriptions in schema definitions by removing docstring metadata
|
||||
openapi_schema = schema_transforms._clean_schema_descriptions(openapi_schema)
|
||||
openapi_schema = schema_transforms._normalize_empty_responses(openapi_schema)
|
||||
|
||||
# Remove query parameters from POST/PUT/PATCH endpoints that have a request body
|
||||
# FastAPI sometimes infers parameters as query params even when they should be in the request body
|
||||
|
|
|
|||
|
|
@ -51,6 +51,33 @@ def _fix_ref_references(openapi_schema: dict[str, Any]) -> dict[str, Any]:
|
|||
return openapi_schema
|
||||
|
||||
|
||||
def _normalize_empty_responses(openapi_schema: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Convert empty 200 responses into 204 No Content."""
|
||||
|
||||
for path_item in openapi_schema.get("paths", {}).values():
|
||||
if not isinstance(path_item, dict):
|
||||
continue
|
||||
for method in list(path_item.keys()):
|
||||
operation = path_item.get(method)
|
||||
if not isinstance(operation, dict):
|
||||
continue
|
||||
responses = operation.get("responses")
|
||||
if not isinstance(responses, dict):
|
||||
continue
|
||||
response_200 = responses.get("200") or responses.get(200)
|
||||
if response_200 is None:
|
||||
continue
|
||||
content = response_200.get("content")
|
||||
if content and any(
|
||||
isinstance(media, dict) and media.get("schema") not in ({}, None) for media in content.values()
|
||||
):
|
||||
continue
|
||||
responses.pop("200", None)
|
||||
responses.pop(200, None)
|
||||
responses["204"] = {"description": response_200.get("description", "No Content")}
|
||||
return openapi_schema
|
||||
|
||||
|
||||
def _eliminate_defs_section(openapi_schema: dict[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
Eliminate $defs section entirely by moving all definitions to components/schemas.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue