Bug: internal library exception is leaked
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start with the validate entry point in openapi_spec_validator/shortcuts.py and the iteration path shown in validation/validators.py. Run the minimal openapi.invalid_reference.yml and main.py reproduction first. Done means the invalid reference raises the package's ValidationError rather than referencing.exceptions.PointerToNowhere, without logging the entire OpenAPI specification.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hello, thank you for maintaining this project!
Description
I found an issue, where an internal library error (referencing lib) is raised and not wrapped in a ValidationError. Also this exception logs the whole of the openapi spec which is not ideal for a really large spec.
Expected behavior
The internal ValidationError exception is raised instead of the internal library one.
Steps to Reproduce
Here is minimal openapi spec to reproduce the issue.
# openapi.invalid_reference.yml
openapi: 3.0.0
info:
title: Trigger unhandled exception
version: 1.0.0
description: >-
This is a minimal openapi config to trigger referencing.exceptions.PointerToNowhere
exception this should be handled by the openapi_spec_validator but it is not
servers:
- url: http://petstore.swagger.io/api
paths:
/pets:
get:
responses:
"200":
description: pet response
"401": # Reference points to nonexistant entry, this should trigger the exception
$ref: "#/components/responses/InvalidReference"
"5XX":
$ref: "#/components/responses/APIError"
components:
responses:
APIError:
description: An error occurred interacting with the API.
content:
application/json:
schema:
$ref: "#/components/schemas/APIError"
# main.py
from openapi_spec_validator import validate
from openapi_spec_validator.readers import read_from_filename
spec_dict, base_uri = read_from_filename('openapi.invalid_reference.yml')
# referencing.exceptions.PointerToNowhere exception is raised
validate(spec_dict)
Raised exception output
Traceback (most recent call last):
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/referencing/_core.py", line 276, in pointer
contents = contents[segment] # type: ignore[reportUnknownArgumentType]
~~~~~~~~^^^^^^^^^
KeyError: 'InvalidReference'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/user/repro/schema_validation/main.py", line 6, in <module>
validate(spec_dict)
~~~~~~~~^^^^^^^^^^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/shortcuts.py", line 55, in validate
return v.validate()
~~~~~~~~~~^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/validators.py", line 72, in validate
for err in self.iter_errors():
~~~~~~~~~~~~~~~~^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/caches.py", line 61, in __next__
item = next(self.parent)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/caches.py", line 30, in __next__
item = next(self.iter)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/decorators.py", line 28, in wrapper
for err in errors:
^^^^^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/validators.py", line 93, in iter_errors
yield from self.root_validator(self.schema_path)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/keywords.py", line 721, in __call__
yield from self.paths_validator(paths)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/keywords.py", line 631, in __call__
yield from self.path_validator(url, path_item)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/keywords.py", line 588, in __call__
yield from self.operation_validator(
url, field_name, operation, parameters
)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/keywords.py", line 515, in __call__
yield from self.responses_validator(responses)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/keywords.py", line 475, in __call__
yield from self.response_validator(response_code, response)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/openapi_spec_validator/validation/keywords.py", line 462, in __call__
if "content" in response:
^^^^^^^^^^^^^^^^^^^^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/pathable/paths.py", line 524, in __contains__
return self.accessor.contains(self.parts, key)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/jsonschema_path/accessors.py", line 178, in contains
node = self[parts]
~~~~^^^^^^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/jsonschema_path/accessors.py", line 129, in __getitem__
resolved = self.get_resolved(parts)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/jsonschema_path/accessors.py", line 239, in get_resolved
result = self._path_resolver.resolve(self.node, parts)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/jsonschema_path/resolvers.py", line 34, in resolve
resolved = self._resolve_with_prefix_cache(node, parts)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/jsonschema_path/resolvers.py", line 80, in _resolve_with_prefix_cache
resolved_schema = SchemaNode._resolve_node(
current_node,
current_resolver,
)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/jsonschema_path/nodes.py", line 24, in _resolve_node
resolved = resolver.lookup(ref)
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/referencing/_core.py", line 690, in lookup
return retrieved.value.pointer(pointer=fragment, resolver=resolver)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/repro/schema_validation/.venv/lib/python3.14/site-packages/referencing/_core.py", line 279, in pointer
raise error from lookup_error
referencing.exceptions.PointerToNowhere: '/components/responses/InvalidReference' does not exist within {'openapi': '3.0.0', 'info': {'title': 'Trigger unhandled exception', 'version': '1.0.0', 'description': 'This is a minimal openapi config to trigger referencing.exceptions.PointerToNowhere exception this should be handled by the openapi_spec_validator but it is not'}, 'servers': [{'url': 'http://petstore.swagger.io/api'}], 'paths': {'/pets': {'get': {'responses': {'200': {'description': 'pet response'}, '401': {'$ref': '#/components/responses/InvalidReference'}, '5XX': {'$ref': '#/components/responses/APIError'}}}}}, 'components': {'responses': {'APIError': {'description': 'An error occurred interacting with the API.', 'content': {'application/json': {'schema': {'$ref': '#/components/schemas/APIError'}}}}}}}
Environment
- OS: Linux ubuntu 24.04.1
- Python version (
python --version) : Python 3.14.4 - python library environment (
uv pip freeze):
annotated-types==0.7.0
attrs==26.1.0
jsonschema==4.26.0
jsonschema-path==0.5.0
jsonschema-specifications==2025.9.1
lazy-object-proxy==1.12.0
openapi-schema-validator==0.9.0
openapi-spec-validator==0.9.0
pathable==0.6.0
pydantic==2.13.4
pydantic-core==2.46.4
pydantic-settings==2.14.1
python-dotenv==1.2.2
pyyaml==6.0.3
referencing==0.37.0
rfc3339-validator==0.1.4
rpds-py==2026.5.1
six==1.17.0
typing-extensions==4.15.0
typing-inspection==0.4.2
- Ngôn ngữ chính
- Python
- Star
- 409
- Fork
- 73
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-openapi/openapi-spec-validator
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
python-openapi/openapi-spec-validator#400 · 1 bình luận ·
-
kind/bug/confirmed
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
python-openapi/openapi-spec-validator#373 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của python-openapi/openapi-spec-validator
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
learningequality/ricecooker#747 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
run-llama/llama_index#23199 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
KhronosGroup/glTF-Blender-IO#2769 ·