Repository navigation
Description
🔴 Required Information
Describe the Bug:
OpenApiSpecParser.parse() treats a type field inside schema instance data as a schema keyword. It removes "type": "invoice" from object-valued defaults and enum members, and changes "type": "STRING" to "type": "string" in examples. In the reproduction below, the parsed enum rejects the very value accepted by the input schema.
Steps to Reproduce:
- Use upstream
mainatbee78e7ce1bc1bfd16cccb0d0f8190ca6d401871with the normal ADK dependencies andjsonschemainstalled. - Run this script; no server or model credentials are needed:
import json
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_spec_parser import OpenApiSpecParser
from jsonschema import Draft202012Validator
value = {"type": "invoice", "amount": 1}
schema = {
"type": "object",
"default": value,
"enum": [value],
"examples": [{"type": "STRING", "amount": 1}],
}
spec = {
"openapi": "3.1.0",
"info": {"title": "Repro", "version": "1.0"},
"paths": {
"/documents": {
"get": {
"operationId": "getDocuments",
"parameters": [
{"name": "filter", "in": "query", "schema": schema}
],
"responses": {"200": {"description": "OK"}},
}
}
},
}
parsed = OpenApiSpecParser().parse(spec)[0].parameters[0].param_schema
result = parsed.model_dump(exclude_none=True)
print(json.dumps(result))
print(Draft202012Validator(schema).is_valid(value))
print(Draft202012Validator(result).is_valid(value))
assert parsed.default == valueExpected Behavior:
Preserve values in default, enum, and examples exactly. Their object properties are application data, including fields named type. The schema's own "type": "object" remains unchanged.
Observed Behavior:
{"type": "object", "enum": [{"amount": 1}], "description": "", "default": {"amount": 1}, "examples": [{"type": "string", "amount": 1}]}
True
False
AssertionError
The original input dictionary is unchanged; the parsed parameter schema is corrupted.
Environment Details:
- ADK Library Version: source checkout,
2.15.1, upstream commit above. - Desktop OS: macOS.
- Python Version: 3.12.15; FastAPI 0.165.0; Pydantic 2.14.4; jsonschema 4.26.0.
Model Information:
- Are you using LiteLLM: No.
- Which model is being used: N/A; offline OpenAPI parsing and JSON Schema validation only.
🟡 Optional Information
Regression: Not checked against older releases.
Additional Context:
_sanitize_schema_types() propagates in_schema=True to every descendant, including instance values under default, enum, and examples. Restricting normalization to actual schema positions should preserve these values. This report leaves the defect unfixed pending discussion of that scope.
How often has this issue occurred?: Always for the supplied input.
Activity
chelsealong commentedon Nov 29, 2026
May I work on this issue (#8447: OpenAPI schema sanitization changes object values in default, enum and examples) and, if I can reproduce it, submit a focused fix with regression coverage? Please let me know if someone is already handling it or if you would prefer a different approach. I would use Codex assistance and disclose that in any PR.
archit15singh commentedon Nov 29, 2026
I replayed nine cases through
OpenApiSpecParser.parse()on mainbee78e7c, release 2.15.1, and #8448ab45fac8. The patch restores validation of the issue’s input and two nested object-enum cases. It also preserves normalization of schematypein real nested schemas, ordinary local schema references, and scalar enum values. The focused parser suite passed 30 tests on main and 31 on the candidate.One separate boundary remains on both main and the candidate. When a literal default or enum object has a
$refkey whose string names an existing local schema, the earlier reference resolver replaces the object before sanitization. Thetypefix works on the issue's payload. This residual behavior is present in the release too and can be tracked independently of the patch.