Fix: Preserve OpenAPI parameter descriptions in experimental parser (#1877)

This commit is contained in:
shlomo666 2025-09-21 17:43:50 +03:00 committed by GitHub
commit 92b7e92e05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View file

@ -303,9 +303,11 @@ def _combine_schemas_and_map_params(
# Convert refs if needed
if convert_refs:
param_schema = _replace_ref_with_defs(param.schema_)
param_schema = _replace_ref_with_defs(param.schema_, param.description)
else:
param_schema = param.schema_
param_schema = param.schema_.copy()
if param.description and not param_schema.get("description"):
param_schema["description"] = param.description
original_desc = param_schema.get("description", "")
location_desc = f"({param.location.capitalize()} parameter)"
if original_desc:
@ -330,9 +332,11 @@ def _combine_schemas_and_map_params(
# Convert refs if needed
if convert_refs:
param_schema = _replace_ref_with_defs(param.schema_)
param_schema = _replace_ref_with_defs(param.schema_, param.description)
else:
param_schema = param.schema_
param_schema = param.schema_.copy()
if param.description and not param_schema.get("description"):
param_schema["description"] = param.description
# Don't make optional parameters nullable - they can simply be omitted
# The OpenAPI specification doesn't require optional parameters to accept null values

View file

@ -154,6 +154,20 @@ class TestParameterHandling:
assert "tags" in properties
assert "X-API-Key" in properties
# Check that parameter descriptions are included
assert "description" in properties["query"], (
"Query parameter should have description"
)
assert properties["query"]["description"] == "Search query"
assert "description" in properties["limit"], (
"Limit parameter should have description"
)
assert properties["limit"]["description"] == "Maximum number of results"
assert "description" in properties["tags"], (
"Tags parameter should have description"
)
assert properties["tags"]["description"] == "Filter by tags"
# Check that required parameters are marked as required
required = params.get("required", [])
assert "query" in required